Bugzilla – Attachment 1397 Details for
Bug 1340
Support for Camellia block cipher to OpenSSH-portable.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Camellia patch with CTR mode.
openssh.ctr.patch (text/plain), 5.46 KB, created by
Yoshisato YANAGISAWA
on 2007-12-13 22:41:59 AEDT
(
hide
)
Description:
Camellia patch with CTR mode.
Filename:
MIME Type:
Creator:
Yoshisato YANAGISAWA
Created:
2007-12-13 22:41:59 AEDT
Size:
5.46 KB
patch
obsolete
>diff -ruN openssh.bak/cipher-ctr.c openssh/cipher-ctr.c >--- openssh.bak/cipher-ctr.c Thu Jun 14 22:21:33 2007 >+++ openssh/cipher-ctr.c Wed Dec 12 22:12:26 2007 >@@ -42,6 +42,18 @@ > u_char aes_counter[AES_BLOCK_SIZE]; > }; > >+#ifdef USE_CIPHER_CAMELLIA >+#include <openssl/camellia.h> >+const EVP_CIPHER *evp_camellia_128_ctr(void); >+void ssh_camellia_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, u_int); >+ >+struct ssh_camellia_ctr_ctx >+{ >+ CAMELLIA_KEY camellia_ctx; >+ u_char camellia_counter[CAMELLIA_BLOCK_SIZE]; >+}; >+#endif >+ > /* > * increment counter 'ctr', > * the counter is of size 'len' bytes and stored in network-byte-order. >@@ -144,3 +156,94 @@ > #endif > return (&aes_ctr); > } >+ >+#ifdef USE_CIPHER_CAMELLIA >+static int >+ssh_camellia_ctr(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src, >+ u_int len) >+{ >+ struct ssh_camellia_ctr_ctx *c; >+ u_int n = 0; >+ u_char buf[CAMELLIA_BLOCK_SIZE]; >+ >+ if (len == 0) >+ return (1); >+ if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) >+ return (0); >+ >+ while ((len--) > 0) { >+ if (n == 0) { >+ Camellia_encrypt(c->camellia_counter, buf, &c->camellia_ctx); >+ ssh_ctr_inc(c->camellia_counter, CAMELLIA_BLOCK_SIZE); >+ } >+ *(dest++) = *(src++) ^ buf[n]; >+ n = (n + 1) % CAMELLIA_BLOCK_SIZE; >+ } >+ return (1); >+} >+ >+static int >+ssh_camellia_ctr_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv, >+ int enc) >+{ >+ struct ssh_camellia_ctr_ctx *c; >+ >+ if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) { >+ c = xmalloc(sizeof(*c)); >+ EVP_CIPHER_CTX_set_app_data(ctx, c); >+ } >+ if (key != NULL) >+ Camellia_set_key(key, >+ EVP_CIPHER_CTX_key_length(ctx) * 8, >+ &c->camellia_ctx); >+ if (iv != NULL) >+ memcpy(c->camellia_counter, iv, CAMELLIA_BLOCK_SIZE); >+ return (1); >+} >+ >+static int >+ssh_camellia_ctr_cleanup(EVP_CIPHER_CTX *ctx) >+{ >+ struct ssh_camellia_ctr_ctx *c; >+ >+ if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) != NULL) { >+ memset(c, 0, sizeof(*c)); >+ xfree(c); >+ EVP_CIPHER_CTX_set_app_data(ctx, NULL); >+ } >+ return (1); >+} >+ >+void >+ssh_camellia_ctr_iv(EVP_CIPHER_CTX *evp, int doset, u_char * iv, u_int len) >+{ >+ struct ssh_camellia_ctr_ctx *c; >+ >+ if ((c = EVP_CIPHER_CTX_get_app_data(evp)) == NULL) >+ fatal("ssh_camellia_ctr_iv: no context"); >+ if (doset) >+ memcpy(c->camellia_counter, iv, len); >+ else >+ memcpy(iv, c->camellia_counter, len); >+} >+ >+const EVP_CIPHER * >+evp_camellia_128_ctr(void) >+{ >+ static EVP_CIPHER camellia_ctr; >+ >+ memset(&camellia_ctr, 0, sizeof(EVP_CIPHER)); >+ camellia_ctr.nid = NID_undef; >+ camellia_ctr.block_size = CAMELLIA_BLOCK_SIZE; >+ camellia_ctr.iv_len = CAMELLIA_BLOCK_SIZE; >+ camellia_ctr.key_len = 16; >+ camellia_ctr.init = ssh_camellia_ctr_init; >+ camellia_ctr.cleanup = ssh_camellia_ctr_cleanup; >+ camellia_ctr.do_cipher = ssh_camellia_ctr; >+#ifndef SSH_OLD_EVP >+ camellia_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | >+ EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV; >+#endif >+ return (&camellia_ctr); >+} >+#endif >diff -ruN openssh.bak/cipher.c openssh/cipher.c >--- openssh.bak/cipher.c Sat Aug 5 11:39:39 2006 >+++ openssh/cipher.c Wed Dec 12 22:12:22 2007 >@@ -55,6 +55,9 @@ > extern const EVP_CIPHER *evp_ssh1_3des(void); > extern void ssh1_3des_iv(EVP_CIPHER_CTX *, int, u_char *, int); > extern const EVP_CIPHER *evp_aes_128_ctr(void); >+#ifdef USE_CIPHER_CAMELLIA >+extern const EVP_CIPHER *evp_camellia_128_ctr(void); >+#endif > extern void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, u_int); > > struct Cipher { >@@ -87,6 +90,14 @@ > #ifdef USE_CIPHER_ACSS > { "acss@openssh.org", SSH_CIPHER_SSH2, 16, 5, 0, EVP_acss }, > #endif >+#ifdef USE_CIPHER_CAMELLIA >+ { "camellia128-cbc@openssh.org", SSH_CIPHER_SSH2, 16, 16, 0, EVP_camellia_128_cbc }, >+ { "camellia192-cbc@openssh.org", SSH_CIPHER_SSH2, 16, 24, 0, EVP_camellia_192_cbc }, >+ { "camellia256-cbc@openssh.org", SSH_CIPHER_SSH2, 16, 32, 0, EVP_camellia_256_cbc }, >+ { "camellia128-ctr@openssh.org", SSH_CIPHER_SSH2, 16, 16, 0, evp_camellia_128_ctr }, >+ { "camellia192-ctr@openssh.org", SSH_CIPHER_SSH2, 16, 24, 0, evp_camellia_128_ctr }, >+ { "camellia256-ctr@openssh.org", SSH_CIPHER_SSH2, 16, 32, 0, evp_camellia_128_ctr }, >+#endif > { NULL, SSH_CIPHER_INVALID, 0, 0, 0, NULL } > }; > >@@ -346,6 +357,10 @@ > #endif > if (c->evptype == evp_aes_128_ctr) > ssh_aes_ctr_iv(&cc->evp, 0, iv, len); >+#ifdef USE_CIPHER_CAMELLIA >+ else if (c->evptype == evp_camellia_128_ctr) >+ ssh_camellia_ctr_iv(&cc->evp, 0, iv, len); >+#endif > else > memcpy(iv, cc->evp.iv, len); > break; >@@ -377,6 +392,10 @@ > #endif > if (c->evptype == evp_aes_128_ctr) > ssh_aes_ctr_iv(&cc->evp, 1, iv, evplen); >+#ifdef USE_CIPHER_CAMELLIA >+ else if (c->evptype == evp_camellia_128_ctr) >+ ssh_camellia_ctr_iv(&cc->evp, 1, iv, evplen); >+#endif > else > memcpy(cc->evp.iv, iv, evplen); > break; >diff -ruN openssh.bak/configure.ac openssh/configure.ac >--- openssh.bak/configure.ac Mon Dec 10 17:12:07 2007 >+++ openssh/configure.ac Wed Dec 12 22:12:16 2007 >@@ -1979,6 +1979,26 @@ > fi ] > ) > >+# Check for OpenSSL without EVP_camellia_{128,192,256}_cbc >+AC_MSG_CHECKING([whether OpenSSL has Camellia support]) >+AC_LINK_IFELSE( >+ [AC_LANG_SOURCE([[ >+#include <string.h> >+#include <openssl/evp.h> >+int main(void) { exit(EVP_camellia_128_cbc() == NULL >+ || EVP_camellia_192_cbc() == NULL >+ || EVP_camellia_256_cbc() == NULL);} >+ ]])], >+ [ >+ AC_MSG_RESULT(yes) >+ AC_DEFINE(USE_CIPHER_CAMELLIA, 1, >+ [libcrypto has Camellia functions]) >+ ], >+ [ >+ AC_MSG_RESULT(no) >+ ] >+) >+ > # Check for OpenSSL without EVP_aes_{192,256}_cbc > AC_MSG_CHECKING([whether OpenSSL has crippled AES support]) > AC_LINK_IFELSE(
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1340
:
1327
|
1392
|
1397
|
1640
|
1878
|
1879
|
1902