Toychain!
A toy blockchain in C
rsa.h File Reference

header of rsa.c More...

#include "lib/mmath.h"
#include "lib/types.h"
#include <stdbool.h>
Include dependency graph for rsa.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _Key
 

Typedefs

typedef struct _Key Key
 

Functions

void init_key (Key *key, int64 val, int64 n)
 initializes a key struct More...
 
Keycopy_key (const Key *o)
 copies key More...
 
char * key_to_str (const Key *key)
 converts a Key to string of the form " (v, n) " More...
 
Keystr_to_key (const char *str)
 parses a string of the form " (v, n) " into a Key struct More...
 
void init_pair_keys (Key *pKey, Key *sKey, int low_size, int up_size)
 initializes a key struct More...
 
bool generate_key_values (int64 p, int64 q, int64 *n, int64 *s, int64 *u)
 generates public and private RSA keys public = (s, n) ; private = (u, n) More...
 
int64encrypt (const char *chaine, int64 s, int64 n)
 encrypt a message using modular exponentiation and a public RSA key (s,n). More...
 
char * decrypt (const int64 *crypted, int size, int64 u, int64 n)
 decrypt a message using modular exponentiation and a RSA key (u,n). More...
 

Detailed Description

header of rsa.c

Typedef Documentation

◆ Key

typedef struct _Key Key

A struct for storing a key

Function Documentation

◆ copy_key()

Key * copy_key ( const Key o)

copies key

Parameters
o
Returns
Key*

◆ decrypt()

char * decrypt ( const int64 crypted,
int  size,
int64  u,
int64  n 
)

decrypt a message using modular exponentiation and a RSA key (u,n).

Parameters
cryptedmessage to be decrypted
size
u
n
Returns
char* : original message

◆ encrypt()

int64 * encrypt ( const char *  chaine,
int64  s,
int64  n 
)

encrypt a message using modular exponentiation and a public RSA key (s,n).

Parameters
chainemessage to be crypted
s
n
Returns
int64* : encrypted message

◆ generate_key_values()

bool generate_key_values ( int64  p,
int64  q,
int64 n,
int64 s,
int64 u 
)

generates public and private RSA keys public = (s, n) ; private = (u, n)

Parameters
pprime
qprime
nreturn value
sreturn value
ureturn value
Returns
true : the generation was successfull!
false : is most probably impossible to generate a valid key pair!

◆ init_key()

void init_key ( Key key,
int64  val,
int64  n 
)

initializes a key struct

Parameters
pprime
qprime
Returns
void

◆ init_pair_keys()

void init_pair_keys ( Key pKey,
Key sKey,
int  low_size,
int  up_size 
)

initializes a key struct

Parameters
pprime
qprime
Returns
void

◆ key_to_str()

char * key_to_str ( const Key key)

converts a Key to string of the form " (v, n) "

Parameters
Keykey to convert
Returns
char* : allocated on the heap

◆ str_to_key()

Key * str_to_key ( const char *  str)

parses a string of the form " (v, n) " into a Key struct

Parameters
charstring to convert
Returns
Key* : allocated on the heap