]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - rsa/rsaes_pkcs1v15.c
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / rsa / rsaes_pkcs1v15.c
index 459c62b427aaf147e3d7240089aa23e09f6da028..c1f753fa9220feb3a60f610c544911b2646d2049 100644 (file)
@@ -1,7 +1,7 @@
 /* rsa_pkcs1v15.c */
 /*
     This file is part of the ARM-Crypto-Lib.
-    Copyright (C) 2006-2011 Daniel Otte (daniel.otte@rub.de)
+    Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
 
     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
 
 #include "random_dummy.h"
 
-uint16_t rsa_pkcs1v15_compute_padlength_B(bigint_tmodulus, uint16_t msg_length_B){
+uint16_t rsa_pkcs1v15_compute_padlength_B(bigint_t *modulus, uint16_t msg_length_B){
        return bigint_get_first_set_bit(modulus) / 8 + 1 - msg_length_B - 3;
 }
 
-uint8_t rsa_encrypt_pkcs1v15(void* dest, uint16_t* out_length, const void* src,
-       uint16_t length_B, rsa_publickey_t* key, const void* pad){
+uint8_t rsa_encrypt_pkcs1v15(void *dest, uint16_t *out_length, const void *src,
+       uint16_t length_B, rsa_publickey_t *key, const void *pad){
        int16_t pad_length;
        bigint_t x;
-       pad_length = rsa_pkcs1v15_compute_padlength_B(key->modulus, length_B);
+       pad_length = rsa_pkcs1v15_compute_padlength_B(&key->modulus, length_B);
        if(pad_length<8){
 #if DEBUG
                cli_putstr_P(PSTR("\r\nERROR: pad_length<8; pad_length: "));
@@ -73,20 +73,20 @@ uint8_t rsa_encrypt_pkcs1v15(void* dest, uint16_t* out_length, const void* src,
        ((uint8_t*)dest)[2+pad_length] = 0x00;
        memcpy((uint8_t*)dest+3+pad_length, src, length_B);
        x.wordv = dest;
-       x.length_B = (length_B+pad_length+3+sizeof(bigint_word_t)-1)/sizeof(bigint_word_t);
+       x.length_W = (length_B+pad_length+3+sizeof(bigint_word_t)-1)/sizeof(bigint_word_t);
 #if DEBUG
        cli_putstr_P(PSTR("\r\nx-data: "));
-       cli_hexdump_block(x.wordv, x.length_B * sizeof(bigint_word_t), 4, 16);
+       cli_hexdump_block(x.wordv, x.length_W * sizeof(bigint_word_t), 4, 16);
 #endif
        bigint_adjust(&x);
-       rsa_os2ip(&x, NULL, length_B+pad_length+3);
+       rsa_os2ip(&x, NULL, length_B + pad_length + 3);
        rsa_enc(&x, key);
        rsa_i2osp(NULL, &x, out_length);
        return 0;
 }
 
-uint8_t rsa_decrypt_pkcs1v15(void* dest, uint16_t* out_length, const void* src,
-       uint16_t length_B, rsa_privatekey_t* key, void* pad){
+uint8_t rsa_decrypt_pkcs1v15(void *dest, uint16_t *out_length, const void *src,
+       uint16_t length_B, rsa_privatekey_t *key, void *pad){
        bigint_t x;
        uint16_t m_length, pad_length=0, idx=0;
        x.wordv = dest;