From fb4cf7b5c6e5f28d886bd4216f09b8052c7bd013 Mon Sep 17 00:00:00 2001 From: bg Date: Sat, 25 Sep 2010 12:08:28 +0000 Subject: [PATCH] adding RSA --- mkfiles/rsa.mk | 14 +++ rsa/random_message_1024 | 1 + rsa/random_message_1024.enc | 1 + rsa/random_message_1024.plain | 1 + rsa/rsa.c | 36 +++++++ rsa/rsa.h | 44 ++++++++ rsa/rsa_der_structure | 12 +++ rsa/rsa_key_blob.c | 179 +++++++++++++++++++++++++++++++++ rsa/rsa_key_blob.h | 25 +++++ rsa/rsa_privatekey_1024.ascii | 15 +++ rsa/rsa_privatekey_2048.ascii | 27 +++++ rsa/rsa_privatekey_2048.der | Bin 0 -> 1192 bytes rsa/rsa_publickey_2048.ascii | 9 ++ rsa/rsa_publickey_2048.der | Bin 0 -> 294 bytes test_src/main-rsa-test.c | 182 ++++++++++++++++++++++++++++++++++ 15 files changed, 546 insertions(+) create mode 100644 mkfiles/rsa.mk create mode 100644 rsa/random_message_1024 create mode 100644 rsa/random_message_1024.enc create mode 100644 rsa/random_message_1024.plain create mode 100644 rsa/rsa.c create mode 100644 rsa/rsa.h create mode 100644 rsa/rsa_der_structure create mode 100644 rsa/rsa_key_blob.c create mode 100644 rsa/rsa_key_blob.h create mode 100644 rsa/rsa_privatekey_1024.ascii create mode 100644 rsa/rsa_privatekey_2048.ascii create mode 100644 rsa/rsa_privatekey_2048.der create mode 100644 rsa/rsa_publickey_2048.ascii create mode 100644 rsa/rsa_publickey_2048.der create mode 100644 test_src/main-rsa-test.c diff --git a/mkfiles/rsa.mk b/mkfiles/rsa.mk new file mode 100644 index 0000000..5158be9 --- /dev/null +++ b/mkfiles/rsa.mk @@ -0,0 +1,14 @@ +# Makefile for RSA +ALGO_NAME := RSA + +# comment out the following line for removement of RSA from the build process +PK_CIPHERS += $(ALGO_NAME) + +$(ALGO_NAME)_DIR := rsa/ +$(ALGO_NAME)_INCDIR := bigint/ noekeon/ memxor/ +$(ALGO_NAME)_OBJ := bigint.o bigint_io.o bigint_add_u.o rsa.o rsa_key_blob.o +$(ALGO_NAME)_TEST_BIN := main-rsa-test.o $(CLI_STD) \ + noekeon_asm.o noekeon_prng.o memxor.o + +$(ALGO_NAME)_PERFORMANCE_TEST := performance + diff --git a/rsa/random_message_1024 b/rsa/random_message_1024 new file mode 100644 index 0000000..f8f3e82 --- /dev/null +++ b/rsa/random_message_1024 @@ -0,0 +1 @@ +%rW¿F»Vè $ rwì¹äoàlƒeâå<ÛlQ¼Ð0¶Ê´醆þvN·Gµ’8 <úSããWë4¸Ú{(JÌVó@.#EçÍяªUU}½c½ÚýÑbCÇ39,Úd'– ƒ ù;qYªC;ë€ \ No newline at end of file diff --git a/rsa/random_message_1024.enc b/rsa/random_message_1024.enc new file mode 100644 index 0000000..31f140d --- /dev/null +++ b/rsa/random_message_1024.enc @@ -0,0 +1 @@ +Á÷S¶¶Še9á%ŽŸZ0霘QßÓf1 3“ž(‘(áG®ûʁŸÞFJ¦‘|c×upªeÍÚ?— 5$#—J˜Íôíåʽþÿˆf¨möÁÌfð¯„#''*TÈBÙ¶ÝêKR>Tu茼íp¤*QÁžŸÝ¾aÂ.WÏ[` \ No newline at end of file diff --git a/rsa/random_message_1024.plain b/rsa/random_message_1024.plain new file mode 100644 index 0000000..f8f3e82 --- /dev/null +++ b/rsa/random_message_1024.plain @@ -0,0 +1 @@ +%rW¿F»Vè $ rwì¹äoàlƒeâå<ÛlQ¼Ð0¶Ê´醆þvN·Gµ’8 <úSããWë4¸Ú{(JÌVó@.#EçÍяªUU}½c½ÚýÑbCÇ39,Úd'– ƒ ù;qYªC;ë€ \ No newline at end of file diff --git a/rsa/rsa.c b/rsa/rsa.c new file mode 100644 index 0000000..0281c7e --- /dev/null +++ b/rsa/rsa.c @@ -0,0 +1,36 @@ +/* rsa_enc.c */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include "cli.h" +#include "bigint/bigint.h" +#include "rsa.h" + +uint8_t rsa_enc_bigint(bigint_t* c, const bigint_t* m, + const rsa_ctx_t* ctx){ + bigint_expmod_u(c, m, &(ctx->pubexp), &(ctx->modulus)); + return 0; +} + +uint8_t rsa_dec_bigint(bigint_t* m, const bigint_t* c, + const rsa_ctx_t* ctx){ + bigint_expmod_u(m, c, &(ctx->privexp), &(ctx->modulus)); + return 0; +} + diff --git a/rsa/rsa.h b/rsa/rsa.h new file mode 100644 index 0000000..2d5c772 --- /dev/null +++ b/rsa/rsa.h @@ -0,0 +1,44 @@ +/* rsa.h */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef RSA_H_ +#define RSA_H_ + +#include +#include "hfal/hfal-basic.h" +#include "bigint/bigint.h" + + +typedef bigint_t rsa_modulus_t; +typedef bigint_t rsa_pubexp_t; +typedef bigint_t rsa_privexp_t; + +typedef struct{ + rsa_modulus_t modulus; + rsa_pubexp_t pubexp; + rsa_privexp_t privexp; +} rsa_ctx_t; + + +uint8_t rsa_enc_bigint(bigint_t* c, const bigint_t* m, + const rsa_ctx_t* ctx); +uint8_t rsa_dec_bigint(bigint_t* m, const bigint_t* c, + const rsa_ctx_t* ctx); + +#endif /* RSA_H_ */ diff --git a/rsa/rsa_der_structure b/rsa/rsa_der_structure new file mode 100644 index 0000000..33b75f6 --- /dev/null +++ b/rsa/rsa_der_structure @@ -0,0 +1,12 @@ + struct + { + BIGNUM *n; // public modulus + BIGNUM *e; // public exponent + BIGNUM *d; // private exponent + BIGNUM *p; // secret prime factor + BIGNUM *q; // secret prime factor + BIGNUM *dmp1; // d mod (p-1) + BIGNUM *dmq1; // d mod (q-1) + BIGNUM *iqmp; // q^-1 mod p + // ... + }; diff --git a/rsa/rsa_key_blob.c b/rsa/rsa_key_blob.c new file mode 100644 index 0000000..1a7a622 --- /dev/null +++ b/rsa/rsa_key_blob.c @@ -0,0 +1,179 @@ +/* rsa_key_blob.c */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include +#include "cli.h" +#include "rsa.h" +#include "bigint/bigint.h" + +#define RSA_KEYSIZE 1024 + +#if RSA_KEYSIZE == 2048 +#define N_LEN_B (32*8) +#define E_LEN_B (3) +#define D_LEN_B (32*8) +#define ALL_LEN_B (N_LEN_B+E_LEN_B+D_LEN_B) + +static uint8_t rsa_key_blob[] PROGMEM = { + /* n */ + 0xDA, 0xBC, 0x4A, 0x42, 0x02, 0x6F, 0x7F, 0xC2, + 0xEB, 0x5A, 0x73, 0x2A, 0x84, 0x25, 0xB5, 0x56, + 0xC7, 0x99, 0x25, 0x0A, 0x50, 0x6F, 0x00, 0xAE, + 0x84, 0x5C, 0x19, 0x30, 0xC6, 0xDE, 0xAF, 0xC6, + 0x30, 0xC8, 0xD0, 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xC4, 0xB0, 0xC5, 0x25, 0xEC, 0xD1, + 0x5C, 0xC3, 0x2C, 0x40, 0x1E, 0x28, 0x42, 0x1E, + 0xC7, 0x26, 0xAB, 0x9E, 0x5A, 0xB9, 0x22, 0xB9, + 0x44, 0x14, 0xC8, 0x1D, 0x51, 0x64, 0x4F, 0xE3, + 0xA0, 0x04, 0x48, 0x04, 0x55, 0x4B, 0xCE, 0x8B, + 0x11, 0x00, 0xCB, 0x85, 0x93, 0x8B, 0x06, 0xCE, + 0x33, 0x0D, 0xA6, 0xB8, 0xBA, 0x5F, 0xC0, 0x3C, + 0x5A, 0xB0, 0x0B, 0x0C, 0x68, 0xE2, 0x4F, 0x4D, + 0xCC, 0x94, 0x54, 0x85, 0xCD, 0x8D, 0x46, 0x79, + 0xD7, 0x2C, 0xD9, 0x67, 0x27, 0xED, 0x1C, 0x22, + 0x6C, 0x90, 0xC2, 0xB1, 0x23, 0xD2, 0x38, 0x59, + 0x79, 0x12, 0x54, 0xAD, 0xEE, 0xFA, 0xE3, 0x31, + 0x87, 0x51, 0x88, 0x15, 0xB9, 0x24, 0x73, 0x5A, + 0x32, 0xA4, 0xD3, 0xCE, 0xEB, 0xC5, 0xAE, 0x9C, + 0x8E, 0xD6, 0x64, 0x00, 0x9E, 0x04, 0x5D, 0x28, + 0xED, 0x99, 0x90, 0xF9, 0xA0, 0xBA, 0x55, 0x81 +}; +#endif /* RSA_KEYSIZE == 2048 */ + +#if RSA_KEYSIZE == 1024 + +#define N_LEN_B (16*8) +#define E_LEN_B (3) +#define D_LEN_B (16*8) +#define ALL_LEN_B (N_LEN_B+E_LEN_B+D_LEN_B) + +static uint8_t rsa_key_blob[] PROGMEM = { + /* n */ + 0xC8, 0xE2, 0x5C, 0xE3, 0x38, 0xE2, 0x05, 0x03, + 0xBA, 0xFD, 0x33, 0x9A, 0xC4, 0x71, 0x5A, 0xD9, + 0x04, 0x8D, 0xF0, 0xDD, 0x03, 0x14, 0xCF, 0x73, + 0xCD, 0xE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xD9, + 0x12, 0xA5, 0xFF, 0x08, 0x4F, 0x67, 0x64, 0xF7, + 0x04, 0xD5, 0xC0, 0xBC, 0x98, 0x2F, 0xF0, 0x8A, + 0x3A, 0x3D, 0xFF, 0xB2, 0xF7, 0x12, 0xA8, 0x71, + 0x4C, 0xF8, 0x21, 0x3B, 0xD4, 0x9C, 0x78, 0x93, + 0x5A, 0xC1, 0x25, 0xB4, 0x5F, 0x95, 0x59, 0xD4, + 0x8D, 0x7D, 0xF4, 0x07, 0x3C, 0xB5, 0x8A, 0x4C, + 0xFF, 0x94, 0x68, 0xCD, 0x1A, 0x12, 0xC5, 0xC1 +}; + +#endif /* RSA_KEYSIZE */ + +void load_rsa_key_blob(rsa_ctx_t* ctx){ + if(ctx->modulus.wordv){ + free(ctx->modulus.wordv); + } + ctx->modulus.wordv = malloc(ALL_LEN_B); + if(ctx->modulus.wordv==NULL){ + cli_putstr_P(PSTR("\r\nERROR: OUT OF MEMORY!!!")); + return; + } + ctx->modulus.info = ctx->privexp.info = ctx->pubexp.info = 0; + memcpy_P(ctx->modulus.wordv, rsa_key_blob, ALL_LEN_B); + ctx->modulus.length_B=N_LEN_B; + ctx->pubexp.wordv = ctx->modulus.wordv+N_LEN_B; + ctx->pubexp.length_B = E_LEN_B; + ctx->privexp.wordv = ctx->pubexp.wordv+E_LEN_B; + ctx->privexp.length_B = D_LEN_B; + + bigint_changeendianess(&(ctx->modulus)); + bigint_changeendianess(&(ctx->pubexp)); + bigint_changeendianess(&(ctx->privexp)); + + bigint_adjust(&(ctx->modulus)); + bigint_adjust(&(ctx->pubexp)); + bigint_adjust(&(ctx->privexp)); +} diff --git a/rsa/rsa_key_blob.h b/rsa/rsa_key_blob.h new file mode 100644 index 0000000..796cb56 --- /dev/null +++ b/rsa/rsa_key_blob.h @@ -0,0 +1,25 @@ +/* rsa_key_blob.h */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef RSA_KEY_BLOB_H_ +#define RSA_KEY_BLOB_H_ + +void load_rsa_key_blob(rsa_ctx_t* ctx); + +#endif /* RSA_KEY_BLOB_H_ */ diff --git a/rsa/rsa_privatekey_1024.ascii b/rsa/rsa_privatekey_1024.ascii new file mode 100644 index 0000000..efe2a67 --- /dev/null +++ b/rsa/rsa_privatekey_1024.ascii @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQDI4lzjOOIFA7r9M5rEcVrZBI3w3QMUz3PN4Lr7If9i9kUXObzc +nQafyO2g/sTSluhRQDEaBQv2e46almc73qN9PA5GAB+UJaXEcSZc6cRD8/WDVZcc +ECAOTS3x8HJdhAEoTRaqld9Suy40wXefGDCXCoZwxu7ihNaFERSscHopuQIDAQAB +AoGALtL0q9IafOi9sT9SF/AEKQmyvC4IBdXFPHvhmZ/3E24r9Jn0t8eyP5RqL1iz +MBMU27uGtnXur+lk+AuOzJm8qY5Xuge9Ct3ZEqX/CE9nZPcE1cC8mC/wijo9/7L3 +EqhxTPghO9SceJNawSW0X5VZ1I199Ac8tYpM/5RozRoSxcECQQDzNwQguScWMDkN +lR6t14PMj9Rk7zmu+xcRKf3X4fFftvrp6ZiMvnL+SZt5jOF1Le8RVZXrkL1HCm+V +UcN6NaKNAkEA03GyGGTXMU/dDRD4Rw6pypfPsWdzKY/Hy5jNRH3Tt1yFT6Ho+vq2 +UHHDK0SthRcAmkv6V7O74bfO8NyxRrWu3QJAcFPseCCLSNgkwX0pmih7GrMi6SsD +fSlCUg8OyfH0RLyBzh6w8e/TtFXSlKTYTAJW866PeyhyAqlzN4d3vK2g0QJAUxnD +Mf0n6hSGPyVlPqAPsTTbBtEunK4KiwUB36JIPC9boYFzzHgOgS1E1FOIkt8IeJvV +xvQ3qi2QYm+KKM0s7QJBAK1me2m5bDd24C3zvr0fmLiDNOVXHKrnAfTx7GYjLrye +d4yrNvIFpKjbX3OzxDCdDLEwlQXLyivWu9hJ9C2kgAo= +-----END RSA PRIVATE KEY----- diff --git a/rsa/rsa_privatekey_2048.ascii b/rsa/rsa_privatekey_2048.ascii new file mode 100644 index 0000000..1a327f0 --- /dev/null +++ b/rsa/rsa_privatekey_2048.ascii @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEA2rxKQgJvf8LrWnMqhCW1VseZJQpQbwCuhFwZMMber8YwyNBn +lhTxX/8MScFKppFSg65GpivMOJC947AQMJ8Cac80Ppw4giohuZgBn2CXe93ftFt4 +m1F8755Iu+8n1aE4EDBgfRpQVmTXRUcbcXW7oew6w6trFYQJ/Yc45yhBR4Sxh96o +Gf/Wv6T1i//3tV+IrhXYJjHelNvccuua/dLjuwWYdq0NCiHftKqbSehr7HyLhyHv +btlkqxdS3ckTSwzfP4c1HyqbiN2SBoNRS16O29J/wRs5nvtHcXXyW8z5qk1cnzT/ +Um9qq4SCqmJYWX14oDcmTIqP8JLp9wWtd2EyTQIDAQABAoIBABKY16dtFZXDOMdj +60V4/0X1imu/yL7nS+8s9WdUQTKooxUvwt7bwPnscVsD+BjZWi6f7pnKN37Hr51g +JsA7hLUCTOrV1WgbtOpWpiyqxbZeUtq+vC5Ya0rkJkL0PmrHXkDiHBIG3rW5tSPK +u+aVn/JQZ16jgGM/6qmHiar9nS87TKTEsMUl7NFcwyxAHihCHscmq55auSK5RBTI +HVFkT+OgBEgEVUvOixEAy4WTiwbOMw2muLpfwDxasAsMaOJPTcyUVIXNjUZ51yzZ +ZyftHCJskMKxI9I4WXkSVK3u+uMxh1GIFbkkc1oypNPO68WunI7WZACeBF0o7ZmQ ++aC6VYECgYEA989FJry3kLfR9CdF5QBnT47Mqm3NyX2asL8Kz4wq8+y842zBcghj +Q/n9lX29f9MM6N1pSRCRR2CqL72dTTHC1XDd5exewE9R5PcOj2y20FDjtFOZqET1 +xbEojJD2VRjdAWK7X5u/txZosjGf94Y5CrGbNJ+HW9HCO7/2ztotHzkCgYEA4fcF +rcDy6UGkHjMj0UPvQyvmXRZgbifeK5vLYVYDxBHq/FehHapGSWsbcqryea7KJs4H +A08Bm7lK78W7fWHfQmpn1Z/dLHPX3gFHXUh/fpws8so5x5hQUVpQzxV3l8mnvciK +Mq2U2PN6UevQjFo7sGR1OHmlbshhjZJ10jkMF7UCgYBoyARmV7+Kep9VDFIafWwx +kKDro1gzTV/eQjlQ/uSelUhdJXw6Ol+2u3rE/hDlfpjj0dMV6OJ0+uObIiLkJBlM +5Nd+w85gpGltViWa8Y3vUXSmp/69zsLZH4qUvSrbWpMAZf3ydEnBIcGNLzyDjgaK +hgSpYJb8dRoa55V1a31OyQKBgQDP1DhH4EBK45HEKPsXfOkyGc1t7qfQiSChcVB0 +/PzHuEctwpcwRq0Q189N/wa3flj1qebvVxo+lQTkVTQllQAYAO/xnnB5cy6nRPvT +Q1voIlKBGBheiKvOt0e9v5vYYqPCPRFGnTpa9E2bzU1p2ZAuo6bgw5mxs+Ftqbhu +GwQRRQKBgQDqI161gPYJ+6tb9fKnVs7ss5zPRkA68NXE1vzFfZCvOWx/W7ykdbVZ +s3MLWsli4HoCDUTsOLhOfn2H+opzJS84pC/pUPcXn/04hkyQvVUBImbab92opiPy +CsxxSB/U05KWW0sUBYb9dLU5ei/JJi0ctIkKyXAO2sDNi8UNUfENJw== +-----END RSA PRIVATE KEY----- diff --git a/rsa/rsa_privatekey_2048.der b/rsa/rsa_privatekey_2048.der new file mode 100644 index 0000000000000000000000000000000000000000..d9835762b964884ac8785aa18b1ce43fe6cb6219 GIT binary patch literal 1192 zcmV;Z1Xueof&`=j0RRGm0RaHoyh=g>Z-2t;T5~FdCAC(^nI#HP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1potr0S^E$f&mHwf&l>l+Pq3a0&jo9>soUv zgeA3B$C)JxP;UUPgj^Xg#@?^SFv!qnmK5<{{|rgNN~V!ggRVxVE6g~Mz2mSDFrNZx z&on-qID#r6xtIZ;V3&K{-?UqJn^Ao4o=CgzC)J@i5HMhU8c^j4% zYZZhE{f9W`C_zVrv4`HM8UNP5r1gvc_qAV$t`*oOG2WEh+;Z!h{nF#R1(GuV#cVRM30s{d60Ry>)I{*Lx literal 0 HcmV?d00001 diff --git a/test_src/main-rsa-test.c b/test_src/main-rsa-test.c new file mode 100644 index 0000000..fa71fe7 --- /dev/null +++ b/test_src/main-rsa-test.c @@ -0,0 +1,182 @@ +/* main-rsa-test.c */ +/* + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/* + * RSA test-suit + * +*/ + +#include "config.h" + +#include "uart_i.h" +#include "debug.h" + +#include "noekeon/noekeon.h" +#include "noekeon/noekeon_prng.h" +#include "bigint/bigint.h" +#include "bigint/bigint_io.h" +#include "rsa.h" +#include "rsa_key_blob.h" + +#include "cli.h" +#include "performance_test.h" +#include +#include +#include + +char* algo_name = "RSA"; + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ + +rsa_ctx_t rsa_ctx; + +void load_fix_rsa(void){ + load_rsa_key_blob(&rsa_ctx); +} + +void rsa_print_item(bigint_t* a, PGM_P pstr){ + uint8_t *p; + cli_putstr_P(PSTR("\r\n")); + cli_putstr_P(pstr); + cli_putstr_P(PSTR(": ")); + uint16_t i; + p = a->wordv + a->length_B -1; + for(i=0; ilength_B-1; ++i){ + if(i%16==0){ + cli_putstr_P(PSTR("\r\n ")); + } + cli_hexdump(p, 1); + cli_putc(':'); + --p; + } + if(i%16==0){ + cli_putstr_P(PSTR("\r\n ")); + } + cli_hexdump(p, 1); +} + +void print_rsa_ctx(rsa_ctx_t* ctx){ + cli_putstr_P(PSTR("\r\n === RSA context ===")); + rsa_print_item(&(ctx->modulus), PSTR("modulus")); + rsa_print_item(&(ctx->pubexp), PSTR("public exponent")); + rsa_print_item(&(ctx->privexp), PSTR("private exponent")); +} + +uint8_t testmsg[128] PROGMEM = { + 0x25, 0x11, 0x1e, 0x08, 0x1c, 0x72, 0x57, 0xbf, + 0x46, 0xbb, 0x56, 0xe8, 0x0b, 0x24, 0x0d, 0x72, + 0x77, 0x11, 0x12, 0x10, 0xec, 0xb9, 0xe4, 0x6f, + 0xe0, 0x6c, 0x83, 0x65, 0xe2, 0xe5, 0x1a, 0x3c, + 0xdb, 0x6c, 0x51, 0x8d, 0xbc, 0xd0, 0x30, 0xb6, + 0xca, 0x01, 0xb4, 0x03, 0x03, 0xe9, 0x86, 0x86, + 0xfe, 0x76, 0x4e, 0xb7, 0x47, 0xb5, 0x06, 0x15, + 0x92, 0x38, 0xc2, 0x0d, 0x3c, 0xfa, 0x53, 0xe3, + 0xe3, 0x57, 0xeb, 0x34, 0xb8, 0xda, 0x7b, 0x0e, + 0x06, 0x28, 0x1d, 0x4a, 0x14, 0xcc, 0x56, 0x8d, + 0xf3, 0x0f, 0x40, 0x2e, 0x23, 0x45, 0xe7, 0xcd, + 0xc5, 0x83, 0x8f, 0xaa, 0x55, 0x55, 0x7d, 0xbd, + 0x19, 0x63, 0xbd, 0x17, 0xda, 0xfd, 0x18, 0xd1, + 0x62, 0x43, 0xc7, 0x33, 0x39, 0x2c, 0xda, 0x64, + 0x27, 0x96, 0xa0, 0x83, 0xa0, 0xf9, 0x3b, 0x1e, + 0x17, 0x71, 0x59, 0xaa, 0x43, 0x3b, 0xeb, 0x80 +}; + +void quick_test(void){ + load_fix_rsa(); + + bigint_t m,c,m_; + uint8_t mw[rsa_ctx.modulus.length_B], cw[rsa_ctx.modulus.length_B], m_w[rsa_ctx.modulus.length_B]; + uint8_t i; + + print_rsa_ctx(&rsa_ctx); + m.wordv = mw; + c.wordv = cw; + m_.wordv = m_w; + m.length_B = rsa_ctx.modulus.length_B; + m.info = 0; + cli_putstr_P(PSTR("\r\ngenerating random message ...")); +/* do{ + for(i=0; i