This module brings ciphering ability to the LibLapin.
Please, read those lines carefuly: this module is NOT
designed as a really secure module. Its only purpose is to cipher
and uncipher ressources used by your program to prevent things
like cheating. Eventually, it could be used as additional security
in a really secure channel, but remember: if you need real
security, use a real ciphering library.
A note about ciphering and unciphering functions: you should
consider ciphering as an operation in a specific direction and
unciphering as the opposed direction, but specificaly as ciphering
and unciphering operations.
With algorithm offered
by the bunny library, you can without any problem
cipher with and unciphering function and uncipher with a ciphering
function.
All you have to do is keep the consistancy of your actions. If you have
ciphered with an unciphering function with an algorithm, then
you have to uncipher with a ciphering function with the same algorithm
to get your data back.
The security module header is lapin/security.h.
Description
  This enumeration describes ciphering algorithm available in the LibLapin.
Symbols
-
BS_XOR:
  Each byte of the data get treated by a XOR operation with
a single byte of the key. This cipher algorithm is not cumulative:
using two times this algorithm on the same data with the same key will
uncipher the data that was ciphered.
-
BS_CAESAR:
  Each byte of the data get treated by a ADD operation with
a single byte of the key when ciphering, SUB when unciphering.
-
BS_SHAKER:
  Each byte of the data get swapped with the value which is
at a specific distance indicated by a byte in the key. Because
swapping is made from the beginning and because it impacts even
the end of the data, this algorithm is cumulative, even if it
does not seems to be.
-
BS_SWITCH:
  This algorithm transform the data from a state by state
encoding to a status change encoding at the binary level.
For example:
1100 0011
Will become:
1010 0010
This ciphering does not use the key at all.
The unciphering level does the inverse operation. This cipher
is cumulative.
-
BS_CUSTOM:
  When calling the bunny_cipher_file, bunny_uncipher_file,
bunny_cipher_data or bunny_uncipher_data with this as t_bunny_ciphering,
the function set in gl_bunny_ressource_ciphering will be called.
The purpose of this value is to allow you to extend the bunny library
from outside.
Any value superior or equal to BS_CUSTOM is valid and considered
by all thoses functions as similar in purpose to BS_CUSTOM and
transmit to your function so you can implement several algorithm.
INDEX
This data table is as long as the amount of ciphering in LibLapin and
contains algorithm name under string format.
INDEX
Description
  Read the sent algorithm name and return the detected enumeration.
BS_CUSTOM is returned if no LibLapin algorithm is found.
Parameters
-
const char *name:
  An algorithm name to read.
INDEX
k
Description
  A key used as ciphering ressource. If you need to reserve space for a specific
size, you can do it this way:
t_bunny_cipher_key *k =
bunny_malloc(sizeof(*k) + length * sizeof(k->key[0]));
You can also use bunny_alloca instead of
bunny_malloc if a local key is
enough for your function. Do not forget to set the
length field and to fill
the
key one.
Attributes
-
int32_t length:
  The length in byte of the key attribute.
-
char key[]:
  An array of length byte containing the data used as key
for ciphering.
INDEX
Description
  Get the embedded key of the program, edit it if it was never done before
and return it.
INDEX
Description
  Write the sent key into the sent program file, in the place
of the embedded key.
Parameters
-
const char *bunny_program:
  A software that needs an embedded key. The sent key will
be written inside.
-
t_bunny_cipher_key *key:
  The key that will be written inside the sent program.
Return value
Return true if everything went well.
Error values and logs
On error, $Vbunny_errno is set to:
Logs written by this function are tagged with the "security" label.
INDEX
Return value
Return outkey
INDEX
Description
  This function pointer is used by
bunny_default_key to edit
the embedded key so the used ciphering key cannot be extracted.
By default, it is
NULL and a default function is called.
INDEX
Description
  Reserve and generate a new key.
Parameters
-
size_t len:
  The length in byte of the key. It must be pair.
Error values and logs
On error, $Vbunny_errno is set to:
-
EINVAL:
Invalid length.
-
ENOMEM:
Out of memory.
Logs written by this function are tagged with the "security" label.
INDEX
Description
  Delete the sent key.
INDEX
Description
  Cipher the sent file with the sent algorithm and
the sent key.
Return value
Return true if everything went well.
Error values and logs
On error, $Vbunny_errno is set to:
-
ENOMEM:
Out of memory.
-
Any errno value that can be set by open, read or write.
Logs written by this function are tagged with the "security" label.
INDEX
Description
  Uncipher the sent file with the sent algorithm and
the sent key.
Return value
Return true if everything went well.
Error values and logs
On error, $Vbunny_errno is set to:
-
ENOMEM:
Out of memory.
-
Any errno value that can be set by open, read or write.
Logs written by this function are tagged with the "security" label.
INDEX
Description
  Cipher the sent data of the length datalen with the sent algorithm and
the sent key.
INDEX
Description
  Cipher the sent data of the length datalen with the sent algorithm and
the sent key.
INDEX
Parameters
-
char *buffer:
  The data to cipher or uncipher.
-
size_t len:
  The length of buffer in bytes.
-
void *data:
  The data stored inside gl_bunny_ressource_data.
-
bool cipher:
  true if ciphering, false if unciphering.
INDEX
  The function pointer used by loading and saving functions
to cipher or uncipher ressources.
INDEX