7 changed files with 323 additions and 10 deletions
@ -0,0 +1,301 @@ |
|||||
|
#include daa-test.h |
||||
|
|
||||
|
int test1(); |
||||
|
int test2(); |
||||
|
int test3(); |
||||
|
|
||||
|
int main(int argc, char **argv) { |
||||
|
if(0 != test1()) { |
||||
|
printf("test1 failed\n"); |
||||
|
return 0; |
||||
|
} else { |
||||
|
printf("test1 succeeded\n"); |
||||
|
} |
||||
|
|
||||
|
int test1() { |
||||
|
struct ecdaa_issuer_public_key_FP256BN ipk; |
||||
|
struct ecdaa_issuer_secret_key_FP256BN isk; |
||||
|
struct ecdaa_member_public_key_FP256BN mpk; |
||||
|
struct ecdaa_member_secret_key_FP256BN msk; |
||||
|
uint8_t nonce[NONCE_SIZE]; |
||||
|
struct ecdaa_credential_FP256BN cred; |
||||
|
struct ecdaa_credential_FP256BN_signature cred_sig; |
||||
|
struct ecdaa_issuer_public_key_FP256BN ipk; |
||||
|
uint8_t bsn[MAX_BSNSIZE]; |
||||
|
size_t bsn_len = 0; |
||||
|
uint8_t msg[MAX_MSGSIZE]; |
||||
|
size_t msg_len = 0; |
||||
|
struct ecdaa_revocations_FP256BN revocations; |
||||
|
bzero(bsn, MAX_BSNSIZE); |
||||
|
bzero(msg, MAX_MSGSIZE); |
||||
|
|
||||
|
if(0 != ecdaa_issuer_key_pair_FP256BN_generate(&ipk, &isk, ecdaa_rand)) { |
||||
|
printf("generate issuer key pair failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
ecdaa_rand(nonce, NONCE_SIZE); |
||||
|
if(0 != ecdaa_member_key_pair_FP256BN_generate(&mpk, &msk, nonce, NONCE_SIZE, ecdaa_rand)) { |
||||
|
printf("generate member key pair failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_credential_FP256BN_generate(&cred, &cred_sig, &isk, &mpk, ecdaa_rand)) { |
||||
|
printf("generate credential failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
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"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
strncpy(bsn, "test basename", 13); |
||||
|
bsn_len = strlen(bsn); |
||||
|
|
||||
|
if(0 != ecdaa_signature_FP256BN_sign(&sig, msg, msg_len, bsn, bsn_len, &msk, &cred, ecdaa_rand)) { |
||||
|
printf("signing message with bsn failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_signature_FP256BN_verify(&sig, &gpk, &revocations, msg, msg_len, bsn, bsn_len)) { |
||||
|
printf("verify signature with bsn failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
int test2() { |
||||
|
struct ecdaa_issuer_public_key_FP256BN ipk; |
||||
|
struct ecdaa_issuer_secret_key_FP256BN isk; |
||||
|
struct ecdaa_member_public_key_FP256BN mpk; |
||||
|
struct ecdaa_member_secret_key_FP256BN msk; |
||||
|
struct ecdaa_credential_FP256BN cred; |
||||
|
struct ecdaa_credential_FP256BN_signature cred_sig; |
||||
|
uint8_t nonce[NONCE_SIZE]; |
||||
|
struct ecdaa_issuer_public_key_FP256BN ipk2; |
||||
|
struct ecdaa_issuer_secret_key_FP256BN isk2; |
||||
|
struct ecdaa_member_public_key_FP256BN mpk2; |
||||
|
struct ecdaa_member_secret_key_FP256BN msk2; |
||||
|
struct ecdaa_credential_FP256BN cred2; |
||||
|
struct ecdaa_credential_FP256BN_signature cred_sig2; |
||||
|
uint8_t bsn[MAX_BSNSIZE]; |
||||
|
size_t bsn_len = 0; |
||||
|
uint8_t msg[MAX_MSGSIZE]; |
||||
|
size_t msg_len = 0; |
||||
|
struct ecdaa_revocations_FP256BN revocations; |
||||
|
uint8_t binbuf[MAX_BUFSIZE]; |
||||
|
char buffer[MAX_BUFSIZE]; |
||||
|
bzero(binbuf,MAX_BUFSIZE); |
||||
|
bzero(buffer,MAX_BUFSIZE); |
||||
|
bzero(bsn, MAX_BSNSIZE); |
||||
|
bzero(msg, MAX_MSGSIZE); |
||||
|
|
||||
|
if(0 != ecdaa_issuer_key_pair_FP256BN_generate(&ipk, &isk, ecdaa_rand)) { |
||||
|
printf("generate issuer key pair failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
if(0 != ecdaa_issuer_public_key_FP256BN_serialize_file("ipktest.bin", &ipk) || |
||||
|
0 != ecdaa_issuer_secret_key_FP256BN_serialize_file("isktest.bin", &isk)) { |
||||
|
printf("saving issuer key-pair to disk failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
if(0 != ecdaa_issuer_public_key_FP256BN_deserialize_file(&ipk2, "ipktest.bin") || |
||||
|
0 != ecdaa_issuer_secret_key_FP256BN_deserialize_file(&isk2, "isktest.bin")) { |
||||
|
printf("loading issuer key pair failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
ecdaa_rand(nonce, NONCE_SIZE); |
||||
|
if(0 != ecdaa_member_key_pair_FP256BN_generate(&mpk, &msk, nonce, NONCE_SIZE, ecdaa_rand)) { |
||||
|
printf("generate member key pair failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_member_public_key_FP256BN_serialize_file("mpktest.bin", &mpk) || |
||||
|
0 != ecdaa_member_secret_key_FP256BN_serialize_file("msktest.bin", &msk)) { |
||||
|
printf("saving member key-pair to disk failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
if(0 != ecdaa_member_public_key_FP256BN_deserialize_file(&mpk2, "mpktest.bin") || |
||||
|
0 != ecdaa_member_secret_key_FP256BN_deserialize_file(&msk2, "msktest.bin")) { |
||||
|
printf("loading member key pair failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_credential_FP256BN_generate(&cred, &cred_sig, &isk2, &mpk2, ecdaa_rand)) { |
||||
|
printf("generate credential failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_credential_FP256BN_serialize_file("credtest.bin", &cred)) { |
||||
|
printf("saving credential to disk failed\n"); |
||||
|
} |
||||
|
if(0 != ecdaa_credential_FP256BN_deserialize_file(&cred2, "credtest.bin")) { |
||||
|
printf("loading credential failed\n"); |
||||
|
} |
||||
|
|
||||
|
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)) { |
||||
|
printf("signing message failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig)) { |
||||
|
printf("saving signature to disk failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin")) { |
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
strncpy(bsn, "test basename", 13); |
||||
|
bsn_len = strlen(bsn); |
||||
|
|
||||
|
if(0 != ecdaa_signature_FP256BN_sign(&sig, msg, msg_len, bsn, bsn_len, &msk2, &cred2, ecdaa_rand)) { |
||||
|
printf("signing message with bsn failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig)) { |
||||
|
printf("saving signature to disk failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin")) { |
||||
|
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 signature with bsn failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
return 0; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
int test3() { |
||||
|
struct ecdaa_issuer_public_key_FP256BN ipk; |
||||
|
struct ecdaa_issuer_secret_key_FP256BN isk; |
||||
|
struct ecdaa_member_public_key_FP256BN mpk; |
||||
|
struct ecdaa_member_secret_key_FP256BN msk; |
||||
|
struct ecdaa_credential_FP256BN cred; |
||||
|
struct ecdaa_credential_FP256BN_signature cred_sig; |
||||
|
uint8_t nonce[NONCE_SIZE]; |
||||
|
struct ecdaa_issuer_public_key_FP256BN ipk2; |
||||
|
struct ecdaa_issuer_secret_key_FP256BN isk2; |
||||
|
struct ecdaa_member_public_key_FP256BN mpk2; |
||||
|
struct ecdaa_member_secret_key_FP256BN msk2; |
||||
|
struct ecdaa_credential_FP256BN cred2; |
||||
|
struct ecdaa_credential_FP256BN_signature cred_sig2; |
||||
|
uint8_t bsn[MAX_BSNSIZE]; |
||||
|
size_t bsn_len = 0; |
||||
|
uint8_t msg[MAX_MSGSIZE]; |
||||
|
size_t msg_len = 0; |
||||
|
struct ecdaa_revocations_FP256BN revocations; |
||||
|
uint8_t binbuf[MAX_BUFSIZE]; |
||||
|
char buffer[MAX_BUFSIZE]; |
||||
|
bzero(binbuf,MAX_BUFSIZE); |
||||
|
bzero(buffer,MAX_BUFSIZE); |
||||
|
bzero(bsn, MAX_BSNSIZE); |
||||
|
bzero(msg, MAX_MSGSIZE); |
||||
|
char *current = buffer; |
||||
|
if(0 != ecdaa_issuer_key_pair_FP256BN_generate(&ipk, &isk, ecdaa_rand)) { |
||||
|
printf("generate issuer key pair failed\n"); |
||||
|
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); |
||||
|
|
||||
|
|
||||
|
if(0 != ecdaa_issuer_public_key_FP256BN_deserialize_file(&ipk2, "ipktest.bin") || |
||||
|
0 != ecdaa_issuer_secret_key_FP256BN_deserialize_file(&isk2, "isktest.bin")) { |
||||
|
printf("loading issuer key pair failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
ecdaa_rand(nonce, NONCE_SIZE); |
||||
|
if(0 != ecdaa_member_key_pair_FP256BN_generate(&mpk, &msk, nonce, NONCE_SIZE, ecdaa_rand)) { |
||||
|
printf("generate member key pair failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_member_public_key_FP256BN_serialize_file("mpktest.bin", &mpk) || |
||||
|
0 != ecdaa_member_secret_key_FP256BN_serialize_file("msktest.bin", &msk)) { |
||||
|
printf("saving member key-pair to disk failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
if(0 != ecdaa_member_public_key_FP256BN_deserialize_file(&mpk2, "mpktest.bin") || |
||||
|
0 != ecdaa_member_secret_key_FP256BN_deserialize_file(&msk2, "msktest.bin")) { |
||||
|
printf("loading member key pair failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_credential_FP256BN_generate(&cred, &cred_sig, &isk2, &mpk2, ecdaa_rand)) { |
||||
|
printf("generate credential failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_credential_FP256BN_serialize_file("credtest.bin", &cred)) { |
||||
|
printf("saving credential to disk failed\n"); |
||||
|
} |
||||
|
if(0 != ecdaa_credential_FP256BN_deserialize_file(&cred2, "credtest.bin")) { |
||||
|
printf("loading credential failed\n"); |
||||
|
} |
||||
|
|
||||
|
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)) { |
||||
|
printf("signing message failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig)) { |
||||
|
printf("saving signature to disk failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin")) { |
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
strncpy(bsn, "test basename", 13); |
||||
|
bsn_len = strlen(bsn); |
||||
|
|
||||
|
if(0 != ecdaa_signature_FP256BN_sign(&sig, msg, msg_len, bsn, bsn_len, &msk2, &cred2, ecdaa_rand)) { |
||||
|
printf("signing message with bsn failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_signature_FP256BN_serialize_file("sigtest.bin", &sig)) { |
||||
|
printf("saving signature to disk failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
if(0 != ecdaa_signature_FP256BN_deserialize_file(&sig2, "sigtest.bin")) { |
||||
|
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 signature with bsn failed\n"); |
||||
|
return 1; |
||||
|
} |
||||
|
return 0; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
|
||||
|
#ifndef ECDAA_ISSUER_MEMBER_H |
||||
|
#define ECDAA_ISSUER_MEMBER_H |
||||
|
#include <ecdaa.h> |
||||
|
#include <ecdaa.h> |
||||
|
#include "server.h" |
||||
|
#include "client.h" |
||||
|
#include "common.h" |
||||
Loading…
Reference in new issue