58 lines
1.5 KiB
C
58 lines
1.5 KiB
C
#ifndef _RSA_H
|
|
#define _RSA_H 1
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stddef.h>
|
|
#include <stdlib.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
|
|
#define RSA_BLOCK_SIZE 128
|
|
|
|
typedef struct bigint_s {
|
|
uint32_t *data;
|
|
size_t len;
|
|
} bigint_t;
|
|
|
|
typedef struct rsa_s {
|
|
bigint_t p;
|
|
bigint_t q;
|
|
} rsa_t;
|
|
|
|
|
|
void *protected_malloc(size_t size);
|
|
|
|
rsa_t rsa_generate_keys(size_t block_size);
|
|
|
|
|
|
void bigint_set_random_bytes(bigint_t n, size_t len);
|
|
void bigint_set_msb_and_lsb_to_one(bigint_t n, size_t len);
|
|
void bigint_bitwise_left_shift(bigint_t n);
|
|
void bigint_bitwise_right_shift(bigint_t n);
|
|
void bigint_decrement(bigint_t n);
|
|
int64_t bigint_cmp(bigint_t a, bigint_t b);
|
|
bigint_t bigint_prime(size_t len, bigint_t *primes);
|
|
void bigint_print(bigint_t n);
|
|
bigint_t bigint_new(size_t len);
|
|
bigint_t bigint_zero(size_t len);
|
|
bigint_t bigint_clone(bigint_t src);
|
|
void bigint_add(bigint_t a, bigint_t b);
|
|
void custom_bigint_add(bigint_t a, bigint_t b, int index);
|
|
bigint_t assignable_bigint_mul(bigint_t a, bigint_t b);
|
|
bigint_t assignable_bigint_modulo(bigint_t a, bigint_t b);
|
|
bigint_t assignable_bigint_pow_mod(bigint_t a, bigint_t e, bigint_t n);
|
|
void bigint_set_zeros(bigint_t n);
|
|
|
|
void bigint_destroy(bigint_t n);
|
|
|
|
void array_set_random_bytes(uint32_t *n, size_t size);
|
|
void array_set_msb_and_lsb_to_one(uint32_t *n, size_t size);
|
|
void array_bitwise_right_shift(uint32_t *a, size_t len);
|
|
void array_bitwise_right_shift(uint32_t *a, size_t len);
|
|
void array_decrement(uint32_t *a, size_t len);
|
|
|
|
#endif
|
|
|