Ordo  0.3.4
Symmetric Cryptography Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
ordo.h File Reference

Wrapper. More...

#include "ordo/common/version.h"
#include "ordo/common/error.h"
#include "ordo/common/query.h"
#include "ordo/enc/enc_stream.h"
#include "ordo/enc/enc_block.h"
#include "ordo/auth/hmac.h"
#include "ordo/kdf/hkdf.h"
#include "ordo/kdf/pbkdf2.h"
#include "ordo/misc/utils.h"
#include "ordo/misc/os_random.h"
#include "ordo/misc/curve25519.h"
Include dependency graph for ordo.h:

Go to the source code of this file.

Functions

ORDO_PUBLIC int ordo_enc_block (prim_t cipher, const void *cipher_params, prim_t mode, const void *mode_params, int direction, const void *key, size_t key_len, const void *iv, size_t iv_len, const void *in, size_t in_len, void *out, size_t *out_len)
 
ORDO_PUBLIC int ordo_enc_stream (prim_t cipher, const void *params, const void *key, size_t key_len, void *inout, size_t len)
 
ORDO_PUBLIC int ordo_digest (prim_t hash, const void *params, const void *in, size_t in_len, void *digest)
 
ORDO_PUBLIC int ordo_hmac (prim_t hash, const void *params, const void *key, size_t key_len, const void *in, size_t in_len, void *fingerprint)
 

Detailed Description

Wrapper.

This is the highest-level API for Ordo, which forgoes the use of cryptographic contexts completely, resulting in more concise code at the cost of reduced flexibility - in other words, if you can afford to use them, you probably want to do so.

Usage snippet (compare to snippet in digest.h):

const char x[] = "Hello, world!";
unsigned char out[32]; // 256 bits
int err = ordo_digest(HASH_SHA256, 0, x, strlen(x), out);
if (err) printf("Error encountered!\n");
// out = 315f5bdb76d0...

Some specialized headers are not included by this header - these are the endianness header & all primitive headers (their parameters are included), if you need their functionality please include them explicitly.

Function Documentation

ORDO_PUBLIC int ordo_enc_block ( prim_t  cipher,
const void *  cipher_params,
prim_t  mode,
const void *  mode_params,
int  direction,
const void *  key,
size_t  key_len,
const void *  iv,
size_t  iv_len,
const void *  in,
size_t  in_len,
void *  out,
size_t *  out_len 
)

Encrypts or decrypts data using a block cipher with a mode of operation.

Parameters
[in]cipherThe block cipher to use.
[in]cipher_paramsThe block cipher parameters.
[in]modeThe mode of operation to use.
[in]mode_paramsThe mode of operation parameters.
[in]direction1 for encryption, 0 for decryption.
[in]keyThe cryptographic key to use.
[in]key_lenThe length in bytes of the key.
[in]ivThe initialization vector.
[in]iv_lenThe length in bytes of the IV.
[in]inThe input plaintext/ciphertext buffer.
[in]in_lenThe length of the input buffer.
[out]outThe output ciphertext/plaintext buffer.
[out]out_lenThe length of the output buffer.
Returns
ORDO_SUCCESS on success, else an error code.
Remarks
The out buffer should be large enough to accomodate the entire ciphertext which may be larger than the plaintext if a mode where padding is enabled and used, see padding notes in enc_block.h.
ORDO_PUBLIC int ordo_enc_stream ( prim_t  cipher,
const void *  params,
const void *  key,
size_t  key_len,
void *  inout,
size_t  len 
)

Encrypts or decrypts data using a stream cipher.

Parameters
[in]cipherThe stream cipher to use.
[in]paramsThe stream cipher parameters.
[in,out]inoutThe plaintext or ciphertext buffer.
[in]lenThe length, in bytes, of the buffer.
[in]keyThe cryptographic key to use.
[in]key_lenThe length, in bytes, of the key.
Returns
ORDO_SUCCESS on success, else an error code.
Remarks
Stream ciphers do not strictly speaking require an initialization vector - if such a feature is needed, it is recommended to use a key derivation function to derive an encryption key from a master key using a pseudorandomly generated nonce.
Encryption is always done in place. If you require out-of-place encryption, make a copy of the plaintext prior to encryption.
Warning
By design, encryption and decryption are equivalent for stream ciphers - an implication is that encrypting a message twice using the same key yields the original message.
ORDO_PUBLIC int ordo_digest ( prim_t  hash,
const void *  params,
const void *  in,
size_t  in_len,
void *  digest 
)

Calculates the digest of a buffer using any hash function.

Parameters
[in]hashThe hash function to use.
[in]paramsThe hash function parameters.
[in]inThe input buffer to hash.
[in]in_lenThe length in bytes of the buffer.
[out]digestThe output buffer for the digest.
Returns
ORDO_SUCCESS on success, else an error code.
ORDO_PUBLIC int ordo_hmac ( prim_t  hash,
const void *  params,
const void *  key,
size_t  key_len,
const void *  in,
size_t  in_len,
void *  fingerprint 
)

Calculates the HMAC fingerprint of a buffer using any hash function.

Parameters
[in]hashThe hash function to use.
[in]paramsThe hash function parameters.
[in]keyThe key to use for authentication.
[in]key_lenThe length in bytes of the key.
[in]inThe input buffer to authenticate.
[in]in_lenThe length, in bytes, of the input buffer.
[out]fingerprintThe output buffer for the fingerprint.
Returns
ORDO_SUCCESS on success, else an error code.