X-Git-Url: http://git.silcnet.org/gitweb/?p=crypto.git;a=blobdiff_plain;f=lib%2Fsilccrypt%2Fsilccipher_i.h;fp=lib%2Fsilccrypt%2Fsilccipher_i.h;h=e52d8f00196716e48da8b1515a76c4b99ced701d;hp=a148d29113a60a305b0db272ea4b674db2eeb564;hb=9f20f0382b6229eca740925a73f96294f6dcedc6;hpb=1b4e874f9401653b659a6adec2d2f046f9331586 diff --git a/lib/silccrypt/silccipher_i.h b/lib/silccrypt/silccipher_i.h index a148d291..e52d8f00 100644 --- a/lib/silccrypt/silccipher_i.h +++ b/lib/silccrypt/silccipher_i.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2007 Pekka Riikonen + Copyright (C) 2007 - 2008 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,67 +24,88 @@ #error "Do not include this header directly" #endif +/* The SilcCipher context. This is not visible to application programmer. + It is accessible from the algorithm implementations. */ +struct SilcCipherStruct { + SilcCipherObject *cipher; /* Cipher operations */ + void *context; /* Algorithm context */ + unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* IV */ + unsigned char block[SILC_CIPHER_MAX_IV_SIZE]; /* Extra block for free use */ +}; + /* These macros can be used to implement the SILC Crypto API and to avoid errors in the API these macros should be used always. */ #define SILC_CIPHER_API_SET_KEY(name) \ - SilcBool silc_##name##_set_key(struct SilcCipherObjectStruct *cipher, \ - void *context, \ - const unsigned char *key, \ + SilcBool silc_##name##_set_key(SilcCipher cipher, \ + struct SilcCipherObjectStruct *ops, \ + void *context, void *key, \ SilcUInt32 keylen, \ SilcBool encryption) #define SILC_CIPHER_API_SET_IV(name) \ - void silc_##name##_set_iv(struct SilcCipherObjectStruct *cipher, \ + void silc_##name##_set_iv(SilcCipher cipher, \ + struct SilcCipherObjectStruct *ops, \ void *context, \ unsigned char *iv) #define SILC_CIPHER_API_ENCRYPT(name) \ - SilcBool silc_##name##_encrypt(struct SilcCipherObjectStruct *cipher, \ + SilcBool silc_##name##_encrypt(SilcCipher cipher, \ + struct SilcCipherObjectStruct *ops, \ void *context, \ const unsigned char *src, \ unsigned char *dst, \ SilcUInt32 len, \ unsigned char *iv) #define SILC_CIPHER_API_DECRYPT(name) \ - SilcBool silc_##name##_decrypt(struct SilcCipherObjectStruct *cipher, \ + SilcBool silc_##name##_decrypt(SilcCipher cipher, \ + struct SilcCipherObjectStruct *ops, \ void *context, \ const unsigned char *src, \ unsigned char *dst, \ SilcUInt32 len, \ unsigned char *iv) -#define SILC_CIPHER_API_CONTEXT_LEN(name) \ - SilcUInt32 silc_##name##_context_len() +#define SILC_CIPHER_API_INIT(name) \ + void *silc_##name##_init(struct SilcCipherObjectStruct *ops) +#define SILC_CIPHER_API_UNINIT(name) \ + void silc_##name##_uninit(struct SilcCipherObjectStruct *ops, \ + void *context) /* Cipher object to represent a cipher algorithm. */ struct SilcCipherObjectStruct { /* Cipher name */ char *name; + char *alg_name; /* Set new key. If `encryption' is TRUE the key is for encryption, FALSE for decryption. The `keylen' is in bits. */ - SilcBool (*set_key)(struct SilcCipherObjectStruct *cipher, - void *context, const unsigned char *key, - SilcUInt32 keylen, SilcBool encryption); + SilcBool (*set_key)(SilcCipher cipher, struct SilcCipherObjectStruct *ops, + void *context, void *key, SilcUInt32 keylen, + SilcBool encryption); /* Set IV. The upper layer (SilcCipher) maintains the IV. If the algorithm needs to set the IV itself, this should be implemented. */ - void (*set_iv)(struct SilcCipherObjectStruct *cipher, + void (*set_iv)(SilcCipher cipher, struct SilcCipherObjectStruct *ops, void *context, unsigned char *iv); /* Encrypt. The `src' and `dst' may be same pointer. The `iv' may be edited inside this function. */ - SilcBool (*encrypt)(struct SilcCipherObjectStruct *cipher, + SilcBool (*encrypt)(SilcCipher cipher, struct SilcCipherObjectStruct *ops, void *context, const unsigned char *src, unsigned char *dst, SilcUInt32 len, unsigned char *iv); /* Decrypt. The `src' and `dst' may be same pointer. The `iv' may be edited inside this function. */ - SilcBool (*decrypt)(struct SilcCipherObjectStruct *cipher, + SilcBool (*decrypt)(SilcCipher cipher, struct SilcCipherObjectStruct *ops, void *context, const unsigned char *src, unsigned char *dst, SilcUInt32 len, unsigned char *iv); - /* Returns the length of the internal cipher context */ - SilcUInt32 (*context_len)(void); + /* Initializes the cipher. Returns internal cipher context. The uninit() + will be called in silc_cipher_free to uninitialize the cipher and free + the context. */ + void *(*init)(struct SilcCipherObjectStruct *ops); + + /* Uninitialize cipher. */ + void (*uninit)(struct SilcCipherObjectStruct *ops, void *context); unsigned int key_len : 10; /* Key length in bits */ unsigned int block_len : 8; /* Block size in bytes */