|
@@ -1,6 +1,6 @@
|
|
|
/* ---- SYMMETRIC KEY STUFF -----
|
|
|
*
|
|
|
- * We put each of the ciphers scheduled keys in their own structs then we put all of
|
|
|
+ * We put each of the ciphers scheduled keys in their own structs then we put all of
|
|
|
* the key formats in one union. This makes the function prototypes easier to use.
|
|
|
*/
|
|
|
#ifdef LTC_BLOWFISH
|
|
@@ -109,7 +109,7 @@ struct noekeon_key {
|
|
|
};
|
|
|
#endif
|
|
|
|
|
|
-#ifdef LTC_SKIPJACK
|
|
|
+#ifdef LTC_SKIPJACK
|
|
|
struct skipjack_key {
|
|
|
unsigned char key[10];
|
|
|
};
|
|
@@ -117,18 +117,18 @@ struct skipjack_key {
|
|
|
|
|
|
#ifdef LTC_KHAZAD
|
|
|
struct khazad_key {
|
|
|
- ulong64 roundKeyEnc[8 + 1];
|
|
|
- ulong64 roundKeyDec[8 + 1];
|
|
|
+ ulong64 roundKeyEnc[8 + 1];
|
|
|
+ ulong64 roundKeyDec[8 + 1];
|
|
|
};
|
|
|
#endif
|
|
|
|
|
|
#ifdef LTC_ANUBIS
|
|
|
-struct anubis_key {
|
|
|
- int keyBits;
|
|
|
- int R;
|
|
|
- ulong32 roundKeyEnc[18 + 1][4];
|
|
|
- ulong32 roundKeyDec[18 + 1][4];
|
|
|
-};
|
|
|
+struct anubis_key {
|
|
|
+ int keyBits;
|
|
|
+ int R;
|
|
|
+ ulong32 roundKeyEnc[18 + 1][4];
|
|
|
+ ulong32 roundKeyDec[18 + 1][4];
|
|
|
+};
|
|
|
#endif
|
|
|
|
|
|
#ifdef LTC_MULTI2
|
|
@@ -182,7 +182,7 @@ typedef union Symmetric_key {
|
|
|
#endif
|
|
|
#ifdef LTC_NOEKEON
|
|
|
struct noekeon_key noekeon;
|
|
|
-#endif
|
|
|
+#endif
|
|
|
#ifdef LTC_SKIPJACK
|
|
|
struct skipjack_key skipjack;
|
|
|
#endif
|
|
@@ -197,7 +197,7 @@ typedef union Symmetric_key {
|
|
|
#endif
|
|
|
#ifdef LTC_KASUMI
|
|
|
struct kasumi_key kasumi;
|
|
|
-#endif
|
|
|
+#endif
|
|
|
#ifdef LTC_MULTI2
|
|
|
struct multi2_key multi2;
|
|
|
#endif
|
|
@@ -211,10 +211,10 @@ typedef union Symmetric_key {
|
|
|
/** A block cipher ECB structure */
|
|
|
typedef struct {
|
|
|
/** The index of the cipher chosen */
|
|
|
- int cipher,
|
|
|
+ int cipher,
|
|
|
/** The block size of the given cipher */
|
|
|
blocklen;
|
|
|
- /** The scheduled key */
|
|
|
+ /** The scheduled key */
|
|
|
symmetric_key key;
|
|
|
} symmetric_ECB;
|
|
|
#endif
|
|
@@ -223,14 +223,14 @@ typedef struct {
|
|
|
/** A block cipher CFB structure */
|
|
|
typedef struct {
|
|
|
/** The index of the cipher chosen */
|
|
|
- int cipher,
|
|
|
- /** The block size of the given cipher */
|
|
|
- blocklen,
|
|
|
+ int cipher,
|
|
|
+ /** The block size of the given cipher */
|
|
|
+ blocklen,
|
|
|
/** The padding offset */
|
|
|
padlen;
|
|
|
/** The current IV */
|
|
|
- unsigned char IV[MAXBLOCKSIZE],
|
|
|
- /** The pad used to encrypt/decrypt */
|
|
|
+ unsigned char IV[MAXBLOCKSIZE],
|
|
|
+ /** The pad used to encrypt/decrypt */
|
|
|
pad[MAXBLOCKSIZE];
|
|
|
/** The scheduled key */
|
|
|
symmetric_key key;
|
|
@@ -241,9 +241,9 @@ typedef struct {
|
|
|
/** A block cipher OFB structure */
|
|
|
typedef struct {
|
|
|
/** The index of the cipher chosen */
|
|
|
- int cipher,
|
|
|
- /** The block size of the given cipher */
|
|
|
- blocklen,
|
|
|
+ int cipher,
|
|
|
+ /** The block size of the given cipher */
|
|
|
+ blocklen,
|
|
|
/** The padding offset */
|
|
|
padlen;
|
|
|
/** The current IV */
|
|
@@ -257,8 +257,8 @@ typedef struct {
|
|
|
/** A block cipher CBC structure */
|
|
|
typedef struct {
|
|
|
/** The index of the cipher chosen */
|
|
|
- int cipher,
|
|
|
- /** The block size of the given cipher */
|
|
|
+ int cipher,
|
|
|
+ /** The block size of the given cipher */
|
|
|
blocklen;
|
|
|
/** The current IV */
|
|
|
unsigned char IV[MAXBLOCKSIZE];
|
|
@@ -273,18 +273,18 @@ typedef struct {
|
|
|
typedef struct {
|
|
|
/** The index of the cipher chosen */
|
|
|
int cipher,
|
|
|
- /** The block size of the given cipher */
|
|
|
- blocklen,
|
|
|
+ /** The block size of the given cipher */
|
|
|
+ blocklen,
|
|
|
/** The padding offset */
|
|
|
- padlen,
|
|
|
+ padlen,
|
|
|
/** The mode (endianess) of the CTR, 0==little, 1==big */
|
|
|
mode,
|
|
|
/** counter width */
|
|
|
ctrlen;
|
|
|
|
|
|
- /** The counter */
|
|
|
- unsigned char ctr[MAXBLOCKSIZE],
|
|
|
- /** The pad used to encrypt/decrypt */
|
|
|
+ /** The counter */
|
|
|
+ unsigned char ctr[MAXBLOCKSIZE],
|
|
|
+ /** The pad used to encrypt/decrypt */
|
|
|
pad[MAXBLOCKSIZE];
|
|
|
/** The scheduled key */
|
|
|
symmetric_key key;
|
|
@@ -300,7 +300,7 @@ typedef struct {
|
|
|
|
|
|
/** The current IV */
|
|
|
unsigned char IV[16],
|
|
|
-
|
|
|
+
|
|
|
/** the tweak key */
|
|
|
tweak[16],
|
|
|
|
|
@@ -321,9 +321,9 @@ typedef struct {
|
|
|
/** A block cipher F8 structure */
|
|
|
typedef struct {
|
|
|
/** The index of the cipher chosen */
|
|
|
- int cipher,
|
|
|
- /** The block size of the given cipher */
|
|
|
- blocklen,
|
|
|
+ int cipher,
|
|
|
+ /** The block size of the given cipher */
|
|
|
+ blocklen,
|
|
|
/** The padding offset */
|
|
|
padlen;
|
|
|
/** The current IV */
|
|
@@ -344,14 +344,14 @@ extern struct ltc_cipher_descriptor {
|
|
|
/** internal ID */
|
|
|
unsigned char ID;
|
|
|
/** min keysize (octets) */
|
|
|
- int min_key_length,
|
|
|
+ int min_key_length,
|
|
|
/** max keysize (octets) */
|
|
|
- max_key_length,
|
|
|
+ max_key_length,
|
|
|
/** block size (octets) */
|
|
|
- block_length,
|
|
|
+ block_length,
|
|
|
/** default number of rounds */
|
|
|
default_rounds;
|
|
|
- /** Setup the cipher
|
|
|
+ /** Setup the cipher
|
|
|
@param key The input symmetric key
|
|
|
@param keylen The length of the input key (octets)
|
|
|
@param num_rounds The requested number of rounds (0==default)
|
|
@@ -378,10 +378,10 @@ extern struct ltc_cipher_descriptor {
|
|
|
*/
|
|
|
int (*test)(void);
|
|
|
|
|
|
- /** Terminate the context
|
|
|
+ /** Terminate the context
|
|
|
@param skey The scheduled key
|
|
|
*/
|
|
|
- void (*done)(symmetric_key *skey);
|
|
|
+ void (*done)(symmetric_key *skey);
|
|
|
|
|
|
/** Determine a key size
|
|
|
@param keysize [in/out] The size of the key desired and the suggested size
|
|
@@ -390,7 +390,7 @@ extern struct ltc_cipher_descriptor {
|
|
|
int (*keysize)(int *keysize);
|
|
|
|
|
|
/** Accelerators **/
|
|
|
- /** Accelerated ECB encryption
|
|
|
+ /** Accelerated ECB encryption
|
|
|
@param pt Plaintext
|
|
|
@param ct Ciphertext
|
|
|
@param blocks The number of complete blocks to process
|
|
@@ -399,7 +399,7 @@ extern struct ltc_cipher_descriptor {
|
|
|
*/
|
|
|
int (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey);
|
|
|
|
|
|
- /** Accelerated ECB decryption
|
|
|
+ /** Accelerated ECB decryption
|
|
|
@param pt Plaintext
|
|
|
@param ct Ciphertext
|
|
|
@param blocks The number of complete blocks to process
|
|
@@ -408,7 +408,7 @@ extern struct ltc_cipher_descriptor {
|
|
|
*/
|
|
|
int (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey);
|
|
|
|
|
|
- /** Accelerated CBC encryption
|
|
|
+ /** Accelerated CBC encryption
|
|
|
@param pt Plaintext
|
|
|
@param ct Ciphertext
|
|
|
@param blocks The number of complete blocks to process
|
|
@@ -418,7 +418,7 @@ extern struct ltc_cipher_descriptor {
|
|
|
*/
|
|
|
int (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
|
|
|
|
|
|
- /** Accelerated CBC decryption
|
|
|
+ /** Accelerated CBC decryption
|
|
|
@param pt Plaintext
|
|
|
@param ct Ciphertext
|
|
|
@param blocks The number of complete blocks to process
|
|
@@ -428,7 +428,7 @@ extern struct ltc_cipher_descriptor {
|
|
|
*/
|
|
|
int (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
|
|
|
|
|
|
- /** Accelerated CTR encryption
|
|
|
+ /** Accelerated CTR encryption
|
|
|
@param pt Plaintext
|
|
|
@param ct Ciphertext
|
|
|
@param blocks The number of complete blocks to process
|
|
@@ -439,7 +439,7 @@ extern struct ltc_cipher_descriptor {
|
|
|
*/
|
|
|
int (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey);
|
|
|
|
|
|
- /** Accelerated LRW
|
|
|
+ /** Accelerated LRW
|
|
|
@param pt Plaintext
|
|
|
@param ct Ciphertext
|
|
|
@param blocks The number of complete blocks to process
|
|
@@ -450,7 +450,7 @@ extern struct ltc_cipher_descriptor {
|
|
|
*/
|
|
|
int (*accel_lrw_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey);
|
|
|
|
|
|
- /** Accelerated LRW
|
|
|
+ /** Accelerated LRW
|
|
|
@param ct Ciphertext
|
|
|
@param pt Plaintext
|
|
|
@param blocks The number of complete blocks to process
|
|
@@ -490,7 +490,7 @@ extern struct ltc_cipher_descriptor {
|
|
|
/** Accelerated GCM packet (one shot)
|
|
|
@param key The secret key
|
|
|
@param keylen The length of the secret key
|
|
|
- @param IV The initial vector
|
|
|
+ @param IV The initial vector
|
|
|
@param IVlen The length of the initial vector
|
|
|
@param adata The additional authentication data (header)
|
|
|
@param adatalen The length of the adata
|
|
@@ -507,14 +507,14 @@ extern struct ltc_cipher_descriptor {
|
|
|
const unsigned char *IV, unsigned long IVlen,
|
|
|
const unsigned char *adata, unsigned long adatalen,
|
|
|
unsigned char *pt, unsigned long ptlen,
|
|
|
- unsigned char *ct,
|
|
|
+ unsigned char *ct,
|
|
|
unsigned char *tag, unsigned long *taglen,
|
|
|
int direction);
|
|
|
|
|
|
- /** Accelerated one shot LTC_OMAC
|
|
|
+ /** Accelerated one shot LTC_OMAC
|
|
|
@param key The secret key
|
|
|
- @param keylen The key length (octets)
|
|
|
- @param in The message
|
|
|
+ @param keylen The key length (octets)
|
|
|
+ @param in The message
|
|
|
@param inlen Length of message (octets)
|
|
|
@param out [out] Destination for tag
|
|
|
@param outlen [in/out] Initial and final size of out
|
|
@@ -525,10 +525,10 @@ extern struct ltc_cipher_descriptor {
|
|
|
const unsigned char *in, unsigned long inlen,
|
|
|
unsigned char *out, unsigned long *outlen);
|
|
|
|
|
|
- /** Accelerated one shot XCBC
|
|
|
+ /** Accelerated one shot XCBC
|
|
|
@param key The secret key
|
|
|
- @param keylen The key length (octets)
|
|
|
- @param in The message
|
|
|
+ @param keylen The key length (octets)
|
|
|
+ @param in The message
|
|
|
@param inlen Length of message (octets)
|
|
|
@param out [out] Destination for tag
|
|
|
@param outlen [in/out] Initial and final size of out
|
|
@@ -539,10 +539,10 @@ extern struct ltc_cipher_descriptor {
|
|
|
const unsigned char *in, unsigned long inlen,
|
|
|
unsigned char *out, unsigned long *outlen);
|
|
|
|
|
|
- /** Accelerated one shot F9
|
|
|
+ /** Accelerated one shot F9
|
|
|
@param key The secret key
|
|
|
- @param keylen The key length (octets)
|
|
|
- @param in The message
|
|
|
+ @param keylen The key length (octets)
|
|
|
+ @param in The message
|
|
|
@param inlen Length of message (octets)
|
|
|
@param out [out] Destination for tag
|
|
|
@param outlen [in/out] Initial and final size of out
|
|
@@ -777,7 +777,7 @@ extern const struct ltc_cipher_descriptor camellia_desc;
|
|
|
#endif
|
|
|
|
|
|
#ifdef LTC_ECB_MODE
|
|
|
-int ecb_start(int cipher, const unsigned char *key,
|
|
|
+int ecb_start(int cipher, const unsigned char *key,
|
|
|
int keylen, int num_rounds, symmetric_ECB *ecb);
|
|
|
int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb);
|
|
|
int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb);
|
|
@@ -785,7 +785,7 @@ int ecb_done(symmetric_ECB *ecb);
|
|
|
#endif
|
|
|
|
|
|
#ifdef LTC_CFB_MODE
|
|
|
-int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
|
|
+int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
|
|
int keylen, int num_rounds, symmetric_CFB *cfb);
|
|
|
int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb);
|
|
|
int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb);
|
|
@@ -795,7 +795,7 @@ int cfb_done(symmetric_CFB *cfb);
|
|
|
#endif
|
|
|
|
|
|
#ifdef LTC_OFB_MODE
|
|
|
-int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
|
|
+int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
|
|
int keylen, int num_rounds, symmetric_OFB *ofb);
|
|
|
int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb);
|
|
|
int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb);
|
|
@@ -842,7 +842,7 @@ int lrw_start( int cipher,
|
|
|
const unsigned char *IV,
|
|
|
const unsigned char *key, int keylen,
|
|
|
const unsigned char *tweak,
|
|
|
- int num_rounds,
|
|
|
+ int num_rounds,
|
|
|
symmetric_LRW *lrw);
|
|
|
int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw);
|
|
|
int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw);
|
|
@@ -853,11 +853,11 @@ int lrw_test(void);
|
|
|
|
|
|
/* don't call */
|
|
|
int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw);
|
|
|
-#endif
|
|
|
+#endif
|
|
|
|
|
|
#ifdef LTC_F8_MODE
|
|
|
-int f8_start( int cipher, const unsigned char *IV,
|
|
|
- const unsigned char *key, int keylen,
|
|
|
+int f8_start( int cipher, const unsigned char *IV,
|
|
|
+ const unsigned char *key, int keylen,
|
|
|
const unsigned char *salt_key, int skeylen,
|
|
|
int num_rounds, symmetric_F8 *f8);
|
|
|
int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8);
|
|
@@ -875,10 +875,10 @@ typedef struct {
|
|
|
} symmetric_xts;
|
|
|
|
|
|
int xts_start( int cipher,
|
|
|
- const unsigned char *key1,
|
|
|
- const unsigned char *key2,
|
|
|
+ const unsigned char *key1,
|
|
|
+ const unsigned char *key2,
|
|
|
unsigned long keylen,
|
|
|
- int num_rounds,
|
|
|
+ int num_rounds,
|
|
|
symmetric_xts *xts);
|
|
|
|
|
|
int xts_encrypt(
|