89 lines
2.5 KiB
C
89 lines
2.5 KiB
C
/*
|
|
************************************************************************
|
|
**
|
|
** Copyright (c) 2011 by
|
|
** Core|Vision B.V.
|
|
** Cereslaan 10b
|
|
** 5384 VT Heesch
|
|
** The Netherlands
|
|
**
|
|
** All Rights Reserved
|
|
**
|
|
************************************************************************
|
|
*/
|
|
/*
|
|
************************************************************************
|
|
**
|
|
** Project name: Dual Inventive: Utility Library
|
|
** Filename: cp3000-encrypt.h
|
|
** Author: Jack Weeland
|
|
** Date: December 1, 2011
|
|
** File version: $Revision: 1.4 $
|
|
** $Date: 2013/04/15 15:37:42 $
|
|
**
|
|
************************************************************************
|
|
*/
|
|
/*
|
|
************************************************************************
|
|
**
|
|
** CP3000 block cypher encryption
|
|
**
|
|
************************************************************************
|
|
*/
|
|
|
|
#ifndef __CP3000_ENCRYPT_H
|
|
#define __CP3000_ENCRYPT_H
|
|
|
|
#include <di-util/cp3000.h>
|
|
|
|
/*
|
|
** Exported functions
|
|
*/
|
|
// Initialize and destroy encryption state
|
|
cp3000_key_t cp3000_init_encrypt_state();
|
|
void cp3000_deinit_encrypt_state(cp3000_key_t);
|
|
|
|
// Set encryption and decryptions keys and initialize state vector;
|
|
// the key _must_ be set, but the vectors will be zero-initialized
|
|
// The key size _must_ be 128, 192 or 256 bits (16, 24 or 32 bytes)
|
|
int cp3000_encrypt_set_key(cp3000_key_t, const void *key, int key_sz);
|
|
int cp3000_encrypt_set_state(cp3000_key_t, const void *vector, int vector_sz);
|
|
int cp3000_decrypt_set_state(cp3000_key_t, const void *vector, int vector_sz);
|
|
|
|
// Encrypt data buffer
|
|
// Parameters:
|
|
// - encryption state
|
|
// - input and output data buffer and size
|
|
// Note:
|
|
// The input buffer is padded with random data bytes for better
|
|
// security. For that reason, the output buffer should be larger
|
|
// than the input buffer.
|
|
int cp3000_encrypt(
|
|
cp3000_key_t,
|
|
const void *in, int in_sz,
|
|
void* out, int out_sz
|
|
);
|
|
|
|
// Decrypt data buffer
|
|
// Parameters:
|
|
// - encryption state
|
|
// - input and output data buffer and size
|
|
// Note:
|
|
// The input and output buffers should be the same size; if the
|
|
// sizes are diffent, then the minimum value will be used. Surplus
|
|
// bytes are simply ignored.
|
|
int cp3000_decrypt(
|
|
cp3000_key_t,
|
|
const void *in, int in_sz,
|
|
void* out, int out_sz
|
|
);
|
|
|
|
// Fill a buffer with random data
|
|
// Returns:
|
|
// < 0 on error
|
|
// 0 when the data is _not_ unpredictable
|
|
// 1 when the dats is unpredictable and thus cryptographically okay
|
|
int cp3000_random_bytes(void *buffer, int buffer_sz);
|
|
|
|
#endif /* __CP3000_ENCRYPT_H */
|