clean: remove comments
This commit is contained in:
parent
3883287e8d
commit
a000c56ce5
48
rsa/bigint.c
48
rsa/bigint.c
|
@ -71,7 +71,6 @@ int bigint_cmp(bigint_t a, bigint_t b) {
|
||||||
while (cursor >= 0) {
|
while (cursor >= 0) {
|
||||||
uint32_t abit = a.data[cursor / size] & (1 << (cursor % size));
|
uint32_t abit = a.data[cursor / size] & (1 << (cursor % size));
|
||||||
uint32_t bbit = b.data[cursor / size] & (1 << (cursor % size));
|
uint32_t bbit = b.data[cursor / size] & (1 << (cursor % size));
|
||||||
//printf("cursor %d abit %ud bbit %ud\n", cursor, abit, bbit);
|
|
||||||
if (abit > bbit) {
|
if (abit > bbit) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -171,63 +170,39 @@ void bigint_add(bigint_t a, bigint_t b) {
|
||||||
size_t width = a.len * size;
|
size_t width = a.len * size;
|
||||||
uint32_t carriage = 0;
|
uint32_t carriage = 0;
|
||||||
|
|
||||||
// printf("hello add\n");
|
|
||||||
for (size_t cursor = 0; cursor < width; cursor++) {
|
for (size_t cursor = 0; cursor < width; cursor++) {
|
||||||
// printf("hahaha %ld %ld\n", cursor, width);
|
|
||||||
uint32_t a_bit = a.data[cursor / size] >> (cursor % size) & 1;
|
uint32_t a_bit = a.data[cursor / size] >> (cursor % size) & 1;
|
||||||
uint32_t b_bit = b.data[cursor / size] >> (cursor % size) & 1;
|
uint32_t b_bit = b.data[cursor / size] >> (cursor % size) & 1;
|
||||||
result.data[cursor / size] |= (a_bit ^ b_bit ^ carriage) << (cursor % size);
|
result.data[cursor / size] |= (a_bit ^ b_bit ^ carriage) << (cursor % size);
|
||||||
carriage = (a_bit & b_bit) | ((a_bit ^ b_bit) & carriage);
|
carriage = (a_bit & b_bit) | ((a_bit ^ b_bit) & carriage);
|
||||||
}
|
}
|
||||||
// printf("im out\n");
|
|
||||||
bigint_destroy(a);
|
bigint_destroy(a);
|
||||||
a = bigint_clone(result);
|
a = bigint_clone(result);
|
||||||
bigint_destroy(result);
|
bigint_destroy(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bigint_set_zeros(bigint_t n) {
|
void bigint_set_zeros(bigint_t n) {
|
||||||
// printf("hello set zeros\n");
|
|
||||||
for (size_t i = 0; i < n.len; i++) {
|
for (size_t i = 0; i < n.len; i++) {
|
||||||
n.data[i] = 0;
|
n.data[i] = 0;
|
||||||
}
|
}
|
||||||
// printf("goodbye set zeros\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bigint_t assignable_bigint_mul(bigint_t a, bigint_t b) {
|
bigint_t assignable_bigint_mul(bigint_t a, bigint_t b) {
|
||||||
bigint_t result = bigint_zero(RSA_BLOCK_SIZE / 8 / sizeof(uint32_t) * 4);
|
bigint_t result = bigint_zero(RSA_BLOCK_SIZE / 8 / sizeof(uint32_t) * 4);
|
||||||
bigint_t b_tool = bigint_zero(RSA_BLOCK_SIZE / 8 / sizeof(uint32_t) * 4);
|
bigint_t b_tool = bigint_zero(RSA_BLOCK_SIZE / 8 / sizeof(uint32_t) * 4);
|
||||||
/*if (a.len > b.len) {
|
|
||||||
result = bigint_zero(a.len);
|
|
||||||
b_tool = bigint_zero(a.len);
|
|
||||||
} else {
|
|
||||||
result = bigint_zero(a.len + b.len);
|
|
||||||
b_tool = bigint_zero(a.len + b.len);
|
|
||||||
}*/
|
|
||||||
size_t size = sizeof(uint32_t) * 8;
|
size_t size = sizeof(uint32_t) * 8;
|
||||||
size_t width = a.len * size;
|
size_t width = a.len * size;
|
||||||
|
|
||||||
printf("multiplying %d and %d\n", a.data[0], b.data[0]);
|
|
||||||
|
|
||||||
// printf("hello mul\n");
|
|
||||||
for (size_t cursor = 0; cursor < width; cursor++) {
|
for (size_t cursor = 0; cursor < width; cursor++) {
|
||||||
// printf("hello BIG LOOP ls %ld %ld\n", cursor, width);
|
|
||||||
if (a.data[cursor / 32] >> (cursor % 32) & 1) {
|
if (a.data[cursor / 32] >> (cursor % 32) & 1) {
|
||||||
bigint_set_zeros(b_tool);
|
bigint_set_zeros(b_tool);
|
||||||
printf("bef %d\n", b_tool.data[0]);
|
|
||||||
// printf("hello memcpy\n");
|
|
||||||
memcpy(b_tool.data, b.data, b.len * sizeof(uint32_t));
|
memcpy(b_tool.data, b.data, b.len * sizeof(uint32_t));
|
||||||
printf("aft %d\n", b_tool.data[0]);
|
|
||||||
// printf("goodbye memcpy\n");
|
|
||||||
for (size_t i = 0; i < cursor; i++) {
|
for (size_t i = 0; i < cursor; i++) {
|
||||||
// printf("hello bitwise ls %ld %ld\n", i, cursor);
|
|
||||||
bigint_bitwise_left_shift(b_tool);
|
bigint_bitwise_left_shift(b_tool);
|
||||||
// printf("goodbye bitwise ls\n");
|
|
||||||
}
|
}
|
||||||
// printf("before hello add\n");
|
|
||||||
bigint_add(result, b_tool);
|
bigint_add(result, b_tool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// printf("GOODBYE BIG LOOP ls \n");
|
|
||||||
bigint_destroy(b_tool);
|
bigint_destroy(b_tool);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -235,12 +210,6 @@ bigint_t assignable_bigint_mul(bigint_t a, bigint_t b) {
|
||||||
// a^e mod n
|
// a^e mod n
|
||||||
// clean memory tricks !!!
|
// clean memory tricks !!!
|
||||||
bigint_t assignable_bigint_pow_mod(bigint_t a, bigint_t e, bigint_t n) {
|
bigint_t assignable_bigint_pow_mod(bigint_t a, bigint_t e, bigint_t n) {
|
||||||
printf("print a\n");
|
|
||||||
bigint_print(a);
|
|
||||||
printf("print e\n");
|
|
||||||
bigint_print(e);
|
|
||||||
printf("print n\n");
|
|
||||||
bigint_print(n);
|
|
||||||
bigint_t result = bigint_clone(a);
|
bigint_t result = bigint_clone(a);
|
||||||
size_t size = sizeof(uint32_t) * 8;
|
size_t size = sizeof(uint32_t) * 8;
|
||||||
int cursor = e.len * size - 1;
|
int cursor = e.len * size - 1;
|
||||||
|
@ -248,20 +217,7 @@ bigint_t assignable_bigint_pow_mod(bigint_t a, bigint_t e, bigint_t n) {
|
||||||
cursor--;
|
cursor--;
|
||||||
}
|
}
|
||||||
cursor--;
|
cursor--;
|
||||||
/*
|
|
||||||
printf("SQUARE\n");
|
|
||||||
bigint_t tmp_result2 = assignable_bigint_mul(result, result);
|
|
||||||
bigint_destroy(result);
|
|
||||||
result = bigint_clone(tmp_result2);
|
|
||||||
bigint_destroy(tmp_result2);
|
|
||||||
tmp_result2 = assignable_bigint_modulo(result, n);
|
|
||||||
bigint_destroy(result);
|
|
||||||
result = bigint_clone(tmp_result2);
|
|
||||||
bigint_destroy(tmp_result2);
|
|
||||||
*/
|
|
||||||
printf("cursor %d\n", cursor);
|
|
||||||
while (cursor >= 0) {
|
while (cursor >= 0) {
|
||||||
printf("SQUARE\n");
|
|
||||||
bigint_t tmp_result2 = assignable_bigint_mul(result, result);
|
bigint_t tmp_result2 = assignable_bigint_mul(result, result);
|
||||||
bigint_destroy(result);
|
bigint_destroy(result);
|
||||||
result = bigint_clone(tmp_result2);
|
result = bigint_clone(tmp_result2);
|
||||||
|
@ -271,7 +227,6 @@ bigint_t assignable_bigint_pow_mod(bigint_t a, bigint_t e, bigint_t n) {
|
||||||
result = bigint_clone(tmp_result2);
|
result = bigint_clone(tmp_result2);
|
||||||
bigint_destroy(tmp_result2);
|
bigint_destroy(tmp_result2);
|
||||||
if (e.data[cursor / 32] & 1 << (cursor % 32)) {
|
if (e.data[cursor / 32] & 1 << (cursor % 32)) {
|
||||||
printf("MULTIPLY\n");
|
|
||||||
bigint_t tmp_result = assignable_bigint_mul(result, a);
|
bigint_t tmp_result = assignable_bigint_mul(result, a);
|
||||||
bigint_destroy(result);
|
bigint_destroy(result);
|
||||||
result = bigint_clone(tmp_result);
|
result = bigint_clone(tmp_result);
|
||||||
|
@ -283,7 +238,6 @@ bigint_t assignable_bigint_pow_mod(bigint_t a, bigint_t e, bigint_t n) {
|
||||||
}
|
}
|
||||||
cursor -= 1;
|
cursor -= 1;
|
||||||
}
|
}
|
||||||
printf("this time its over\n");
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +266,7 @@ bigint_t bigint_prime(size_t len) {
|
||||||
printf("random bytes\n");
|
printf("random bytes\n");
|
||||||
bigint_print(n);
|
bigint_print(n);
|
||||||
bigint_set_msb_and_lsb_to_one(n);
|
bigint_set_msb_and_lsb_to_one(n);
|
||||||
printf("msb and lsb set to tone\n");
|
printf("msb and lsb set to one\n");
|
||||||
bigint_print(n);
|
bigint_print(n);
|
||||||
|
|
||||||
bigint_t d = bigint_clone(n);
|
bigint_t d = bigint_clone(n);
|
||||||
|
|
Loading…
Reference in New Issue