Skip to content

ed448 signature malleability #7706

Closed
Closed

Description

@reaperhulk

Similar to #7693, ed448 verification doesn't check that s is less than the group order, allowing malleability for some signatures. Wycheproof doesn't have vectors for this yet, but I generated an example:

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <openssl/crypto.h>
#include <openssl/evp.h>
#include <openssl/x509.h>


int main(void) {
    OPENSSL_init();
    int ret = 0;
    int res;
    unsigned char *public = OPENSSL_hexstr2buf("fedb02a658d74990244d9d10cf338e977565cbbda6b24c716829ed6ee1e4f28cf2620c052db8d878f6243bffc22242816c1aaa67d2f3603600", NULL);
    unsigned char *sig = OPENSSL_hexstr2buf("0cc16ba24d69277f927c1554b0f08a2a711bbdd20b058ccc660d00ca13542a3cef9e5c44c54ab23a2eb14f947e167b990b080863e28b399380f30db6e54d5d1406d23378ffde11b1fb81b2b438a3b8e8aa7f7f4e1befcc905023fab5a5465053844f04cf0c1b51d84760f869588687f57500", NULL);
    unsigned char *msg = OPENSSL_hexstr2buf("38", NULL);

    EVP_PKEY *pkey = EVP_PKEY_new_raw_public_key(NID_ED448, NULL, public, 57);
    assert(pkey != NULL);
    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
    res = EVP_DigestVerifyInit(ctx, NULL, NULL, NULL, pkey);
    assert(res == 1);
    res = EVP_DigestVerify(ctx, sig, 114, msg, 1);
    if (res == 1) {
        printf("Verification passed but should have failed.\n");
        ret = 1;
    }
    exit(ret);
}

Activity

  1. mattcaswell commented on Dec 3, 2018

    @mattcaswell
    Member

    Hmmm. Something doesn't quite look right with this test. Either that or I'm doing something stupid (which is entirely possible). An ed448 signature is composed of a 57 byte point R and a 57 byte integer s. R comes first followed by s. So in your test code the value of s is:

    f30db6e54d5d1406d23378ffde11b1fb81b2b438a3b8e8aa7f7f4e1befcc905023fab5a5465053844f04cf0c1b51d84760f869588687f57500

    ed448 encodes integers in little-endian order, so the most significant byte here is 0x00. s needs to be in the range 0 <= s < L. Where L is the group order and is a 57 byte integer with the most significat byte set to 0x3F. Therefore if s >= L as you claim then the most significant byte of s would have to be 0x3F or greater - and not 0x00 as in this test case.

  2. mattcaswell commented on Dec 3, 2018

    @mattcaswell
    Member

    Either that or I'm doing something stupid

    Yep. Me being stupid.

    Apparently even though s is defined to be 57 bytes long by the standard, the order L is in fact only 56 bytes long! So a valid value for s always ends in 0x00, and if s >=L then the two most significant bytes must be 0x003F or greater. Which it is in your test case (0x0075)

  3. mattcaswell commented on Dec 3, 2018

    @mattcaswell
    Member

    Can you provide the equivalent valid sig?

  4. mattcaswell commented on Dec 3, 2018

    @mattcaswell
    Member

    Can you provide the equivalent valid sig?

    Forget that...no longer needed.

  5. mattcaswell commented on Dec 3, 2018

    @mattcaswell
    Member

    Fix in #7748.

  6. added a commit that references this issue on Dec 11, 2018
    f807ad1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions