36void print_buf(
unsigned char *buf,
int len,
int brk, FILE *ofp);
38int main(
int argc,
char *argv[]) {
39 int buf_len, msg_len, i;
44 fprintf(stderr,
"Usage: %s <bufsize> <msglen>\n", argv[0]);
48 srand((
unsigned int)time(NULL));
50 if ((buf_len = atoi(argv[1])) <= 0) {
51 fprintf(stderr,
"Buffer length must be positive, not %d\n", buf_len);
54 if ((msg_len = atoi(argv[2])) <= 0) {
55 fprintf(stderr,
"Message length must be positive, not %d\n", msg_len);
58 if (msg_len > buf_len) msg_len = buf_len;
60 buf = calloc(buf_len,
sizeof(*buf));
61 for (i = 0; i < msg_len; ++i) buf[i] = i + 1;
64 "Buffer size: %d bytes\n"
65 "Message len: %d bytes\n\n",
74 printf(
"Error from encoding function: %d\n",
res);
78 printf(
"Encoded message:\n");
84 printf(
"Error from decoding function: %d\n",
res);
88 printf(
"Decoded message (%d bytes):\n", msg_len);
99 for (i = 0; i < len; ++i) {
102 while (c == 0) c = (
unsigned char)rand();
108void print_buf(
unsigned char *buf,
int len,
int brk, FILE *ofp) {
111 for (i = 0; i < len; ++i) {
112 fprintf(ofp,
"%02X", buf[i]);
114 if ((i + 1) % brk == 0)
119 if (i % brk) fputc(
'\n', ofp);
mp_result rsa_pkcs1v15_encode(unsigned char *buf, int msg_len, int buf_len, int tag, random_f filler)
mp_result rsa_pkcs1v15_decode(unsigned char *buf, int buf_len, int tag, int *msg_len)
void random_fill(unsigned char *buf, int len)
void print_buf(unsigned char *buf, int len, int brk, FILE *ofp)