📄 timing_rsa.c
字号:
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/bn.h>
#include "ippcp.h"
#include "ippcore.h"
#ifdef OPENSSL_NO_RSA
int main(int argc, char *argv[])
{
printf("No RSA support\n");
return(0);
}
#else
#include <openssl/rsa.h>
unsigned char pt0[512]; // copy of actual plain text
unsigned char ct0[512]; // copy of actual cipher text
int plen; // size (bytes) of actual plain text
int clen; // size (bytes) of actual cipher text
#define SetKey \
key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \
key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \
key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \
key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \
key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \
key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \
key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \
key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \
memcpy(pt0, ptext, sizeof(ptext) - 1); \
memcpy(ct0, ctext, sizeof(ctext) - 1); \
plen = sizeof(ptext) - 1; \
clen = sizeof(ctext) - 1; \
return (sizeof(n)-1)*8;
static int key128(RSA *key)
{
static unsigned char n[] =
"\x95\x08\xfa\xca\xcd\xf2\x97\xb8\x26\xa4\x92\x6a\xe0\x8c\x6f\x27";
static unsigned char p[] =
"\xd2\xd6\x49\x54\x74\x2c\xc8\xb9";
static unsigned char q[] =
"\xb4\xf5\xa5\x51\x82\x5f\x46\xdf";
static unsigned char e[] =
"\x2f\xe2\x8a\xad\xe2\xdb\x92\x88\x28\xf0\x34\x7a\x69\xbe\xbb\x41";
static unsigned char d[] =
"\x0b\x34\xab\x03\x9d\xfd\xad\x4c\xf3\x4d\x76\x9f\x73\x44\x63\x21";
static unsigned char dmp1[] =
"\x66\x1d\x6c\x94\x81\xe0\x09\xf9";
static unsigned char dmq1[] =
"\xa6\x6a\xf8\xe3\x96\x8d\xc4\x0d";
static unsigned char iqmp[] =
"\x4a\x61\xb5\x0c\x24\x58\x32\x90";
static unsigned char ptext[] =
"\x52\x2d\x2e\xe9\x7a\xff\x90\x7e\xf4\xca\xa9\x07\x87\x1b\x5c\x27";
static unsigned char ctext[] =
"\x71\x28\x70\x57\x77\x4d\xa1\x1c\xb6\x3e\xce\x94\x93\xc4\xa6\x5f";
SetKey;
}
static int key160(RSA *key)
{
static unsigned char n[] =
"\x9b\x2a\xa5\x84\xb2\x14\xfb\x4f\x96\xa2\xdc\x28\x02\x16\x0b\xa7"
"\x62\xde\x57\xab";
static unsigned char p[] =
"\x00\x00\xf5\xab\xc0\xd0\xe1\xe3\x92\x72\x7a\xdf";
static unsigned char q[] =
"\x00\x00\xa1\xb0\xc3\x0b\x66\x49\xb5\x39\x88\xb5";
static unsigned char e[] =
"\x7a\x1d\x99\xaa\x13\xd2\xcf\x22\x31\xfd\x6a\x0b\x6a\x72\xa6\xbd"
"\x04\xd9\x4d\x19";
static unsigned char d[] =
"\x90\xc3\x26\x8e\xd9\x63\xdc\xf2\x76\x4a\x32\x85\xe2\x4f\xaa\x44"
"\x30\x54\x78\x91";
static unsigned char dmp1[] =
"\x00\x00\x41\x12\xb8\x83\xef\x22\xc8\xf2\x3a\xdf";
static unsigned char dmq1[] =
"\x00\x00\x51\xe0\xd6\xfa\x2d\xf8\x0c\x85\xc5\xdd";
static unsigned char iqmp[] =
"\x00\x00\x63\xb5\x1e\x18\x7d\xe8\x5c\x09\xf0\xde";
static unsigned char ptext[] =
"\x5b\x62\x1f\xdb\x47\xb3\xd0\x57\x33\xdb\x02\x9d\x7c\xaa\x9b\xe8"
"\x70\x11\xad\x1c";
static unsigned char ctext[] =
"\x1a\xda\x32\x2f\xdd\xe1\x33\x3f\x17\x32\xfd\x3c\x9a\x5c\xab\xb1"
"\xf1\x1c\x48\x42";
SetKey;
}
static int key192(RSA *key)
{
static unsigned char n[] =
"\xc7\x0f\x96\x59\x3c\x25\xd3\xc1\x1f\x2e\xd3\xe9\xa9\x25\x2c\xc5"
"\xa4\x89\xbd\x01\x89\xf9\xbd\x05";
static unsigned char p[] =
"\xe4\x21\xb6\x51\xfb\xf9\x2b\x0e\x86\xc5\x5e\x85";
static unsigned char q[] =
"\xdf\x60\xc0\xe2\xdc\x67\x18\xeb\xaf\xa1\x6c\x81";
static unsigned char e[] =
"\x33\x05\xf2\xcd\x7a\x1d\x99\xaa\x13\xd2\xcf\x22\x31\xfd\x6a\x0b"
"\x6a\x72\xa6\xbd\x04\xd9\x4d\x17";
static unsigned char d[] =
"\x83\xe2\x0f\x59\x81\x7f\x1a\x98\x8c\x72\x4e\x13\x24\x48\x83\x01"
"\x5c\x31\xa9\xf4\xaf\x2b\x28\xa7";
static unsigned char dmp1[] =
"\x60\x67\x07\xa3\x4f\x4a\x32\xbc\xae\xfc\x5b\xb7";
static unsigned char dmq1[] =
"\xcb\x05\xb3\x16\x28\x94\xa3\x89\x8d\xa3\x97\xa7";
static unsigned char iqmp[] =
"\xc5\xe5\xd7\xc9\x1e\x1b\xdb\x95\x24\xab\x40\xc3";
static unsigned char ptext[] =
"\x77\x39\xf3\xa4\x0a\x13\xc1\xa3\xf9\x94\x7d\xb0\xb7\xdd\xf8\x51"
"\x57\xf1\x2e\x55\x86\xc6\x18\x3f";
static unsigned char ctext[] =
"\x89\x80\xbe\xdb\x3a\x0a\x97\x2d\x0a\x7b\x7c\x7a\xe4\x2a\xdf\xac"
"\x60\xa1\x92\x3d\x6b\x6e\x47\xf8";
SetKey;
}
static int key224(RSA *key)
{
static unsigned char n[] =
"\x69\x0a\xe1\x79\x5d\xa4\x78\x4f\xdd\x91\x2d\x4d\xb8\xd2\x4f\xcd"
"\x72\x4a\x53\x5a\x80\x83\x4d\x9c\x69\x3c\x29\x63";
static unsigned char p[] =
"\x00\x00\xab\x33\x8a\x52\xaf\xed\x66\xb6\xe9\x6f\xa6\xb3\xb1\xc1";
static unsigned char q[] =
"\x00\x00\x9d\x12\x59\xbf\x6a\xc1\x38\x49\x17\x49\x3a\x29\xdc\x23";
static unsigned char e[] =
"\x02\xa4\xc2\x89\xd4\x08\x2f\xb6\xd1\x61\x02\x1d\x77\x11\x83\x26"
"\x54\xa3\x59\xdc\x47\x6c\xe7\x96\xe1\x60\x1f\xc3";
static unsigned char d[] =
"\x57\x8c\x68\x6e\xe8\xac\x97\xde\x09\x89\x8b\x6f\x49\x6c\x6a\x53"
"\x23\x03\x8e\xca\x9f\xf4\x71\xb5\xa7\x78\x6b\xeb";
static unsigned char dmp1[] =
"\x00\x00\xa6\xc7\xe1\x4b\xc9\x7e\xfd\xd7\x26\xf5\x85\x7b\xf5\x6b";
static unsigned char dmq1[] =
"\x00\x00\x0b\xb9\xda\x26\xc6\x99\x37\xa9\x1f\xc8\xa6\xce\x97\x0f";
static unsigned char iqmp[] =
"\x00\x00\x01\x26\xff\xa9\x0f\x72\xa5\x07\xa3\x3a\x69\x33\xf5\x85";
static unsigned char ptext[] =
"\x48\xc5\xd2\xc0\x8e\xf3\xe9\x78\xe6\x91\x0c\xc9\x26\x35\x84\x71"
"\x4b\x07\x2d\x02\x2b\xae\x45\x99\xa9\xfb\x01\x78";
static unsigned char ctext[] =
"\x59\xe2\x40\x98\xaa\x5f\x96\xa2\x7b\xb7\x2e\x54\x59\xea\x1c\x07"
"\xdd\xa0\x12\x82\x37\x73\xb5\x2a\xb9\x85\x48\xa1";
SetKey;
}
static int key256(RSA *key)
{
static unsigned char n[] =
"\x65\xd8\x37\x9c\x9c\x49\xec\x91\x16\xc6\xc0\xd6\x0e\x14\x74\x44"
"\x8a\xf8\xfe\x5c\xf6\x38\x7a\x2a\x34\xfc\xf3\xd5\x4b\x23\x37\x39";
static unsigned char p[] =
"\xbe\xbc\xd2\x70\x29\xfd\x8c\x4b\x4f\x76\xae\x8b\x32\x34\xdb\xe5";
static unsigned char q[] =
"\x88\xb1\x09\xbf\xc6\xd8\x5b\xec\xc4\x7d\x74\xc0\x5b\x3e\x00\xc5";
static unsigned char e[] =
"\x31\xec\x74\x39\x6b\xaf\xa4\x03\x31\xac\xa8\x06\xae\xf2\x2f\x6b"
"\x2f\xe2\x8a\xad\xe2\xdb\x92\x88\x28\xf0\x34\x7a\x69\xbe\xbb\x41";
static unsigned char d[] =
"\x38\xf5\xb4\x41\x6a\x7d\x9f\x62\x9e\x57\x04\xcc\xde\x4a\xd9\xa8"
"\x99\x12\x99\x6d\xa8\xea\xf8\xba\x08\x1b\x38\x85\x5f\x18\x04\xc1";
static unsigned char dmp1[] =
"\x65\xc9\xda\xdb\xe8\xd6\xd9\x43\x9a\x04\x88\x0f\x07\xb6\xb3\x19";
static unsigned char dmq1[] =
"\x2b\x54\x9c\xe8\x76\xcd\x40\xb0\xcb\xb1\x3b\xa8\xd9\x29\x15\xbd";
static unsigned char iqmp[] =
"\x36\xcb\xb2\x5c\x84\xd5\xe5\x6f\x92\x21\x4a\xd6\x6b\xbe\x5b\x51";
static unsigned char ptext[] =
"\x4e\x18\xfd\x27\x06\x74\xa2\x3f\xe0\x43\xd3\x9b\xb2\x1e\xee\x75"
"\x90\xae\x5f\x67\xf3\x45\x81\xdd\xd3\xf4\x8a\xc3\x74\x1c\x58\x60";
static unsigned char ctext[] =
"\x44\x67\xc7\x82\x39\xad\x7d\x51\xc8\x53\x6d\x6f\x61\xf0\x00\x94"
"\x95\xb1\x8d\xba\x19\x22\x94\x50\x3d\xa0\x84\x65\x16\x7f\xa7\xe5";
SetKey;
}
static int key384(RSA *key)
{
static unsigned char n[] =
"\xad\xb0\xef\xf7\xbd\xd0\x9e\x97\x03\xa7\x4d\x99\xc2\x32\xf6\x1f"
"\x9b\x77\x71\xdc\x89\xca\x91\x54\xc6\x59\x5e\x62\xe9\xcb\x48\x0f"
"\x29\x55\xdd\x15\x1d\x5b\xf8\x9c\x8f\xa3\x45\x3f\x6d\xd9\x9e\xb9";
static unsigned char p[] =
"\xd5\x14\xce\x08\x31\xa7\xa3\xa6\xe2\xc5\x31\x70\xb2\xdc\x3f\xc6"
"\x72\x37\xbb\xa1\xad\x6d\x9b\xe3";
static unsigned char q[] =
"\xd0\xad\x0b\x6c\x13\x96\x39\xfb\xf4\x05\x51\x6e\x73\xc6\x59\xd5"
"\xb1\x25\x31\x18\xa5\xa4\x15\xb3";
static unsigned char e[] =
"\x6a\x72\xa6\xbd\x04\xd9\x4d\x16\x55\xac\xad\x4d\x81\xef\x20\xb3"
"\x46\xf8\x0f\x4a\x2b\xf7\x4a\x28\xde\x57\x09\x79\x92\xb4\x04\xe5"
"\x56\x58\x8c\xed\x6c\x1a\xcd\x4e\xbf\x05\x3f\x68\x09\xf7\x3a\x93";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -