Lines Matching +full:key +full:- +full:up
11 /* Test ML-DSA operation. */
22 * @brief Consumes an 8-bit unsigned integer from a buffer.
24 * This function extracts an 8-bit unsigned integer from the provided buffer,
29 * @param val Pointer to store the extracted 8-bit value.
39 *len -= sizeof(uint8_t); in consume_uint8_t()
61 *len -= sizeof(size_t); in consume_size_t()
66 * @brief Selects a key type and size from a buffer.
68 * This function reads a key size value from the buffer, determines the
69 * corresponding key type and length, and updates the buffer pointer
70 * accordingly. If `only_valid` is set, it restricts selection to valid key
75 * @param keytype Pointer to store the selected key type string.
76 * @param keylen Pointer to store the selected key length.
77 * @param only_valid Flag to restrict selection to valid key sizes.
79 * @return 1 if a key type is successfully selected, 0 on failure.
93 *len -= sizeof(uint16_t); in select_keytype_and_size()
99 * If `only_valid` is set, select only ML-DSA-44, ML-DSA-65, and ML-DSA-87. in select_keytype_and_size()
107 * Note, keylens for valid values (cases 0-2) are taken based on input in select_keytype_and_size()
112 *keytype = "ML-DSA-44"; in select_keytype_and_size()
116 *keytype = "ML-DSA-65"; in select_keytype_and_size()
120 *keytype = "ML-DSA-87"; in select_keytype_and_size()
125 *keytype = "ML-DSA-33"; in select_keytype_and_size()
130 *keytype = "ML-DSA-87"; in select_keytype_and_size()
132 *len -= sizeof(uint16_t); in select_keytype_and_size()
134 *keylen %= ML_DSA_87_PUB_LEN; /* size to our key buffer */ in select_keytype_and_size()
145 * @brief Creates an ML-DSA raw key from a buffer.
147 * This function selects a key type and size from the buffer, generates a random
148 * key of the appropriate length, and creates either a public or private ML-DSA
149 * key using OpenSSL's EVP_PKEY interface.
153 * @param key1 Pointer to store the generated EVP_PKEY key (public or private).
156 * @note The generated key is allocated using OpenSSL's EVP_PKEY functions
166 uint8_t key[MAX_ML_DSA_PRIV_LEN]; in create_ml_dsa_raw_key() local
173 * Select public or private key creation based on the low order bit of the in create_ml_dsa_raw_key()
175 * Note that keylen as returned from select_keytype_and_size is a public key in create_ml_dsa_raw_key()
176 * length, so make the adjustment to private key lengths here. in create_ml_dsa_raw_key()
197 * libfuzzer provides by default up to 4096 bit input buffers, but it's in create_ml_dsa_raw_key()
201 if (!RAND_bytes(key, keylen)) in create_ml_dsa_raw_key()
205 * Try to generate either a raw public or private key using random data in create_ml_dsa_raw_key()
211 pubkey = EVP_PKEY_new_raw_public_key_ex(NULL, keytype, NULL, key, keylen); in create_ml_dsa_raw_key()
213 pubkey = EVP_PKEY_new_raw_private_key_ex(NULL, keytype, NULL, key, keylen); in create_ml_dsa_raw_key()
220 EVP_PKEY **key) in keygen_ml_dsa_real_key_helper() argument
228 * Only generate valid key types and lengths. Note, no adjustment is made to in keygen_ml_dsa_real_key_helper()
246 *key = EVP_PKEY_new(); in keygen_ml_dsa_real_key_helper()
247 if (*key == NULL) in keygen_ml_dsa_real_key_helper()
250 if (!EVP_PKEY_generate(ctx, key)) { in keygen_ml_dsa_real_key_helper()
251 fprintf(stderr, "Failed to generate new real key\n"); in keygen_ml_dsa_real_key_helper()
262 * @brief Generates a valid ML-DSA key using OpenSSL.
264 * This function selects a valid ML-DSA key type and size from the buffer,
265 * initializes an OpenSSL EVP_PKEY context, and generates a cryptographic key
270 * @param key1 Pointer to store the first generated EVP_PKEY key.
271 * @param key2 Pointer to store the second generated EVP_PKEY key.
273 * @note The generated key is allocated using OpenSSL's EVP_PKEY functions
285 * @brief Performs key sign and verify using an EVP_PKEY.
287 * This function generates a random key, signs random data using the provided
288 * public key, then verifies it. It makes use of OpenSSL's EVP_PKEY API for
293 * @param[in] key1 Pointer to an EVP_PKEY structure used for key operations.
301 EVP_PKEY *key = (EVP_PKEY *)key1; in ml_dsa_sign_verify() local
302 EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_pkey(NULL, key, NULL); in ml_dsa_sign_verify()
308 const char *alg = EVP_PKEY_get0_type_name(key); in ml_dsa_sign_verify()
310 OSSL_PARAM_octet_string("context-string", in ml_dsa_sign_verify()
330 * Because ML-DSA is fundamentally a one-shot algorithm like "pure" Ed25519 in ml_dsa_sign_verify()
332 * sign/verify functions. Therefore, we only test the one-shot functions. in ml_dsa_sign_verify()
348 if ((ctx = EVP_PKEY_CTX_new_from_pkey(NULL, key, NULL)) == NULL in ml_dsa_sign_verify()
364 * @brief Performs key sign and verify using an EVP_PKEY.
366 * This function generates a random key, signs random data using the provided
367 * public key, then verifies it. It makes use of OpenSSL's EVP_PKEY API for
372 * @param[in] key1 Pointer to an EVP_PKEY structure used for key operations.
380 EVP_PKEY *key = (EVP_PKEY *)key1; in ml_dsa_digest_sign_verify() local
387 OSSL_PARAM_octet_string("context-string", in ml_dsa_digest_sign_verify()
407 * Because ML-DSA is fundamentally a one-shot algorithm like "pure" Ed25519 in ml_dsa_digest_sign_verify()
409 * sign/verify functions. Therefore, we only test the one-shot functions. in ml_dsa_digest_sign_verify()
412 if (!EVP_DigestSignInit_ex(ctx, NULL, NULL, NULL, "?fips=true", key, params) in ml_dsa_digest_sign_verify()
425 || EVP_DigestVerifyInit_ex(ctx, NULL, NULL, NULL, "?fips=true", key, in ml_dsa_digest_sign_verify()
441 * @brief Exports and imports an ML-DSA key.
443 * This function extracts key material from the given key (`key1`), exports it
444 * as parameters, and then attempts to reconstruct a new key from those
450 * @param[in] key1 The key to be exported and imported.
451 * @param[in] key2 Unused input key (reserved for future use).
455 * @note If any step in the export-import process fails, the function
456 * logs an error and cleans up allocated resources.
498 * @param key1 First key, expected to be an `EVP_PKEY *`.
499 * @param key2 Second key, expected to be an `EVP_PKEY *`.
514 * @brief Frees allocated ML-DSA keys.
516 * This function releases memory associated with up to four EVP_PKEY objects by
517 * calling `EVP_PKEY_free()` on each provided key.
519 * @param key1 Pointer to the first key to be freed.
520 * @param key2 Pointer to the second key to be freed.
521 * @param key3 Pointer to the third key to be freed.
522 * @param key4 Pointer to the fourth key to be freed.
524 * @note This function assumes that each key is either a valid EVP_PKEY
540 * up, executing, and cleaning up cryptographic operations, along with
553 * @brief Function pointer for setting up the operation.
576 * @brief Function pointer for cleaning up after the operation.
578 * @param in1 First input parameter to be cleaned up.
579 * @param in2 Second input parameter to be cleaned up.
580 * @param out1 First output parameter to be cleaned up.
581 * @param out2 Second output parameter to be cleaned up.
588 "Generate ML-DSA raw key",
594 "Generate ML-DSA keypair, using EVP_PKEY_keygen",
595 "Generates a real ML-DSA keypair, should always work",
600 "Do a sign/verify operation on a key",
601 "Generate key, sign random data, verify it, should work",
606 "Do a digest sign/verify operation on a key",
607 "Generate key, digest sign random data, verify it, should work",
612 "Do an export/import of key data",
641 * @return 0 on successful execution, -1 if the input is too short.
655 return -1; in FuzzerTestOneInput()
660 return -1; in FuzzerTestOneInput()