From f6b8e0eae4374f339487a33e3e4fe5462d5816e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 25 Nov 2017 10:16:00 +0100 Subject: New upstream version 2.0.0 --- ccast/axTLS/rsa.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) mode change 100644 => 100755 ccast/axTLS/rsa.c (limited to 'ccast/axTLS/rsa.c') diff --git a/ccast/axTLS/rsa.c b/ccast/axTLS/rsa.c old mode 100644 new mode 100755 index e707f2b..14948eb --- a/ccast/axTLS/rsa.c +++ b/ccast/axTLS/rsa.c @@ -187,6 +187,50 @@ int RSA_decrypt(const RSA_CTX *ctx, const uint8_t *in_data, return size ? size : -1; } +/** + * @brief Use PKCS1.5 for decryption. + * @param ctx [in] The context + * @param in_data [in] The data to encrypt + * @param out_data [out] The decrypted data. + * @return The number of bytes that were originally encrypted. -1 on error. + */ +int RSA_decrypt2(const RSA_CTX *ctx, const uint8_t *in_data, uint8_t *out_data) +{ + const int byte_size = ctx->num_octets; + int i, size; + bigint *decrypted_bi, *dat_bi; + uint8_t *block = (uint8_t *)malloc(byte_size); + + /* decrypt */ + dat_bi = bi_import(ctx->bi_ctx, in_data, byte_size); + + decrypted_bi = RSA_public(ctx, dat_bi); /* Frees dat_bi and exponent ? */ + + /* convert to a normal block (frees decrypted_bi) */ + bi_export(ctx->bi_ctx, decrypted_bi, block, byte_size); + + + /* We assume this is padded with "0001ff....ff00" */ + i = 2; + while (block[i++] == 0xff && i < byte_size) + ; + + /* Skip last 0x00 */ + if (i < byte_size && block[i] == 0x00) + i++; + + size = byte_size - i; + + /* get only the bit we want */ + if (size > 0) { + memcpy(out_data, &block[i], size); + } + + free(block); + + return size ? size : -1; +} + /** * Performs m = c^d mod n */ -- cgit v1.2.3