version 1.1, 2004/05/16 15:04:54 |
version 1.2, 2004/08/16 03:59:58 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/ox_ntl/crypt/rsa/ntlrsatest.cpp,v 1.1 2004/05/16 15:04:54 iwane Exp $ */ |
|
|
#include "ntlrsa.h" |
#include "ntlrsa.h" |
#include <stdio.h> |
#include <stdio.h> |
#include <string.h> |
#include <string.h> |
|
|
|
static void |
|
enctest(NtlRsa *rsa, const char *C) |
|
{ |
|
unsigned char code[1024]; |
|
unsigned char buf[1024]; |
|
int a1 = rsa->encryptByPublicKey(code, C); |
|
int a2 = rsa->decryptByPrivateKey(buf, code); |
|
|
|
printf("<%2d>: [%s] ==> [%s][%02x %02x %02x %02x %02x]", strncmp(C, (char *)buf, a1), C, buf, buf[0], buf[1], buf[2], buf[3], buf[4]); |
|
printf("%d %d %d\n", a1, a2, strlen(C)); |
|
if (a1 < 0 || a2 < 0) { |
|
printf("error\n"); |
|
exit(-1); |
|
} |
|
|
|
a1 = rsa->encryptByPrivateKey(code, C); |
|
a2 = rsa->decryptByPublicKey(buf, code); |
|
printf("<%2d>: [%s] ==> [%s]", strncmp(C, (char *)buf, a2), C, buf); |
|
printf("\t\t%d %d\n", a1, a2); |
|
if (a1 < 0 || a2 < 0) { |
|
printf("error\n"); |
|
exit(-1); |
|
} |
|
} |
|
|
/* |
/* |
* example: NtlRsa |
* example: NtlRsa |
*/ |
*/ |
Line 24 main(int argc, char *argv[]) |
|
Line 49 main(int argc, char *argv[]) |
|
|
|
|
|
|
|
#define enctest(C) do { \ |
|
a1 = rsa.encryptByPublicKey(code, C); \ |
|
a2 = rsa.decryptByPrivateKey(buf, code); \ |
|
printf("<%2d>: [%s] ==> [%s][%02x %02x %02x %02x %02x]", strncmp(C, (char *)buf, a1), C, buf, buf[0], buf[1], buf[2], buf[3], buf[4]); \ |
|
printf("%d %d %d\n", a1, a2, strlen(C)); \ |
|
if (a1 < 0 || a2 < 0) { printf("error\n"); return (-1); } \ |
|
a1 = rsa.encryptByPrivateKey(code, C); \ |
|
a2 = rsa.decryptByPublicKey(buf, code); \ |
|
printf("<%2d>: [%s] ==> [%s]", strncmp(C, (char *)buf, a2), C, buf); \ |
|
printf("\t\t%d %d\n", a1, a2); \ |
|
if (a1 < 0 || a2 < 0) { printf("error\n"); return (-1); } \ |
|
} while (0) |
|
|
|
for (int i = 0; i < argc; i++) { |
for (int i = 0; i < argc; i++) { |
enctest(argv[i]); |
enctest(&rsa, argv[i]); |
} |
} |
|
|
char *ptr = msg; |
char *ptr = msg; |
Line 74 main(int argc, char *argv[]) |
|
Line 86 main(int argc, char *argv[]) |
|
p += a2; |
p += a2; |
} |
} |
|
|
cout << "decrypt: " << strcmp((char *)buf, msg) << ": " << buf << endl; |
cout << "decrypt: " << strcmp((char *)buf, msg) << endl; |
} |
} |
|
|
|
|