]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8783: [libsrtp] Fix alignment issue
authorSpencer Thomason <spencer@whiteskycommunications.com>
Fri, 22 Jul 2016 14:37:21 +0000 (07:37 -0700)
committerSpencer Thomason <spencer@whiteskycommunications.com>
Fri, 22 Jul 2016 14:37:21 +0000 (07:37 -0700)
Backport upstream alignment fix to correct bus error on platforms
that require strict memory alignment such as SPARC

FS-8783 #resolve

From upstream:
commit 4d8430a504137509f23b5a19f8a06b6df0f651cc
Author: Jaap Keuter <jaap.keuter@xs4all.nl>
Date:   Fri Nov 7 00:13:10 2014 +0100

While setting the IV for AES ICM the nonce is simply typecast from
a void * to a v128_t *. This breaches alignment requirements for
v128_t objects on platforms that require it.
Instead make a copy of the nonce to assure proper alignment.

libs/srtp/crypto/cipher/aes_icm.c
libs/srtp/crypto/cipher/aes_icm_ossl.c

index ef7545f2830cc8615a75b77fdae04e676225f2a7..cda56a8ddc3b0c246c7d80228d95ffb52874ba6e 100644 (file)
@@ -284,12 +284,15 @@ aes_icm_set_octet(aes_icm_ctx_t *c,
 
 err_status_t
 aes_icm_set_iv(aes_icm_ctx_t *c, void *iv, int direction) {
-  v128_t *nonce = (v128_t *) iv;
+  v128_t nonce;
+
+  /* set nonce (for alignment) */
+  v128_copy_octet_string(&nonce, iv);
 
   debug_print(mod_aes_icm, 
-             "setting iv: %s", v128_hex_string(nonce)); 
+             "setting iv: %s", v128_hex_string(&nonce)); 
  
-  v128_xor(&c->counter, &c->offset, nonce);
+  v128_xor(&c->counter, &c->offset, &nonce);
   
   debug_print(mod_aes_icm, 
              "set_counter: %s", v128_hex_string(&c->counter)); 
index 12054a2cc95e0e0d3db513ab10e1d08da55a3300..1e1860d0934f79e0f942f6e5bdf48aa177941a16 100644 (file)
@@ -263,11 +263,14 @@ err_status_t aes_icm_openssl_context_init (aes_icm_ctx_t *c, const uint8_t *key)
 err_status_t aes_icm_openssl_set_iv (aes_icm_ctx_t *c, void *iv, int dir)
 {
     const EVP_CIPHER *evp;
-    v128_t *nonce = (v128_t*)iv;
+    v128_t nonce;
 
-    debug_print(mod_aes_icm, "setting iv: %s", v128_hex_string(nonce));
+    /* set nonce (for alignment) */
+    v128_copy_octet_string(&nonce, iv);
 
-    v128_xor(&c->counter, &c->offset, nonce);
+    debug_print(mod_aes_icm, "setting iv: %s", v128_hex_string(&nonce));
+
+    v128_xor(&c->counter, &c->offset, &nonce);
 
     debug_print(mod_aes_icm, "set_counter: %s", v128_hex_string(&c->counter));