diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-11-25 10:16:00 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-11-25 10:16:00 +0100 |
commit | f6b8e0eae4374f339487a33e3e4fe5462d5816e1 (patch) | |
tree | 5f5f764fd6cda404b2ad6e85762c03fce3a335db /ccast/axTLS/rsa.c | |
parent | 615ab5513e79c4abc5bbe5c993587785b6a1738b (diff) |
New upstream version 2.0.0upstream/2.0.0
Diffstat (limited to 'ccast/axTLS/rsa.c')
-rwxr-xr-x[-rw-r--r--] | ccast/axTLS/rsa.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/ccast/axTLS/rsa.c b/ccast/axTLS/rsa.c index e707f2b..14948eb 100644..100755 --- a/ccast/axTLS/rsa.c +++ b/ccast/axTLS/rsa.c @@ -188,6 +188,50 @@ int RSA_decrypt(const RSA_CTX *ctx, const uint8_t *in_data, } /** + * @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 */ bigint *RSA_private(const RSA_CTX *c, bigint *bi_msg) |