| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <stdlib.h>
- #include "rsa.h"
- #include "keys.h"
- int rsa3072_test(void){
- int ret;
- rsa_pk_t pk = {0};
- rsa_sk_t sk = {0};
- uint8_t signature[384];
- uint32_t signLen;
- // message hash to sign
- uint8_t hash[32] = {0x7c, 0x14, 0x67, 0x8e, 0x4d, 0x24, 0x66, 0xb2, 0xb5, 0xd1, 0xce, 0x38, 0xc7, 0x68, 0xa9, 0x38,
- 0x37, 0xa9, 0x09, 0x35, 0x41, 0x2f, 0x56, 0xd7, 0xec, 0xd7, 0xab, 0xea, 0x4b, 0x43, 0x19, 0x8b};
- uint32_t hashLen = 32;
- uint32_t saltLen = 20;
- // copy keys.h message about public key and private key to the flash RAM
- pk.bits = KEY_M_BITS;
- memcpy(&pk.modulus [RSA_MAX_MODULUS_LEN-sizeof(key_m) ], key_m, sizeof(key_m ));
- memcpy(&pk.exponent [RSA_MAX_MODULUS_LEN-sizeof(key_e) ], key_e, sizeof(key_e ));
- sk.bits = KEY_M_BITS;
- memcpy(&sk.modulus [RSA_MAX_MODULUS_LEN-sizeof(key_m) ], key_m, sizeof(key_m ));
- memcpy(&sk.public_exponet [RSA_MAX_MODULUS_LEN-sizeof(key_e) ], key_e, sizeof(key_e ));
- memcpy(&sk.exponent [RSA_MAX_MODULUS_LEN-sizeof(key_pe)], key_pe, sizeof(key_pe));
- memcpy(&sk.prime1 [RSA_MAX_PRIME_LEN - sizeof(key_p1)], key_p1, sizeof(key_p1));
- memcpy(&sk.prime2 [RSA_MAX_PRIME_LEN - sizeof(key_p2)], key_p2, sizeof(key_p2));
- memcpy(&sk.prime_exponent1 [RSA_MAX_PRIME_LEN - sizeof(key_e1)], key_e1, sizeof(key_e1));
- memcpy(&sk.prime_exponent2 [RSA_MAX_PRIME_LEN - sizeof(key_e2)], key_e2, sizeof(key_e2));
- memcpy(&sk.coefficient [RSA_MAX_PRIME_LEN - sizeof(key_c) ], key_c, sizeof(key_c ));
- ret = rsassaPssSign(signature, &signLen, hash, hashLen, saltLen, &sk);
- if (ret) {
- printf("rsassaPssSign fail.\n");
- return -1;
- }
- ret = rsassaPssVerify(signature, signLen, hash, hashLen, saltLen, &pk);
- if (ret) {
- printf("rsassaPssVerify fail.\n");
- return -1;
- } else {
- printf("rsassaPssVerify ok.\n");
- }
- ret = rsassaPkcs1v15Sign(signature, &signLen, hash, hashLen, &sk);
- if (ret) {
- printf("rsassaPkcs1v15Sign fail.\n");
- return -1;
- }
- ret = rsassaPkcs1v15Verify(signature, signLen, hash, hashLen, &pk);
- if (ret) {
- printf("rsassaPkcs1v15Verify fail.\n");
- return -1;
- } else {
- printf("rsassaPkcs1v15Verify ok.\n");
- }
- return 0;
- }
|