diff --git a/src/wp_ecx_sig.c b/src/wp_ecx_sig.c index 15119532..9a91cb40 100644 --- a/src/wp_ecx_sig.c +++ b/src/wp_ecx_sig.c @@ -262,83 +262,61 @@ static int wp_ecx_digest_verify_init(wp_EcxSigCtx *ctx, const char *mdName, return ok; } +/** Parameters that we support getting from the ECX signature context. */ +static const OSSL_PARAM wp_supported_gettable_ctx_params[] = { + OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0), + OSSL_PARAM_END +}; /** - * Put DER encoding of the Ed25519 signature algorithm in the parameter object. + * Returns an array of ECX signature context parameters that can be retrieved. * - * @param [in] ctx ECX signature context object. - * @param [in] p Parameter object. - * @return 1 on success. - * @return 0 on failure. + * @param [in] ctx ECX signature context object. Unused. + * @param [in] provCtx wolfProvider context object. Unused. + * @return Array of parameters. */ -static int wp_ed25519_get_alg_id(wp_EcxSigCtx *ctx, OSSL_PARAM *p) +static const OSSL_PARAM *wp_ecx_gettable_ctx_params(wp_EcxSigCtx *ctx, + WOLFPROV_CTX *provCtx) { - /* Ed25519 Algorithm Id: SEQ OBJ 2b 65 70 */ - static const byte ed25519AlgId[] = { - 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, - }; - (void)ctx; - - return OSSL_PARAM_set_octet_string(p, ed25519AlgId, sizeof(ed25519AlgId)); + (void)provCtx; + return wp_supported_gettable_ctx_params; } -/** - * Put data from Ed25519 signture context object into parameter objects. - * - * @param [in] ctx ECX signature context object. - * @param [in] params Array of parameter objects. - * @return 1 on success. - * @return 0 on failure. - */ -static int wp_ed25519_get_ctx_params(wp_EcxSigCtx *ctx, OSSL_PARAM *params) -{ - int ok = 1; - OSSL_PARAM *p; - - if (ctx == NULL) { - ok = 0; - } - - if (ok) { - p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID); - if (p != NULL) { - ok = wp_ed25519_get_alg_id(ctx, p); - } - } +#ifdef WP_HAVE_ED25519 - WOLFPROV_LEAVE(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); - return ok; -} +/* + * Ed25519 + */ /** - * Put DER encoding of the Ed448 signature algorithm in the parameter object. + * Put DER encoding of the Ed25519 signature algorithm in the parameter object. * * @param [in] ctx ECX signature context object. * @param [in] p Parameter object. * @return 1 on success. * @return 0 on failure. */ -static int wp_ed448_get_alg_id(wp_EcxSigCtx *ctx, OSSL_PARAM *p) +static int wp_ed25519_get_alg_id(wp_EcxSigCtx *ctx, OSSL_PARAM *p) { - /* Ed448 Algorithm Id: SEQ OBJ 2b 65 71 */ - static const byte ed448AlgId[] = { - 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x71, + /* Ed25519 Algorithm Id: SEQ OBJ 2b 65 70 */ + static const byte ed25519AlgId[] = { + 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, }; (void)ctx; - return OSSL_PARAM_set_octet_string(p, ed448AlgId, sizeof(ed448AlgId)); + return OSSL_PARAM_set_octet_string(p, ed25519AlgId, sizeof(ed25519AlgId)); } /** - * Put data from Ed448 signture context object into parameter objects. + * Put data from Ed25519 signture context object into parameter objects. * * @param [in] ctx ECX signature context object. * @param [in] params Array of parameter objects. * @return 1 on success. * @return 0 on failure. */ -static int wp_ed448_get_ctx_params(wp_EcxSigCtx *ctx, OSSL_PARAM *params) +static int wp_ed25519_get_ctx_params(wp_EcxSigCtx *ctx, OSSL_PARAM *params) { int ok = 1; OSSL_PARAM *p; @@ -350,7 +328,7 @@ static int wp_ed448_get_ctx_params(wp_EcxSigCtx *ctx, OSSL_PARAM *params) if (ok) { p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID); if (p != NULL) { - ok = wp_ed448_get_alg_id(ctx, p); + ok = wp_ed25519_get_alg_id(ctx, p); } } @@ -358,32 +336,6 @@ static int wp_ed448_get_ctx_params(wp_EcxSigCtx *ctx, OSSL_PARAM *params) return ok; } -/** Parameters that we support getting from the ECX signature context. */ -static const OSSL_PARAM wp_supported_gettable_ctx_params[] = { - OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0), - OSSL_PARAM_END -}; -/** - * Returns an array of ECX signature context parameters that can be retrieved. - * - * @param [in] ctx ECX signature context object. Unused. - * @param [in] provCtx wolfProvider context object. Unused. - * @return Array of parameters. - */ -static const OSSL_PARAM *wp_ecx_gettable_ctx_params(wp_EcxSigCtx *ctx, - WOLFPROV_CTX *provCtx) -{ - (void)ctx; - (void)provCtx; - return wp_supported_gettable_ctx_params; -} - -#ifdef WP_HAVE_ED25519 - -/* - * Ed25519 - */ - /** * Sign the data using an Ed25519 key. * @@ -529,6 +481,54 @@ const OSSL_DISPATCH wp_ed25519_signature_functions[] = { * Ed448 */ +/** + * Put DER encoding of the Ed448 signature algorithm in the parameter object. + * + * @param [in] ctx ECX signature context object. + * @param [in] p Parameter object. + * @return 1 on success. + * @return 0 on failure. + */ +static int wp_ed448_get_alg_id(wp_EcxSigCtx *ctx, OSSL_PARAM *p) +{ + /* Ed448 Algorithm Id: SEQ OBJ 2b 65 71 */ + static const byte ed448AlgId[] = { + 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x71, + }; + + (void)ctx; + + return OSSL_PARAM_set_octet_string(p, ed448AlgId, sizeof(ed448AlgId)); +} + +/** + * Put data from Ed448 signture context object into parameter objects. + * + * @param [in] ctx ECX signature context object. + * @param [in] params Array of parameter objects. + * @return 1 on success. + * @return 0 on failure. + */ +static int wp_ed448_get_ctx_params(wp_EcxSigCtx *ctx, OSSL_PARAM *params) +{ + int ok = 1; + OSSL_PARAM *p; + + if (ctx == NULL) { + ok = 0; + } + + if (ok) { + p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID); + if (p != NULL) { + ok = wp_ed448_get_alg_id(ctx, p); + } + } + + WOLFPROV_LEAVE(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); + return ok; +} + /** * Sign the data using an Ed448 key. * diff --git a/test/test_ecx.c b/test/test_ecx.c index 31773652..4647996e 100644 --- a/test/test_ecx.c +++ b/test/test_ecx.c @@ -202,8 +202,16 @@ int test_ecx_sign_verify_raw_priv(void *data) EVP_PKEY *pkey_ossl = NULL; EVP_PKEY *pkey_wolf = NULL; + #if defined(WP_HAVE_ED25519) && defined(WP_HAVE_ED448) unsigned char readback_ossl[MAX(ED25519_KEY_SIZE, ED448_KEY_SIZE)]; unsigned char readback_wolf[MAX(ED25519_KEY_SIZE, ED448_KEY_SIZE)]; + #elif defined(WP_HAVE_ED25519) + unsigned char readback_ossl[ED25519_KEY_SIZE]; + unsigned char readback_wolf[ED25519_KEY_SIZE]; + #elif defined(WP_HAVE_ED448) + unsigned char readback_ossl[ED448_KEY_SIZE]; + unsigned char readback_wolf[ED448_KEY_SIZE]; + #endif #ifdef WP_HAVE_ED25519 unsigned char sig_ed25519[ED25519_SIG_SIZE]; @@ -335,8 +343,16 @@ int test_ecx_sign_verify_raw_pub(void *data) const unsigned char *p = NULL; unsigned char buf[128]; size_t bufLen = 0; + #if defined(WP_HAVE_ED25519) && defined(WP_HAVE_ED448) unsigned char readback_ossl[MAX(ED25519_KEY_SIZE, ED448_KEY_SIZE)]; unsigned char readback_wolf[MAX(ED25519_KEY_SIZE, ED448_KEY_SIZE)]; + #elif defined(WP_HAVE_ED25519) + unsigned char readback_ossl[ED25519_KEY_SIZE]; + unsigned char readback_wolf[ED25519_KEY_SIZE]; + #elif defined(WP_HAVE_ED448) + unsigned char readback_ossl[ED448_KEY_SIZE]; + unsigned char readback_wolf[ED448_KEY_SIZE]; + #endif #ifdef WP_HAVE_ED25519 unsigned char sig_ed25519[ED25519_SIG_SIZE];