[Python] python Crypto Ed25519ph same processing(?) different signatures

Discussão em 'Python' iniciado por Stack, Maio 14, 2025.

  1. Stack

    Stack Membro Participativo

    in python i do (shorthand, code below, output below):

    digest = SHA512.new(message)
    signer = eddsa.new(privatekey, "rfc8032")
    siganture = signer.sign(digest)


    this gives the correct signature (see: Ed25519ph, TEST abc, https://datatracker.ietf.org/doc/html/rfc8032)

    but when i print the intermediate hashed message (digest.hexdigest()) and use this as input for the signer i get a different signature???

    signer = eddsa.new(privatekey, "rfc8032")
    siganture = signer.sign(message_hashed)


    then the signature is same as; Ed25519, TEST SHA(abc), https://datatracker.ietf.org/doc/html/rfc8032

    the reason i am trying to get my head around this is because i cannot get the first (Ed25519ph, TEST abc) to work in arduino (also gives the second signature)

    output:

    python sign_problem.py

    Ed25519ph: TEST abc
    ('Message (hex):', '616263')
    ('Caculated hash (hex):', 'ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f')
    ('Caculated signature (hex):', '98A70222F0B8121AA9D30F813D683F809E462B469C7FF87639499BB94E6DAE4131F85042463C2A355A2003D062ADF5AAA10B8C61E636062AAAD11C2A26083406')

    Ed25519ph: TEST abc: staring with hashed message
    ('Hashed message (hex):', 'DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F')
    ('Caculated signature (hex):', 'DC2A4459E7369633A52B1BF277839A00201009A3EFBF3ECB69BEA2186C26B58909351FC9AC90B3ECFDFBC7C66431E0303DCA179C138AC17AD9BEF1177331A704')


    code:

    from Crypto.PublicKey import ECC
    from Crypto.Signature import eddsa
    from Crypto.Hash import SHA512

    import hexdump

    privatekey = eddsa.import_private_key(b'\x83\x3F\xE6\x24\x09\x23\x7B\x9D\x62\xEC\x77\x58\x75\x20\x91\x1E\x9A\x75\x9C\xEC\x1D\x19\x75\x5B\x7D\xA9\x01\xB9\x6D\xCA\x3D\x42')

    print("")
    print("Ed25519ph: TEST abc")

    message = b'\x61\x62\x63'
    print("Message (hex):",hexdump.dump(message, sep=""))

    digest = SHA512.new(message)
    print("Caculated hash (hex):", digest.hexdigest())
    signer_1 = eddsa.new(privatekey, "rfc8032")
    calculated_signature_1 = signer_1.sign(digest)
    print("Caculated signature (hex):",hexdump.dump(calculated_signature_1, sep=""))

    print("")
    print("Ed25519ph: TEST abc: staring with hashed message")

    message_hashed = b'\xDD\xAF\x35\xA1\x93\x61\x7A\xBA\xCC\x41\x73\x49\xAE\x20\x41\x31\x12\xE6\xFA\x4E\x89\xA9\x7E\xA2\x0A\x9E\xEE\xE6\x4B\x55\xD3\x9A\x21\x92\x99\x2A\x27\x4F\xC1\xA8\x36\xBA\x3C\x23\xA3\xFE\xEB\xBD\x45\x4D\x44\x23\x64\x3C\xE8\x0E\x2A\x9A\xC9\x4F\xA5\x4C\xA4\x9F'
    print("Hashed message (hex):", hexdump.dump(message_hashed, sep=""))

    signer_2 = eddsa.new(privatekey, "rfc8032")
    calculated_signature_2 = signer_2.sign(message_hashed)
    print("Caculated signature (hex):",hexdump.dump(calculated_signature_2, sep=""))



    excerpt from https://datatracker.ietf.org/doc/html/rfc8032

    -----TEST SHA(abc)

    ALGORITHM:
    Ed25519

    SECRET KEY:
    833fe62409237b9d62ec77587520911e
    9a759cec1d19755b7da901b96dca3d42

    PUBLIC KEY:
    ec172b93ad5e563bf4932c70e1245034
    c35467ef2efd4d64ebf819683467e2bf

    MESSAGE (length 64 bytes):
    ddaf35a193617abacc417349ae204131
    12e6fa4e89a97ea20a9eeee64b55d39a
    2192992a274fc1a836ba3c23a3feebbd
    454d4423643ce80e2a9ac94fa54ca49f

    SIGNATURE:
    dc2a4459e7369633a52b1bf277839a00
    201009a3efbf3ecb69bea2186c26b589
    09351fc9ac90b3ecfdfbc7c66431e030
    3dca179c138ac17ad9bef1177331a704
    -----



    and

    -----TEST abc

    ALGORITHM:
    Ed25519ph

    SECRET KEY:
    833fe62409237b9d62ec77587520911e
    9a759cec1d19755b7da901b96dca3d42

    PUBLIC KEY:
    ec172b93ad5e563bf4932c70e1245034
    c35467ef2efd4d64ebf819683467e2bf

    MESSAGE (length 3 bytes):
    616263

    SIGNATURE:
    98a70222f0b8121aa9d30f813d683f80
    9e462b469c7ff87639499bb94e6dae41
    31f85042463c2a355a2003d062adf5aa
    a10b8c61e636062aaad11c2a26083406
    -----

    Continue reading...

Compartilhe esta Página