|
|
|
@ -1,4 +1,4 @@ |
|
|
|
#include daa-test.h |
|
|
|
#include "daa-test.h" |
|
|
|
|
|
|
|
int test1(); |
|
|
|
int test2(); |
|
|
|
@ -7,9 +7,20 @@ int test3(); |
|
|
|
int main(int argc, char **argv) { |
|
|
|
if(0 != test1()) { |
|
|
|
printf("test1 failed\n"); |
|
|
|
return 0; |
|
|
|
} else { |
|
|
|
printf("test1 succeeded\n"); |
|
|
|
} |
|
|
|
if(0 != test2()) { |
|
|
|
printf("test2 failed\n"); |
|
|
|
} else { |
|
|
|
printf("test2 succeeded\n"); |
|
|
|
} |
|
|
|
if(0 != test3()) { |
|
|
|
printf("test3 failed\n"); |
|
|
|
} else { |
|
|
|
printf("test3 succeeded\n"); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int test1() { |
|
|
|
@ -20,7 +31,7 @@ int test1() { |
|
|
|
uint8_t nonce[NONCE_SIZE]; |
|
|
|
struct ecdaa_credential_FP256BN cred; |
|
|
|
struct ecdaa_credential_FP256BN_signature cred_sig; |
|
|
|
struct ecdaa_issuer_public_key_FP256BN ipk; |
|
|
|
struct ecdaa_signature_FP256BN sig; |
|
|
|
uint8_t bsn[MAX_BSNSIZE]; |
|
|
|
size_t bsn_len = 0; |
|
|
|
uint8_t msg[MAX_MSGSIZE]; |
|
|
|
@ -44,17 +55,11 @@ int test1() { |
|
|
|
} |
|
|
|
strncpy(msg, "test message\n", 13); |
|
|
|
msg_len = strlen(msg); |
|
|
|
|
|
|
|
if(0 != ecdaa_signature_FP256BN_sign(&sig, msg, msg_len, bsn, bsn_len, &msk, &cred, ecdaa_rand)) { |
|
|
|
printf("signing message failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
if(0 != ecdaa_signature_FP256BN_verify(&sig, &ipk.gpk, &revocations, msg, msg_len, bsn, bsn_len)) { |
|
|
|
printf("verify message with bsn failed\n"); |
|
|
|
if(0 != ecdaa_credential_FP256BN_validate(&cred, &cred_sig, &mpk, &ipk.gpk)) { |
|
|
|
printf("credential verification failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
strncpy(bsn, "test basename", 13); |
|
|
|
bsn_len = strlen(bsn); |
|
|
|
|
|
|
|
@ -62,10 +67,23 @@ int test1() { |
|
|
|
printf("signing message with bsn failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
if(0 != ecdaa_signature_FP256BN_verify(&sig, &gpk, &revocations, msg, msg_len, bsn, bsn_len)) { |
|
|
|
if(0 != ecdaa_signature_FP256BN_verify(&sig, &ipk.gpk, &revocations, msg, msg_len, bsn, bsn_len)) { |
|
|
|
printf("verify signature with bsn failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
bzero(bsn, MAX_BSNSIZE); |
|
|
|
bsn_len = 0; |
|
|
|
if(0 != ecdaa_signature_FP256BN_sign(&sig, msg, msg_len, NULL, bsn_len, &msk, &cred, ecdaa_rand)) { |
|
|
|
printf("signing message failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
if(0 != ecdaa_signature_FP256BN_verify(&sig, &ipk.gpk, &revocations, msg, msg_len, bsn, bsn_len)) { |
|
|
|
printf("verify message failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
@ -76,6 +94,7 @@ int test2() { |
|
|
|
struct ecdaa_member_secret_key_FP256BN msk; |
|
|
|
struct ecdaa_credential_FP256BN cred; |
|
|
|
struct ecdaa_credential_FP256BN_signature cred_sig; |
|
|
|
struct ecdaa_signature_FP256BN sig; |
|
|
|
uint8_t nonce[NONCE_SIZE]; |
|
|
|
struct ecdaa_issuer_public_key_FP256BN ipk2; |
|
|
|
struct ecdaa_issuer_secret_key_FP256BN isk2; |
|
|
|
@ -83,6 +102,7 @@ int test2() { |
|
|
|
struct ecdaa_member_secret_key_FP256BN msk2; |
|
|
|
struct ecdaa_credential_FP256BN cred2; |
|
|
|
struct ecdaa_credential_FP256BN_signature cred_sig2; |
|
|
|
struct ecdaa_signature_FP256BN sig2; |
|
|
|
uint8_t bsn[MAX_BSNSIZE]; |
|
|
|
size_t bsn_len = 0; |
|
|
|
uint8_t msg[MAX_MSGSIZE]; |
|
|
|
@ -123,7 +143,7 @@ int test2() { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
if(0 != ecdaa_member_public_key_FP256BN_deserialize_file(&mpk2, "mpktest.bin") || |
|
|
|
if(0 != ecdaa_member_public_key_FP256BN_deserialize_file(&mpk2, "mpktest.bin", nonce, NONCE_SIZE) || |
|
|
|
0 != ecdaa_member_secret_key_FP256BN_deserialize_file(&msk2, "msktest.bin")) { |
|
|
|
printf("loading member key pair failed\n"); |
|
|
|
return 1; |
|
|
|
@ -141,24 +161,24 @@ int test2() { |
|
|
|
|
|
|
|
strncpy(msg, "test message\n", 13); |
|
|
|
msg_len = strlen(msg); |
|
|
|
|
|
|
|
if(0 != ecdaa_signature_FP256BN_sign(&sig, msg, msg_len, bsn, bsn_len, &msk2, &cred2, ecdaa_rand)) { |
|
|
|
bsn_len = 0; |
|
|
|
if(0 != ecdaa_signature_FP256BN_sign(&sig, msg, msg_len, NULL, bsn_len, &msk2, &cred2, ecdaa_rand)) { |
|
|
|
printf("signing message failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig)) { |
|
|
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig, 0)) { |
|
|
|
printf("saving signature to disk failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin")) { |
|
|
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin", 0)) { |
|
|
|
printf("loading signature failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
if(0 != ecdaa_signature_FP256BN_verify(&sig2, &ipk2.gpk, &revocations, msg, msg_len, bsn, bsn_len)) { |
|
|
|
printf("verify message with bsn failed\n"); |
|
|
|
return 1; |
|
|
|
printf("verify message failed\n"); |
|
|
|
//return 1;
|
|
|
|
} |
|
|
|
|
|
|
|
strncpy(bsn, "test basename", 13); |
|
|
|
@ -168,11 +188,11 @@ int test2() { |
|
|
|
printf("signing message with bsn failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig)) { |
|
|
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig, 1)) { |
|
|
|
printf("saving signature to disk failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin")) { |
|
|
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin", 1)) { |
|
|
|
printf("loading signature failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
@ -191,6 +211,7 @@ int test3() { |
|
|
|
struct ecdaa_member_secret_key_FP256BN msk; |
|
|
|
struct ecdaa_credential_FP256BN cred; |
|
|
|
struct ecdaa_credential_FP256BN_signature cred_sig; |
|
|
|
struct ecdaa_signature_FP256BN sig; |
|
|
|
uint8_t nonce[NONCE_SIZE]; |
|
|
|
struct ecdaa_issuer_public_key_FP256BN ipk2; |
|
|
|
struct ecdaa_issuer_secret_key_FP256BN isk2; |
|
|
|
@ -198,6 +219,7 @@ int test3() { |
|
|
|
struct ecdaa_member_secret_key_FP256BN msk2; |
|
|
|
struct ecdaa_credential_FP256BN cred2; |
|
|
|
struct ecdaa_credential_FP256BN_signature cred_sig2; |
|
|
|
struct ecdaa_signature_FP256BN sig2; |
|
|
|
uint8_t bsn[MAX_BSNSIZE]; |
|
|
|
size_t bsn_len = 0; |
|
|
|
uint8_t msg[MAX_MSGSIZE]; |
|
|
|
@ -215,11 +237,8 @@ int test3() { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
if(0 != ecdaa_issuer_public_key_FP256BN_serialize(binbuf, &ipk)) { |
|
|
|
printf("serialize issuers public key failed"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
ecdaa_bintohex(binbuf, ECDAA_ISSUER_PUBLIC_KEY_FP256BN_LENGTH, current); |
|
|
|
ecdaa_issuer_public_key_FP256BN_serialize(binbuf, &ipk); |
|
|
|
ecdaa_bintohex(binbuf, current, ECDAA_ISSUER_PUBLIC_KEY_FP256BN_LENGTH); |
|
|
|
|
|
|
|
|
|
|
|
if(0 != ecdaa_issuer_public_key_FP256BN_deserialize_file(&ipk2, "ipktest.bin") || |
|
|
|
@ -239,7 +258,7 @@ int test3() { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
if(0 != ecdaa_member_public_key_FP256BN_deserialize_file(&mpk2, "mpktest.bin") || |
|
|
|
if(0 != ecdaa_member_public_key_FP256BN_deserialize_file(&mpk2, "mpktest.bin", nonce, NONCE_SIZE) || |
|
|
|
0 != ecdaa_member_secret_key_FP256BN_deserialize_file(&msk2, "msktest.bin")) { |
|
|
|
printf("loading member key pair failed\n"); |
|
|
|
return 1; |
|
|
|
@ -257,23 +276,24 @@ int test3() { |
|
|
|
|
|
|
|
strncpy(msg, "test message\n", 13); |
|
|
|
msg_len = strlen(msg); |
|
|
|
bsn_len = 0; |
|
|
|
|
|
|
|
if(0 != ecdaa_signature_FP256BN_sign(&sig, msg, msg_len, bsn, bsn_len, &msk2, &cred2, ecdaa_rand)) { |
|
|
|
if(0 != ecdaa_signature_FP256BN_sign(&sig, msg, msg_len, NULL, bsn_len, &msk2, &cred2, ecdaa_rand)) { |
|
|
|
printf("signing message failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig)) { |
|
|
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig, 0)) { |
|
|
|
printf("saving signature to disk failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin")) { |
|
|
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin", 0)) { |
|
|
|
printf("loading signature failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
if(0 != ecdaa_signature_FP256BN_verify(&sig2, &ipk2.gpk, &revocations, msg, msg_len, bsn, bsn_len)) { |
|
|
|
printf("verify message with bsn failed\n"); |
|
|
|
printf("verify message failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
@ -284,11 +304,11 @@ int test3() { |
|
|
|
printf("signing message with bsn failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig)) { |
|
|
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig, 1)) { |
|
|
|
printf("saving signature to disk failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin")) { |
|
|
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin", 1)) { |
|
|
|
printf("loading signature failed\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
@ -297,5 +317,4 @@ int test3() { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|