Bienvenue sur le site de la LibLapin.
Jetez un coup d'oeil en bas de la page pour choisir votre niveau de documentation en fonction de votre niveau avec la LibLapin.
Pour l'instant, c'est réglé sur 'Manuel complet'. Si c'est votre première fois avec la LibLapin, il vaudrait mieux choisir 'Débutant'.
De même, n'oubliez pas de préciser une version de la bibliothèque.

LibLapin's logo

LibLapin

Security





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.
typedef enum e_bunny_ciphering
{
     BS_XOR,      BS_CAESAR,      BS_SHAKER,      BS_SWITCH,      BS_CUSTOM
} t‌_‌b‌u‌n‌n‌y‌_‌c‌i‌p‌h‌e‌r‌i‌n‌g;

Description

     This enumeration describes ciphering algorithm available in the LibLapin.

Symbols




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.

Return value

The t‌_‌b‌u‌n‌n‌y‌_‌c‌i‌p‌h‌e‌r‌i‌n‌g algorithm found or BS_CUSTOM if no algorithm is found.




INDEX

k
typedef struct u_bunny_cipher_key
{
     uint32_t length;
     char key[];

} t‌_‌b‌u‌n‌n‌y‌_‌c‌i‌p‌h‌e‌r‌_‌k‌e‌y;

Description

     A key used as ciphering ressource. If you need to reserve space for a specific size, you can do it this way:

t‌_‌b‌u‌n‌n‌y‌_‌c‌i‌p‌h‌e‌r‌_‌k‌e‌y *k = b‌u‌n‌n‌y‌_‌m‌a‌l‌l‌o‌c(sizeof(*k) + length * sizeof(k->key[0]));

You can also use bunny_alloca instead of b‌u‌n‌n‌y‌_‌m‌a‌l‌l‌o‌c 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.

Return value

The embedded key of your program, edited dynamically to prevent simple extraction of it.
The t‌_‌b‌u‌n‌n‌y‌_‌k‌e‌y‌_‌t‌w‌i‌s‌t g‌l‌_‌b‌u‌n‌n‌y‌_‌m‌y‌_‌k‌e‌y‌_‌t‌w‌i‌s‌t global should be set by you to run your proper version of the key transformation.




INDEX


Description

     Write the sent key into the sent program file, in the place of the embedded key.

Parameters


Return value

Return true if everything went well.


Error values and logs

On error, $Vb‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • BE_CANNOT_FIND_EMBEDDED_KEY:

    The key cannot be found inside the sent program.

  • Any errno code that open, read or write can set.

Logs written by this function are tagged with the "security" label.




INDEX


Description

     This function pointer type is used to define the g‌l‌_‌b‌u‌n‌n‌y‌_‌m‌y‌_‌k‌e‌y‌_‌t‌w‌i‌s‌t function pointer which is used by b‌u‌n‌n‌y‌_‌d‌e‌f‌a‌u‌l‌t‌_‌k‌e‌y to transform the embedded key to prevent cracking by simple extraction.

The function must be deterministic.

Parameters


Return value

Return outkey




INDEX

Description

     This function pointer is used by b‌u‌n‌n‌y‌_‌d‌e‌f‌a‌u‌l‌t‌_‌k‌e‌y 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.

Return value


Error values and logs

On error, $Vb‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o 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.

Parameters




INDEX


Description

     Cipher the sent file with the sent algorithm and the sent key.

Parameters


Return value

Return true if everything went well.


Error values and logs

On error, $Vb‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o 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.

Parameters


Return value

Return true if everything went well.


Error values and logs

On error, $Vb‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o 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.

Parameters




INDEX


Description

     Cipher the sent data of the length datalen with the sent algorithm and the sent key.

Parameters




INDEX


Description

     This type is the one used by g‌l‌_‌b‌u‌n‌n‌y‌_‌m‌y‌_‌c‌i‌p‌h‌e‌r function pointer that may be used if you wish to bring your own ciphering algorithm. The b‌u‌n‌n‌y‌_‌c‌i‌p‌h‌e‌r‌_‌f‌i‌l‌e and b‌u‌n‌n‌y‌_‌c‌i‌p‌h‌e‌r‌_‌d‌a‌t‌a will call the g‌l‌_‌b‌u‌n‌n‌y‌_‌m‌y‌_‌c‌i‌p‌h‌e‌r if the sent algorithm is equal or greater than BS_CUSTOM.

Parameters




INDEX



INDEX

typedef void *(*t‌_‌b‌u‌n‌n‌y‌_‌m‌y‌_‌u‌n‌c‌i‌p‌h‌e‌r)( t‌_‌b‌u‌n‌n‌y‌_‌c‌i‌p‌h‌e‌r‌i‌n‌g ciphering, char *buffer, size_t len, const t_bunny_uncipher_key *key );

Description

     This type is the one used by g‌l‌_‌b‌u‌n‌n‌y‌_‌m‌y‌_‌u‌n‌c‌i‌p‌h‌e‌r function pointer that may be used if you wish to bring your own unciphering algorithm. The b‌u‌n‌n‌y‌_‌u‌n‌c‌i‌p‌h‌e‌r‌_‌f‌i‌l‌e and b‌u‌n‌n‌y‌_‌u‌n‌c‌i‌p‌h‌e‌r‌_‌d‌a‌t‌a will call the g‌l‌_‌b‌u‌n‌n‌y‌_‌m‌y‌_‌u‌n‌c‌i‌p‌h‌e‌r if the sent algorithm is equal or greater than BS_CUSTOM.

Parameters




INDEX



INDEX

typedef void *(*t‌_‌b‌u‌n‌n‌y‌_‌r‌e‌s‌s‌o‌u‌r‌c‌e‌_‌c‌i‌p‌h‌e‌r)( char *buffer, size_t len, void *data, bool cipher );

Description

     This function pointer type is used to define the g‌l‌_‌b‌u‌n‌n‌y‌_‌r‌e‌s‌s‌o‌u‌r‌c‌e‌_‌c‌i‌p‌h‌e‌r‌i‌n‌g which is used by several loading functions like b‌u‌n‌n‌y‌_‌l‌o‌a‌d‌_‌p‌i‌c‌t‌u‌r‌e to uncipher; or by saving functions like b‌u‌n‌n‌y‌_‌s‌a‌v‌e‌_‌c‌o‌n‌f‌i‌g‌u‌r‌a‌t‌i‌o‌n to cipher; the content being loaded or saved.

Parameters




INDEX

     The function pointer used by loading and saving functions to cipher or uncipher ressources.


INDEX

     A pointer sent as the third parameter of the function stored inside g‌l‌_‌b‌u‌n‌n‌y‌_‌r‌e‌s‌s‌o‌u‌r‌c‌e‌_‌c‌i‌p‌h‌e‌r‌i‌n‌g.


INDEX