SILC_AES_S = aes_x86.asm aes.c
endif
if SILC_X86_64
-SILC_AES_S = aes_x86_84.asm aes.c
+SILC_AES_S = aes_x86_64.asm aes.c
endif
else
SILC_AES_S = aes.c
SILC_CIPHER_API_SET_KEY(aes)
{
- aes_encrypt_key(key, keylen, &((AesContext *)context)->enc);
- aes_decrypt_key(key, keylen, &((AesContext *)context)->dec);
+ if (encryption)
+ aes_encrypt_key(key, keylen, &((AesContext *)context)->u.enc);
+ else
+ aes_decrypt_key(key, keylen, &((AesContext *)context)->u.dec);
return TRUE;
}
lp32(iv)[1] ^= lp32(src)[1];
lp32(iv)[2] ^= lp32(src)[2];
lp32(iv)[3] ^= lp32(src)[3];
- aes_encrypt(iv, iv, &((AesContext *)context)->enc);
+ aes_encrypt(iv, iv, &((AesContext *)context)->u.enc);
memcpy(dst, iv, 16);
src += 16;
dst += 16;
while(nb--) {
memcpy(tmp, src, 16);
- aes_decrypt(src, dst, &((AesContext *)context)->dec);
+ aes_decrypt(src, dst, &((AesContext *)context)->u.dec);
lp32(dst)[0] ^= lp32(iv)[0];
lp32(dst)[1] ^= lp32(iv)[1];
lp32(dst)[2] ^= lp32(iv)[2];
} aes_decrypt_ctx;
typedef struct {
- aes_encrypt_ctx enc;
- aes_decrypt_ctx dec;
+ union {
+ aes_encrypt_ctx enc;
+ aes_decrypt_ctx dec;
+ } u;
} AesContext;
#define AES_RETURN void
/* Sets the key for the cipher */
SilcBool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key,
- SilcUInt32 keylen)
+ SilcUInt32 keylen, SilcBool encryption)
{
- return cipher->cipher->set_key(cipher->context, key, keylen);
+ return cipher->cipher->set_key(cipher->context, key, keylen, encryption);
}
/* Sets the IV (initial vector) for the cipher. */
/* The default SILC Cipher object to represent any cipher in SILC. */
typedef struct {
char *name;
- SilcBool (*set_key)(void *, const unsigned char *, SilcUInt32);
+ SilcBool (*set_key)(void *, const unsigned char *, SilcUInt32, SilcBool);
SilcBool (*encrypt)(void *, const unsigned char *, unsigned char *,
SilcUInt32, unsigned char *);
SilcBool (*decrypt)(void *, const unsigned char *, unsigned char *,
/* Default cipher in the SILC protocol */
#define SILC_DEFAULT_CIPHER "aes-256-cbc"
-
/* Macros */
/* Function names in SILC Crypto modules. The name of the cipher
#define SILC_CIPHER_API_SET_KEY(cipher) \
SilcBool silc_##cipher##_set_key(void *context, \
const unsigned char *key, \
- SilcUInt32 keylen)
+ SilcUInt32 keylen, \
+ SilcBool encryption)
#define SILC_CIPHER_API_ENCRYPT_CBC(cipher) \
SilcBool silc_##cipher##_encrypt_cbc(void *context, \
const unsigned char *src, \
unsigned char *dst, \
SilcUInt32 len, \
unsigned char *iv)
-
-
#define SILC_CIPHER_API_CONTEXT_LEN(cipher) \
SilcUInt32 silc_##cipher##_context_len()
-
/* Prototypes */
/****f* silccrypt/SilcCipherAPI/silc_cipher_register
* SYNOPSIS
*
* SilcBool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key,
- * SilcUInt32 keylen);
+ * SilcUInt32 keylen, SilcBool encryption);
*
* DESCRIPTION
*
* Sets the key for the cipher. The `keylen' is the key length in
- * bits.
+ * bits. If the `encryption' is TRUE the key is for encryption, if FALSE
+ * the key is for decryption.
*
***/
SilcBool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key,
- SilcUInt32 keylen);
+ SilcUInt32 keylen, SilcBool encryption);
/****f* silccrypt/SilcCipherAPI/silc_cipher_set_iv
*
***/
const char *silc_cipher_get_name(SilcCipher cipher);
-#endif
+#endif /* SILCCIPHER_H */
silc_hash_final(sha1, keymat + 16);
/* Set the key to the cipher */
- silc_cipher_set_key(aes, keymat, 256);
+ silc_cipher_set_key(aes, keymat, 256, FALSE);
/* First, verify the MAC of the private key data */
mac_len = silc_hmac_len(sha1hmac);
silc_hash_final(sha1, keymat + 16);
/* Set the key to the cipher */
- silc_cipher_set_key(aes, keymat, 256);
+ silc_cipher_set_key(aes, keymat, 256, TRUE);
/* Encode the buffer to be encrypted. Add padding to it too, at least
block size of the cipher. */
if (ske->responder) {
if (ret_send_key) {
silc_cipher_set_key(*ret_send_key, keymat->receive_enc_key,
- keymat->enc_key_len);
+ keymat->enc_key_len, TRUE);
silc_cipher_set_iv(*ret_send_key, keymat->receive_iv);
}
if (ret_receive_key) {
silc_cipher_set_key(*ret_receive_key, keymat->send_enc_key,
- keymat->enc_key_len);
+ keymat->enc_key_len, FALSE);
silc_cipher_set_iv(*ret_receive_key, keymat->send_iv);
}
if (ret_hmac_send)
} else {
if (ret_send_key) {
silc_cipher_set_key(*ret_send_key, keymat->send_enc_key,
- keymat->enc_key_len);
+ keymat->enc_key_len, TRUE);
silc_cipher_set_iv(*ret_send_key, keymat->send_iv);
}
if (ret_receive_key) {
silc_cipher_set_key(*ret_receive_key, keymat->receive_enc_key,
- keymat->enc_key_len);
+ keymat->enc_key_len, FALSE);
silc_cipher_set_iv(*ret_receive_key, keymat->receive_iv);
}
if (ret_hmac_send)