mirror of
https://github.com/open-quantum-safe/liboqs.git
synced 2025-11-22 00:09:23 -05:00
Generate kat_sig combine_message_signature from template
This commit is contained in:
parent
abea47380d
commit
9dcbb7bdb0
@ -26,7 +26,7 @@ Implementation
|
||||
--------------
|
||||
|
||||
- **Source of implementation:** https://github.com/PQClean/PQClean
|
||||
- **Implementation version:** https://github.com/PQClean/PQClean/commit/e56b2e5556934963cae177062fca17798760afd2
|
||||
- **Implementation version:** https://github.com/PQClean/PQClean/commit/6e12692b4e8484340779fc90676c6af5e3d8f039
|
||||
- **License:** public domain
|
||||
- **Language:** C
|
||||
- **Constant-time:** Yes
|
||||
|
||||
@ -123,6 +123,7 @@ replacer('src/kem/kem.c', instructions, '/////')
|
||||
replacer('src/kem/kem.h', instructions, '/////')
|
||||
replacer('src/sig/sig.c', instructions, '/////')
|
||||
replacer('src/sig/sig.h', instructions, '/////')
|
||||
replacer('tests/kat_sig.c', instructions, '/////')
|
||||
replacer('VisualStudio/winconfig.h', instructions, '/////')
|
||||
generator_all('VisualStudio/oqs/dll.def', instructions)
|
||||
unix2dos('VisualStudio/oqs/dll.def')
|
||||
|
||||
@ -110,6 +110,7 @@ sigs:
|
||||
pretty_name_full: DILITHIUM_2
|
||||
implementation: clean
|
||||
sources: ['sign.c', 'polyvec.c', 'poly.c', 'packing.c', 'ntt.c', 'reduce.c', 'rounding.c', 'symmetric.c']
|
||||
signed_msg_order: sig_then_msg
|
||||
visual_studio_guid: 1f5e5dbe-8082-4756-9e90-c7d84198d682
|
||||
-
|
||||
scheme: "3"
|
||||
@ -117,6 +118,7 @@ sigs:
|
||||
pretty_name_full: DILITHIUM_3
|
||||
implementation: clean
|
||||
sources: ['sign.c', 'polyvec.c', 'poly.c', 'packing.c', 'ntt.c', 'reduce.c', 'rounding.c', 'symmetric.c']
|
||||
signed_msg_order: sig_then_msg
|
||||
visual_studio_guid: 8a93b308-7b77-41e7-88a5-275994b62322
|
||||
-
|
||||
scheme: "4"
|
||||
@ -124,6 +126,7 @@ sigs:
|
||||
pretty_name_full: DILITHIUM_4
|
||||
implementation: clean
|
||||
sources: ['sign.c', 'polyvec.c', 'poly.c', 'packing.c', 'ntt.c', 'reduce.c', 'rounding.c', 'symmetric.c']
|
||||
signed_msg_order: sig_then_msg
|
||||
visual_studio_guid: fb8c21f2-891b-46fb-8a45-17f69dfa31bd
|
||||
-
|
||||
name: mqdss
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
{% for family in instructions['sigs'] %}{% for scheme in family['schemes'] %}
|
||||
} else if (0 == strcmp(sig->method_name, "{{ scheme['pretty_name_full'] }}")) {
|
||||
{%- if scheme['signed_msg_order'] == 'sig_then_msg' %}
|
||||
// signed_msg = signature || msg
|
||||
*signed_msg_len = signature_len + msg_len;
|
||||
*signed_msg = malloc(*signed_msg_len);
|
||||
if (*signed_msg == NULL) {
|
||||
return OQS_ERROR;
|
||||
}
|
||||
memcpy(*signed_msg, signature, signature_len);
|
||||
memcpy(*signed_msg + signature_len, msg, msg_len);
|
||||
return OQS_SUCCESS;
|
||||
{%- else %}
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
{%- endif %}{% endfor %}{% endfor %}
|
||||
|
||||
@ -367,7 +367,7 @@ int PQCLEAN_DILITHIUM2_CLEAN_crypto_sign(uint8_t *sm,
|
||||
* - unsigned long long *mlen: pointer to output length of message
|
||||
* - const unsigned char *sm: pointer to signed message
|
||||
* - unsigned long long smlen: length of signed message
|
||||
* - const unsigned char *sk: pointer to bit-packed public key
|
||||
* - const unsigned char *pk: pointer to bit-packed public key
|
||||
*
|
||||
* Returns 0 if signed message could be verified correctly and -1 otherwise
|
||||
**************************************************/
|
||||
|
||||
@ -367,7 +367,7 @@ int PQCLEAN_DILITHIUM3_CLEAN_crypto_sign(uint8_t *sm,
|
||||
* - unsigned long long *mlen: pointer to output length of message
|
||||
* - const unsigned char *sm: pointer to signed message
|
||||
* - unsigned long long smlen: length of signed message
|
||||
* - const unsigned char *sk: pointer to bit-packed public key
|
||||
* - const unsigned char *pk: pointer to bit-packed public key
|
||||
*
|
||||
* Returns 0 if signed message could be verified correctly and -1 otherwise
|
||||
**************************************************/
|
||||
|
||||
@ -367,7 +367,7 @@ int PQCLEAN_DILITHIUM4_CLEAN_crypto_sign(uint8_t *sm,
|
||||
* - unsigned long long *mlen: pointer to output length of message
|
||||
* - const unsigned char *sm: pointer to signed message
|
||||
* - unsigned long long smlen: length of signed message
|
||||
* - const unsigned char *sk: pointer to bit-packed public key
|
||||
* - const unsigned char *pk: pointer to bit-packed public key
|
||||
*
|
||||
* Returns 0 if signed message could be verified correctly and -1 otherwise
|
||||
**************************************************/
|
||||
|
||||
8
tests/KATs/sig/DILITHIUM_3.kat
Normal file
8
tests/KATs/sig/DILITHIUM_3.kat
Normal file
File diff suppressed because one or more lines are too long
8
tests/KATs/sig/DILITHIUM_4.kat
Normal file
8
tests/KATs/sig/DILITHIUM_4.kat
Normal file
File diff suppressed because one or more lines are too long
172
tests/kat_sig.c
172
tests/kat_sig.c
@ -35,7 +35,9 @@ void fprintBstr(FILE *fp, const char *S, const uint8_t *A, size_t L) {
|
||||
|
||||
OQS_STATUS combine_message_signature(uint8_t **signed_msg, size_t *signed_msg_len, const uint8_t *msg, size_t msg_len, const uint8_t *signature, size_t signature_len, const OQS_SIG *sig) {
|
||||
if (0) {
|
||||
///// OQS_COPY_FROM_PQCLEAN_FRAGMENT_COMBINE_MESSAGE_SIGNATURE_START
|
||||
} else if (0 == strcmp(sig->method_name, "DILITHIUM_2")) {
|
||||
// signed_msg = signature || msg
|
||||
*signed_msg_len = signature_len + msg_len;
|
||||
*signed_msg = malloc(*signed_msg_len);
|
||||
if (*signed_msg == NULL) {
|
||||
@ -44,6 +46,168 @@ OQS_STATUS combine_message_signature(uint8_t **signed_msg, size_t *signed_msg_le
|
||||
memcpy(*signed_msg, signature, signature_len);
|
||||
memcpy(*signed_msg + signature_len, msg, msg_len);
|
||||
return OQS_SUCCESS;
|
||||
} else if (0 == strcmp(sig->method_name, "DILITHIUM_3")) {
|
||||
// signed_msg = signature || msg
|
||||
*signed_msg_len = signature_len + msg_len;
|
||||
*signed_msg = malloc(*signed_msg_len);
|
||||
if (*signed_msg == NULL) {
|
||||
return OQS_ERROR;
|
||||
}
|
||||
memcpy(*signed_msg, signature, signature_len);
|
||||
memcpy(*signed_msg + signature_len, msg, msg_len);
|
||||
return OQS_SUCCESS;
|
||||
} else if (0 == strcmp(sig->method_name, "DILITHIUM_4")) {
|
||||
// signed_msg = signature || msg
|
||||
*signed_msg_len = signature_len + msg_len;
|
||||
*signed_msg = malloc(*signed_msg_len);
|
||||
if (*signed_msg == NULL) {
|
||||
return OQS_ERROR;
|
||||
}
|
||||
memcpy(*signed_msg, signature, signature_len);
|
||||
memcpy(*signed_msg + signature_len, msg, msg_len);
|
||||
return OQS_SUCCESS;
|
||||
} else if (0 == strcmp(sig->method_name, "MQDSS-31-48")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "MQDSS-31-64")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "Rainbow-Ia-Classic")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "Rainbow-Ia-Cyclic")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "Rainbow-Ia-Cyclic-Compressed")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "Rainbow-IIIc-Classic")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "Rainbow-IIIc-Cyclic")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "Rainbow-IIIc-Cyclic-Compressed")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "Rainbow-Vc-Classic")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "Rainbow-Vc-Cyclic")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "Rainbow-Vc-Cyclic-Compressed")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-128f-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-128f-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-128s-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-128s-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-192f-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-192f-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-192s-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-192s-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-256f-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-256f-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-256s-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-Haraka-256s-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-128f-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-128f-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-128s-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-128s-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-192f-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-192f-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-192s-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-192s-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-256f-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-256f-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-256s-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHA256-256s-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-128f-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-128f-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-128s-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-128s-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-192f-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-192f-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-192s-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-192s-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-256f-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-256f-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-256s-robust")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
} else if (0 == strcmp(sig->method_name, "SPHINCS+-SHAKE256-256s-simple")) {
|
||||
// not yet implemented
|
||||
return OQS_ERROR;
|
||||
///// OQS_COPY_FROM_PQCLEAN_FRAGMENT_COMBINE_MESSAGE_SIGNATURE_END
|
||||
} else {
|
||||
return OQS_ERROR;
|
||||
}
|
||||
@ -90,7 +254,7 @@ OQS_STATUS sig_kat(const char *method_name) {
|
||||
|
||||
msg_len = 33 * (0 + 1);
|
||||
fprintf(fh, "mlen = %zu\n", msg_len);
|
||||
|
||||
|
||||
msg = malloc(msg_len);
|
||||
OQS_randombytes(msg, msg_len);
|
||||
fprintBstr(fh, "msg = ", msg, msg_len);
|
||||
@ -104,7 +268,7 @@ OQS_STATUS sig_kat(const char *method_name) {
|
||||
fprintf(stderr, "[kat_sig] %s ERROR: malloc failed!\n", method_name);
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
rc = OQS_SIG_keypair(sig, public_key, secret_key);
|
||||
if (rc != OQS_SUCCESS) {
|
||||
fprintf(stderr, "[kat_sig] %s ERROR: OQS_SIG_keypair failed!\n", method_name);
|
||||
@ -112,7 +276,7 @@ OQS_STATUS sig_kat(const char *method_name) {
|
||||
}
|
||||
fprintBstr(fh, "pk = ", public_key, sig->length_public_key);
|
||||
fprintBstr(fh, "sk = ", secret_key, sig->length_secret_key);
|
||||
|
||||
|
||||
rc = OQS_SIG_sign(sig, signature, &signature_len, msg, msg_len, secret_key);
|
||||
if (rc != OQS_SUCCESS) {
|
||||
fprintf(stderr, "[kat_sig] %s ERROR: OQS_SIG_sign failed!\n", method_name);
|
||||
@ -125,7 +289,7 @@ OQS_STATUS sig_kat(const char *method_name) {
|
||||
}
|
||||
fprintf(fh, "smlen = %zu\n", signed_msg_len);
|
||||
fprintBstr(fh, "sm = ", signed_msg, signed_msg_len);
|
||||
|
||||
|
||||
rc = OQS_SIG_verify(sig, msg, msg_len, signature, signature_len, public_key);
|
||||
if (rc != OQS_SUCCESS) {
|
||||
fprintf(stderr, "[kat_sig] %s ERROR: OQS_SIG_verify failed!\n", method_name);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user