/******************************************************************************/
-uint32_t bigint_get_first_set_bit(const bigint_t *a){
+int32_t bigint_get_first_set_bit(const bigint_t *a){
if(a->length_W == 0) {
- return (uint32_t)(-1);
+ return -1;
}
return (a->length_W-1) * sizeof(bigint_word_t) * CHAR_BIT + GET_FBS(a);
}
/******************************************************************************/
-uint32_t bigint_get_last_set_bit(const bigint_t *a){
- uint32_t r=0;
- uint8_t b=0;
- bigint_word_t x=1;
- if(a->length_W==0){
- return (uint32_t)(-1);
+int32_t bigint_get_last_set_bit(const bigint_t *a){
+ uint32_t r = 0;
+ uint8_t b = 0;
+ bigint_word_t x = 1;
+ if (a->length_W == 0) {
+ return -1;
}
- while(a->wordv[r]==0 && r<a->length_W){
+ while (a->wordv[r] == 0 && r < a->length_W) {
++r;
}
- if(a->wordv[r] == 0){
+ if (a->wordv[r] == 0) {
return (uint32_t)(-1);
}
- while((x&a->wordv[r])==0){
+ while ((x&a->wordv[r])==0) {
++b;
x <<= 1;
}
- return r*BIGINT_WORD_SIZE+b;
+ return r * BIGINT_WORD_SIZE + b;
}
/******************************************************************************/
bigint_word_t *p;
bigint_wordplus_t t = 0;
- if (shift == 0) {
+ if (a->length_W == 0 || shift == 0) {
return;
}
byteshift = shift / 8;
byteshift = shift / 8;
bitshift = shift & 7;
+ if (a->length_W == 0) {
+ return;
+ }
+
if(bigint_get_first_set_bit(a) < shift){ /* we would shift out more than we have */
bigint_set_zero(a);
return;
if(byteshift){
memmove(a->wordv, (uint8_t*)a->wordv + byteshift, a->length_W * sizeof(bigint_word_t) - byteshift);
memset((uint8_t*)&a->wordv[a->length_W] - byteshift, 0, byteshift);
+ a->length_W -= byteshift / sizeof(bigint_word_t);
}
- a->length_W -= byteshift / sizeof(bigint_word_t);
if(bitshift != 0 && a->length_W){
/* shift to the right */
/******************************************************************************/
void bigint_adjust(bigint_t *a);
-uint32_t bigint_get_first_set_bit(const bigint_t *a);
-uint32_t bigint_get_last_set_bit(const bigint_t *a);
+int32_t bigint_get_first_set_bit(const bigint_t *a);
+int32_t bigint_get_last_set_bit(const bigint_t *a);
bigint_length_t bigint_length_b(const bigint_t *a);
bigint_length_t bigint_length_B(const bigint_t *a);
void bigint_copy(bigint_t *dest, const bigint_t *src);
ALGO_NAME := RSAES_PKCS1V15
# comment out the following line for removement of RSA from the build process
-SIGNATURE += $(ALGO_NAME)
+PK_CIPHERS += $(ALGO_NAME)
$(ALGO_NAME)_DIR := rsa/
$(ALGO_NAME)_INCDIR := memxor/ bigint/ noekeon/
#if DEBUG
#include "cli.h"
+#include <stdio.h>
#endif
void rsa_enc(bigint_t *data, const rsa_publickey_t *key){
while(BIGINT_NEG_MASK & m1.info){
#if DEBUG
cli_putstr_P(PSTR("\r\nDBG: adding "));
- bigint_print_hex(key->components[0]);
+ bigint_print_hex(&key->components[0]);
cli_putstr_P(PSTR("\r\nDBG: to "));
bigint_print_hex(&m1);
#endif