• Xanza@lemm.ee
    link
    fedilink
    English
    arrow-up
    4
    ·
    4 days ago

    Signing isn’t encryption. It’s a non-cipher hash.

    $ ❯ echo "This is a signed message." | ssh-keygen -Y sign -n file -f ~/.ssh/id_ed25519 > content.txt.sig
    Signing data on standard input
    

    Which outputs the hash of the signed statement, which was signed with my private key;

    -----BEGIN SSH SIGNATURE-----
    U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgCwxAYX85ptsTc+Dtz3a0IRondh
    qFF3wKMsTqt+c4oGMAAAAEZmlsZQAAAAAAAAAGc2hhNTEyAAAAUwAAAAtzc2gtZWQyNTUx
    OQAAAECvqKLkm+kWUgFh0bI8jYIR5BPUaq76MZ94exp2yUn+KnK5YA79ggFY/C4VsnDqJp
    SAedWp4eOUwPNG8RR59KsP
    -----END SSH SIGNATURE-----
    

    And can then be verified using my public key;

    ❯ echo "This is a signed message." | ssh-keygen -Y check-novalidate -n file -f ~/.ssh/id_ed25519.pub -s content.txt.sig
    Good "file" signature with ED25519 key SHA256:ltAIkPgF9rLt1KlRRh6tQUtWNT8/wErhtAibmSHfbVs
    
    • frezik@midwest.social
      link
      fedilink
      arrow-up
      2
      ·
      4 days ago

      Mathematically, signing is encryption using the private key. That’s how the algorithm works. The input to the function is irrelevant.

      • Xanza@lemm.ee
        link
        fedilink
        English
        arrow-up
        2
        arrow-down
        2
        ·
        edit-2
        4 days ago

        Mathematically, they’re not even close to the same. How you could ever assert such an indefensibly and empirically incorrect statement is beyond my reasoning skills to understand.

        PKC Key signing uses hashing algorithms like RSA, ElGamal, DSA, and ECDSA to create one way cryptographic hashes for given input data. The singular purpose of these signatures is to verify the integrity of data. Not to protect the data in any way whatsoever or to be reversed into clear text; again, the hash is one way.

        PKC encryption uses encryption algorithms like AES, Blowfish, Twofish, PGP, and Diffie-Hellman to create reversible cipher text. The difference being, the cipher text of an encryption process can be reversed and represents the data itself.

        All of this is clearly outlined in the RFC: https://www.ietf.org/rfc/rfc4880.txt

        • frezik@midwest.social
          link
          fedilink
          arrow-up
          4
          arrow-down
          1
          ·
          4 days ago

          I know it because I’ve actually implemented RSA as an exercise and know how it works.

          What you’re talking about with hashes is an implementation detail. It’s an important one, because using exactly the same algorithm for signing and encryption has some security pitfalls, and it will usually be slower. However, the function you call is exactly the same. The hash is encrypted with the private key. It can be verified by generating the same hash, decrypting with the public key, and matching the two hashes.

          See also: https://cryptobook.nakov.com/digital-signatures/rsa-signatures

          Signing a message msg with the private key exponent d:

          • Calculate the message hash: h = hash(msg)
          • Encrypt h to calculate the signature: s = hd (mod n)

          The operation “hd (mod n)” is just RSA encryption, but with the private key.

    • SigmarStern@discuss.tchncs.de
      link
      fedilink
      arrow-up
      1
      ·
      4 days ago

      Thanks for that rabbit hole. My former colleagues and I have just started a new conversation thread in our WhatsApp group about the differences of (non-) cryptographic hashes and encryption. And all because I was confused why you’ve chosen to reference the public key file in your original comment. Well, at least I’m learning something.