/* Copyright 2014, Kenneth MacKay. Licensed under the BSD 2-clause license. */
#include "uECC.h"
#include <stdio.h>
#include <string.h>
int ecc_rng(uint8_t *dest,unsigned size);
int TestEcdsa() {
int i, c;
uint8_t private[32] = {0};
uint8_t public[64] = {0};
uint8_t hash[32] = {0};
uint8_t sig[64] = {0};
//unsigned char *plat_public = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEFBfm3uQdpKNVVLWO1OQlvC/LEdBG6V68//nzEmeQnL83xWJPs16HBLvxsax2rRICQTTkf4F9fyLG4bjSoYBpkg==";
//unsigned char *plat_hash[32] = {0};
//unsigned char *plat_sig = "MEQCIEEgzmiGBWHLYJ1hg0cKi4KCAUX6MLDfHIMfmPlAwSsOAiA4tKnLfab+wVr8M1KEpsCCoDN89mKorzzxez9IZenqpg==";
uECC_set_rng(ecc_rng);
uECC_Curve _secp256r1 = uECC_secp256r1();
uECC_Curve _secp256k1 = uECC_secp256k1();
uint8_t beigu_public[64] = {
0x85, 0xC2, 0xDD, 0x2D, 0x2E, 0x52, 0x18, 0x35, 0x9B, 0xA1, 0xDD, 0x25, 0xB3, 0x6F, 0x02, 0xF4, 0xD7, 0x7C, 0x25, 0xF9, 0xD7, 0x4F, 0x49, 0x3C, 0x41, 0x76, 0xCE, 0x08, 0x19, 0x91, 0xCF, 0x0F, 0x7B, 0x2E, 0x28, 0xD0, 0x0E, 0x55, 0x69, 0xAE, 0xC1, 0x11, 0x47, 0x3D, 0xB8, 0x8F, 0x0D, 0x76, 0xE9, 0xF9, 0x65, 0x8C, 0x4A, 0x83, 0x0D, 0xF5, 0xAE, 0x78, 0x69, 0xB4, 0x8D, 0x96, 0x5B, 0x64
};
uint8_t beigu_hash[32] = {0x76, 0x29, 0x4f, 0x8e, 0xc5, 0x36, 0xed, 0x41, 0x8f, 0x12, 0x26, 0x0e, 0xea, 0xb3, 0x5f, 0xa5, 0xf9, 0x0a, 0xb5, 0xc3, 0xec, 0xdd, 0xbd, 0xd6, 0x51, 0x57, 0xa9, 0x60, 0xd0, 0x2f, 0xe8, 0x61};
uint8_t beigu_sig[64] = {0x4F, 0xC8, 0x14, 0xA7, 0x23, 0x47, 0x6C, 0xBC, 0x22, 0x13, 0xE5, 0xB2, 0x92, 0x32, 0xA1, 0x01, 0x71, 0xEB, 0x8B, 0x99, 0x67, 0x93, 0xD7, 0xC2, 0xBC, 0x52, 0x1B, 0xA2, 0xF6, 0x86, 0x34, 0x87, 0x62, 0xA5, 0xCF, 0xC7, 0x6B, 0xF6, 0xF1, 0x48, 0x28, 0x48, 0x02, 0xC2, 0x60, 0x60, 0xF8, 0xDE, 0x9F, 0xD8, 0x4C, 0xDA, 0xF2, 0xE5, 0x52, 0x6A, 0xCF, 0x49, 0x2B, 0xDA, 0x9C, 0xF4, 0x41, 0xD5};
//memcpy(beigu_hash, beigu_public, sizeof(beigu_hash));
if (!uECC_verify(beigu_public, beigu_hash, sizeof(beigu_hash), beigu_sig, _secp256r1)) {
printf("=====1 beigu uECC_verify() failed\n");
}
if (!uECC_verify(beigu_public, beigu_hash, sizeof(beigu_hash), beigu_sig, _secp256k1)) {
printf("=====2 beigu uECC_verify() failed\n");
}
const struct uECC_Curve_t * curves[5];
int num_curves = 0;
#if uECC_SUPPORTS_secp160r1
curves[num_curves++] = uECC_secp160r1();
#endif
#if uECC_SUPPORTS_secp192r1
curves[num_curves++] = uECC_secp192r1();
#endif
#if uECC_SUPPORTS_secp224r1
curves[num_curves++] = uECC_secp224r1();
#endif
#if uECC_SUPPORTS_secp256r1
curves[num_curves++] = uECC_secp256r1();
#endif
#if uECC_SUPPORTS_secp256k1
curves[num_curves++] = uECC_secp256k1();
#endif
printf("Testing 256 signatures\n");
for (c = 0; c < num_curves; ++c) {
for (i = 0; i < 256; ++i) {
printf(".");
fflush(stdout);
if (!uECC_make_key(public, private, curves[c])) {
printf("uECC_make_key() failed\n");
return 1;
}
memcpy(hash, public, sizeof(hash));
if (!uECC_sign(private, hash, sizeof(hash), sig, curves[c])) {
printf("uECC_sign() failed\n");
return 1;
}
if (!uECC_verify(public, hash, sizeof(hash), sig, curves[c])) {
printf("uECC_verify() failed\n");
return 1;
}
}
printf("\n");
}
return 0;
}