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

header of sign.c More...

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

Go to the source code of this file.

Data Structures

struct  _Signature
 
struct  _Protected
 

Typedefs

typedef struct _Signature Signature
 
typedef struct _Protected Protected
 

Functions

Signatureinit_signature_raw (int64 *content, int size)
 initialize a signaure without copying the data !!! takes ownership of content More...
 
Signatureinit_signature (const int64 *content, int size)
 initialize a signaure More...
 
Signaturecopy_signature (const Signature *o)
 Copy a Signature object. More...
 
void free_signature (Signature *sig)
 free a Signature object. More...
 
Signaturesign (char *mess, Key *sKey)
 sign a message More...
 
char * signature_to_str (const Signature *sgn)
 convert a signature to string More...
 
Signaturestr_to_signature (const char *str)
 parse a string to a signature More...
 
Signaturestr_to_signature_len (const char *str, size_t len)
 Converts a string to a signature, knowing it's length. More...
 
Protectedinit_protected (Key *pKey, char *mess, Signature *sgn)
 create a signed declaration More...
 
Protectedinit_protected_raw (Key *pKey, char *mess, Signature *sgn)
 create a signed declaration !!! Takes ownership of key, message and signature. More...
 
void free_protected (Protected *pr)
 free a signed declaration and it's content More...
 
Protectedcopy_protected (const Protected *o)
 copy protected More...
 
bool verify (const Protected *pr)
 checks if the signature matches the message More...
 
char * protected_to_str (const Protected *prc)
 convert a signed Protected (declaration) to string. More...
 
Protectedstr_to_protected (const char *str)
 parse a string to a signed declaration More...
 
Protectedstr_to_protected_len (const char *str, size_t slen)
 parse a string to a signed declaration More...
 

Detailed Description

header of sign.c

Typedef Documentation

◆ Protected

typedef struct _Protected Protected

Structure for storing a Protected (declaration).

◆ Signature

typedef struct _Signature Signature

A struct for storing a signature

Function Documentation

◆ copy_protected()

Protected * copy_protected ( const Protected o)

copy protected

Parameters
oProtected to copy
Returns
Protected*

◆ copy_signature()

Signature * copy_signature ( const Signature o)

Copy a Signature object.

Parameters
o
Returns
Signature*

◆ free_protected()

void free_protected ( Protected pr)

free a signed declaration and it's content

Parameters
pr: element to free

◆ free_signature()

void free_signature ( Signature sig)

free a Signature object.

Parameters
sig: signature to delete

◆ init_protected()

Protected * init_protected ( Key pKey,
char *  mess,
Signature sgn 
)

create a signed declaration

Parameters
pKey: public key
mess: associated message
sgn: signed message
Returns
Protected*

◆ init_protected_raw()

Protected * init_protected_raw ( Key pKey,
char *  mess,
Signature sgn 
)

create a signed declaration !!! Takes ownership of key, message and signature.

Parameters
pKey: public key
mess: associated message
sgn: signed message
Returns
Protected*

◆ init_signature()

Signature * init_signature ( const int64 content,
int  size 
)

initialize a signaure

Parameters
content: content of the signature
size: size of content
Returns
Signature* : a new signature on the heap

◆ init_signature_raw()

Signature * init_signature_raw ( int64 content,
int  size 
)

initialize a signaure without copying the data !!! takes ownership of content

Parameters
content: content of the signature
size: size of content
Returns
Signature* : a new signature on the heap

◆ protected_to_str()

char * protected_to_str ( const Protected prc)

convert a signed Protected (declaration) to string.

Parameters
prc: declaration to convert
Returns
char*

◆ sign()

Signature * sign ( char *  mess,
Key sKey 
)

sign a message

Parameters
mess: message to sign
sKey: private key to sign the message with
Returns
Signature*

◆ signature_to_str()

char * signature_to_str ( const Signature sgn)

convert a signature to string

Parameters
sgn: signature to convert
Returns
char*

◆ str_to_protected()

Protected * str_to_protected ( const char *  str)

parse a string to a signed declaration

Parameters
str: string to parse
Returns
Protected*

◆ str_to_protected_len()

Protected * str_to_protected_len ( const char *  str,
size_t  slen 
)

parse a string to a signed declaration

Parameters
str: string to parse
slen: length of the string
Returns
Protected*

◆ str_to_signature()

Signature * str_to_signature ( const char *  str)

parse a string to a signature

Parameters
str
Returns
Signature*

◆ str_to_signature_len()

Signature * str_to_signature_len ( const char *  str,
const size_t  len 
)

Converts a string to a signature, knowing it's length.

Parameters
str
len
Returns
Signature*

◆ verify()

bool verify ( const Protected pr)

checks if the signature matches the message

Parameters
Protected*: protected message
Returns
bool