projects
/
silc.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
609978b
)
Added encryptio boolena indicator to silc_cipher_set_key.
author
Pekka Riikonen
<priikone@silcnet.org>
Mon, 18 Dec 2006 14:48:46 +0000
(14:48 +0000)
committer
Pekka Riikonen
<priikone@silcnet.org>
Mon, 18 Dec 2006 14:48:46 +0000
(14:48 +0000)
lib/silccrypt/Makefile.ad
patch
|
blob
|
history
lib/silccrypt/aes.c
patch
|
blob
|
history
lib/silccrypt/rijndael_internal.h
patch
|
blob
|
history
lib/silccrypt/silccipher.c
patch
|
blob
|
history
lib/silccrypt/silccipher.h
patch
|
blob
|
history
lib/silccrypt/silcpk.c
patch
|
blob
|
history
lib/silcske/silcske.c
patch
|
blob
|
history
diff --git
a/lib/silccrypt/Makefile.ad
b/lib/silccrypt/Makefile.ad
index 56de2636d99fdac10e1d7a6e40cdf1e49b7bb9b0..7f369d09d21c9047ec8c68ccb21cd68cbfa2e9d3 100644
(file)
--- a/
lib/silccrypt/Makefile.ad
+++ b/
lib/silccrypt/Makefile.ad
@@
-24,7
+24,7
@@
if SILC_I486
SILC_AES_S = aes_x86.asm aes.c
endif
if SILC_X86_64
SILC_AES_S = aes_x86.asm aes.c
endif
if SILC_X86_64
-SILC_AES_S = aes_x86_
8
4.asm aes.c
+SILC_AES_S = aes_x86_
6
4.asm aes.c
endif
else
SILC_AES_S = aes.c
endif
else
SILC_AES_S = aes.c
diff --git
a/lib/silccrypt/aes.c
b/lib/silccrypt/aes.c
index 9fc9f1e663ec0450e0f0523b35c59616e2b18a9a..d05bb7684a0bfb717d88ff1c7f0452c19e856256 100644
(file)
--- a/
lib/silccrypt/aes.c
+++ b/
lib/silccrypt/aes.c
@@
-45,8
+45,10
@@
SILC_CIPHER_API_SET_KEY(aes)
{
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;
}
return TRUE;
}
@@
-69,7
+71,7
@@
SILC_CIPHER_API_ENCRYPT_CBC(aes)
lp32(iv)[1] ^= lp32(src)[1];
lp32(iv)[2] ^= lp32(src)[2];
lp32(iv)[3] ^= lp32(src)[3];
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;
memcpy(dst, iv, 16);
src += 16;
dst += 16;
@@
-88,7
+90,7
@@
SILC_CIPHER_API_DECRYPT_CBC(aes)
while(nb--) {
memcpy(tmp, src, 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];
lp32(dst)[0] ^= lp32(iv)[0];
lp32(dst)[1] ^= lp32(iv)[1];
lp32(dst)[2] ^= lp32(iv)[2];
diff --git
a/lib/silccrypt/rijndael_internal.h
b/lib/silccrypt/rijndael_internal.h
index bd6051fd3771bb5eb5141e13d9a7628412316867..e6dcb1c3a4a5fa9dca85a4d7bcbec681625581e6 100644
(file)
--- a/
lib/silccrypt/rijndael_internal.h
+++ b/
lib/silccrypt/rijndael_internal.h
@@
-52,8
+52,10
@@
typedef struct {
} aes_decrypt_ctx;
typedef struct {
} 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
} AesContext;
#define AES_RETURN void
diff --git
a/lib/silccrypt/silccipher.c
b/lib/silccrypt/silccipher.c
index bf018c9716f8fb1e05fc5064574c8b725d054972..1832566fec29c45286b3a926c316f63f779746c8 100644
(file)
--- a/
lib/silccrypt/silccipher.c
+++ b/
lib/silccrypt/silccipher.c
@@
-333,9
+333,9
@@
SilcBool silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src,
/* Sets the key for the cipher */
SilcBool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key,
/* 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. */
}
/* Sets the IV (initial vector) for the cipher. */
diff --git
a/lib/silccrypt/silccipher.h
b/lib/silccrypt/silccipher.h
index 51e389f7f7a8f152a3819f44960ebaffc2e4a43f..c020d280414688a7ad0579acb3ef0ac973d5636a 100644
(file)
--- a/
lib/silccrypt/silccipher.h
+++ b/
lib/silccrypt/silccipher.h
@@
-49,7
+49,7
@@
typedef struct SilcCipherStruct *SilcCipher;
/* The default SILC Cipher object to represent any cipher in SILC. */
typedef struct {
char *name;
/* 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 *,
SilcBool (*encrypt)(void *, const unsigned char *, unsigned char *,
SilcUInt32, unsigned char *);
SilcBool (*decrypt)(void *, const unsigned char *, unsigned char *,
@@
-72,7
+72,6
@@
extern DLLAPI const SilcCipherObject silc_default_ciphers[];
/* Default cipher in the SILC protocol */
#define SILC_DEFAULT_CIPHER "aes-256-cbc"
/* 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
/* Macros */
/* Function names in SILC Crypto modules. The name of the cipher
@@
-89,7
+88,8
@@
extern DLLAPI const SilcCipherObject silc_default_ciphers[];
#define SILC_CIPHER_API_SET_KEY(cipher) \
SilcBool silc_##cipher##_set_key(void *context, \
const unsigned char *key, \
#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, \
#define SILC_CIPHER_API_ENCRYPT_CBC(cipher) \
SilcBool silc_##cipher##_encrypt_cbc(void *context, \
const unsigned char *src, \
@@
-102,12
+102,9
@@
SilcBool silc_##cipher##_decrypt_cbc(void *context, \
unsigned char *dst, \
SilcUInt32 len, \
unsigned char *iv)
unsigned char *dst, \
SilcUInt32 len, \
unsigned char *iv)
-
-
#define SILC_CIPHER_API_CONTEXT_LEN(cipher) \
SilcUInt32 silc_##cipher##_context_len()
#define SILC_CIPHER_API_CONTEXT_LEN(cipher) \
SilcUInt32 silc_##cipher##_context_len()
-
/* Prototypes */
/****f* silccrypt/SilcCipherAPI/silc_cipher_register
/* Prototypes */
/****f* silccrypt/SilcCipherAPI/silc_cipher_register
@@
-268,16
+265,17
@@
SilcBool silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src,
* SYNOPSIS
*
* SilcBool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key,
* SYNOPSIS
*
* SilcBool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key,
- *
SilcUInt32 keyle
n);
+ *
SilcUInt32 keylen, SilcBool encryptio
n);
*
* DESCRIPTION
*
* Sets the key for the cipher. The `keylen' is the key length in
*
* 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,
*
***/
SilcBool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key,
- SilcUInt32 keylen);
+ SilcUInt32 keylen
, SilcBool encryption
);
/****f* silccrypt/SilcCipherAPI/silc_cipher_set_iv
*
/****f* silccrypt/SilcCipherAPI/silc_cipher_set_iv
*
@@
-359,4
+357,4
@@
SilcUInt32 silc_cipher_get_iv_len(SilcCipher cipher);
***/
const char *silc_cipher_get_name(SilcCipher cipher);
***/
const char *silc_cipher_get_name(SilcCipher cipher);
-#endif
+#endif
/* SILCCIPHER_H */
diff --git
a/lib/silccrypt/silcpk.c
b/lib/silccrypt/silcpk.c
index b0fd72835fcab0a660545a286e0b0117e8193d2e..7e7c234e72681cd6355c0e6b69aec9e51cf37215 100644
(file)
--- a/
lib/silccrypt/silcpk.c
+++ b/
lib/silccrypt/silcpk.c
@@
-863,7
+863,7
@@
SilcBool silc_pkcs_silc_import_private_key_file(unsigned char *filedata,
silc_hash_final(sha1, keymat + 16);
/* Set the key to the cipher */
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);
/* First, verify the MAC of the private key data */
mac_len = silc_hmac_len(sha1hmac);
@@
-1275,7
+1275,7
@@
silc_pkcs_silc_export_private_key_file(void *private_key,
silc_hash_final(sha1, keymat + 16);
/* Set the key to the cipher */
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. */
/* Encode the buffer to be encrypted. Add padding to it too, at least
block size of the cipher. */
diff --git
a/lib/silcske/silcske.c
b/lib/silcske/silcske.c
index 6f9a568c94ca1b379119501409c8311375bfeb3f..f554e3b0f6becccf430e63864f85b59d43d11df2 100644
(file)
--- a/
lib/silcske/silcske.c
+++ b/
lib/silcske/silcske.c
@@
-2982,12
+2982,12
@@
SilcBool silc_ske_set_keys(SilcSKE ske,
if (ske->responder) {
if (ret_send_key) {
silc_cipher_set_key(*ret_send_key, keymat->receive_enc_key,
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,
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)
silc_cipher_set_iv(*ret_receive_key, keymat->send_iv);
}
if (ret_hmac_send)
@@
-2999,12
+2999,12
@@
SilcBool silc_ske_set_keys(SilcSKE ske,
} else {
if (ret_send_key) {
silc_cipher_set_key(*ret_send_key, keymat->send_enc_key,
} 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,
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)
silc_cipher_set_iv(*ret_receive_key, keymat->receive_iv);
}
if (ret_hmac_send)