Merge branch 'no_gmt_unix_time' of git://github.com/nmathewson/openssl into OpenSSL_1...
authorBen Laurie <ben@links.org>
Sat, 19 Oct 2013 10:46:32 +0000 (11:46 +0100)
committerBen Laurie <ben@links.org>
Sat, 19 Oct 2013 10:46:32 +0000 (11:46 +0100)
71 files changed:
CHANGES
Configure
NEWS
README
apps/apps.h
apps/openssl.c
apps/pkcs12.c
config
crypto/aes/asm/aes-parisc.pl
crypto/aes/asm/bsaes-x86_64.pl
crypto/armcap.c
crypto/asn1/a_int.c
crypto/bn/asm/mips-mont.pl
crypto/bn/asm/mips.pl
crypto/bn/asm/parisc-mont.pl
crypto/bn/asm/x86_64-gf2m.pl
crypto/bn/bn_nist.c
crypto/buffer/buffer.c
crypto/buffer/buffer.h
crypto/ec/ec_ameth.c
crypto/ec/ec_asn1.c
crypto/ec/ec_lib.c
crypto/evp/e_aes.c
crypto/evp/e_aes_cbc_hmac_sha1.c
crypto/evp/e_des3.c
crypto/modes/asm/ghash-parisc.pl
crypto/modes/cbc128.c
crypto/modes/ccm128.c
crypto/modes/cts128.c
crypto/modes/gcm128.c
crypto/modes/modes_lcl.h
crypto/opensslv.h
crypto/pariscid.pl
crypto/pem/pem_info.c
crypto/pkcs12/p12_crt.c
crypto/rand/rand.h
crypto/rand/rand_err.c
crypto/rand/rand_lib.c
crypto/rc4/asm/rc4-parisc.pl
crypto/rsa/rsa_ameth.c
crypto/rsa/rsa_pmeth.c
crypto/sha/asm/sha1-parisc.pl
crypto/sha/asm/sha1-x86_64.pl
crypto/sha/asm/sha512-mips.pl
crypto/sha/asm/sha512-parisc.pl
crypto/x509/x509_vfy.c
crypto/x509/x_all.c
crypto/x86cpuid.pl
demos/x509/mkreq.c
doc/crypto/X509_STORE_CTX_get_error.pod
doc/crypto/ecdsa.pod
doc/ssl/SSL_CTX_set_client_CA_list.pod
doc/ssl/SSL_CTX_set_options.pod
doc/ssl/SSL_CTX_use_psk_identity_hint.pod
doc/ssl/SSL_accept.pod
doc/ssl/SSL_connect.pod
doc/ssl/SSL_do_handshake.pod
doc/ssl/SSL_shutdown.pod
openssl.spec
ssl/d1_both.c
ssl/d1_lib.c
ssl/d1_pkt.c
ssl/d1_srvr.c
ssl/s3_cbc.c
ssl/s3_lib.c
ssl/ssl.h
ssl/ssl3.h
ssl/ssl_lib.c
ssl/ssltest.c
ssl/t1_lib.c
test/cms-test.pl

diff --git a/CHANGES b/CHANGES
index ca82ad295d5c4b66573692a0835d63aba13052f8..cfaebba26ab67f8962aea1cc4517efb82d104e99 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,9 +2,21 @@
  OpenSSL CHANGES
  _______________
 
+ Changes between 1.0.1e and 1.0.1f [xx XXX xxxx]
+
+  *) Add option SSL_OP_SAFARI_ECDHE_ECDSA_BUG (part of SSL_OP_ALL) which
+     avoids preferring ECDHE-ECDSA ciphers when the client appears to be
+     Safari on OS X.  Safari on OS X 10.8..10.8.3 advertises support for
+     several ECDHE-ECDSA ciphers, but fails to negotiate them.  The bug
+     is fixed in OS X 10.8.4, but Apple have ruled out both hot fixing
+     10.8..10.8.3 and forcing users to upgrade to 10.8.4 or newer.
+     [Rob Stradling, Adam Langley]
+
  Changes between 1.0.1d and 1.0.1e [11 Feb 2013]
 
-  *)
+  *) Correct fix for CVE-2013-0169. The original didn't work on AES-NI
+     supporting platforms or when small records were transferred.
+     [Andy Polyakov, Steve Henson]
 
  Changes between 1.0.1c and 1.0.1d [5 Feb 2013]
 
        Add command line options to s_client/s_server.
      [Steve Henson]
 
+ Changes between 1.0.0j and 1.0.0k [5 Feb 2013]
+
+  *) Make the decoding of SSLv3, TLS and DTLS CBC records constant time.
+
+     This addresses the flaw in CBC record processing discovered by 
+     Nadhem Alfardan and Kenny Paterson. Details of this attack can be found
+     at: http://www.isg.rhul.ac.uk/tls/     
+
+     Thanks go to Nadhem Alfardan and Kenny Paterson of the Information
+     Security Group at Royal Holloway, University of London
+     (www.isg.rhul.ac.uk) for discovering this flaw and Adam Langley and
+     Emilia Käsper for the initial patch.
+     (CVE-2013-0169)
+     [Emilia Käsper, Adam Langley, Ben Laurie, Andy Polyakov, Steve Henson]
+
+  *) Return an error when checking OCSP signatures when key is NULL.
+     This fixes a DoS attack. (CVE-2013-0166)
+     [Steve Henson]
+
+  *) Call OCSP Stapling callback after ciphersuite has been chosen, so
+     the right response is stapled. Also change SSL_get_certificate()
+     so it returns the certificate actually sent.
+     See http://rt.openssl.org/Ticket/Display.html?id=2836.
+     (This is a backport)
+     [Rob Stradling <rob.stradling@comodo.com>]
+
+  *) Fix possible deadlock when decoding public keys.
+     [Steve Henson]
+
+ Changes between 1.0.0i and 1.0.0j [10 May 2012]
+
+  [NB: OpenSSL 1.0.0i and later 1.0.0 patch levels were released after
+  OpenSSL 1.0.1.]
+
+  *) Sanity check record length before skipping explicit IV in DTLS
+     to fix DoS attack.
+
+     Thanks to Codenomicon for discovering this issue using Fuzz-o-Matic
+     fuzzing as a service testing platform.
+     (CVE-2012-2333)
+     [Steve Henson]
+
+  *) Initialise tkeylen properly when encrypting CMS messages.
+     Thanks to Solar Designer of Openwall for reporting this issue.
+     [Steve Henson]
+
+ Changes between 1.0.0h and 1.0.0i [19 Apr 2012]
+
+  *) Check for potentially exploitable overflows in asn1_d2i_read_bio
+     BUF_mem_grow and BUF_mem_grow_clean. Refuse attempts to shrink buffer
+     in CRYPTO_realloc_clean.
+
+     Thanks to Tavis Ormandy, Google Security Team, for discovering this
+     issue and to Adam Langley <agl@chromium.org> for fixing it.
+     (CVE-2012-2110)
+     [Adam Langley (Google), Tavis Ormandy, Google Security Team]
+
  Changes between 1.0.0g and 1.0.0h [12 Mar 2012]
 
   *) Fix MMA (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) weakness
   *) Change 'Configure' script to enable Camellia by default.
      [NTT]
 
+ Changes between 0.9.8x and 0.9.8y [5 Feb 2013]
+
+  *) Make the decoding of SSLv3, TLS and DTLS CBC records constant time.
+
+     This addresses the flaw in CBC record processing discovered by 
+     Nadhem Alfardan and Kenny Paterson. Details of this attack can be found
+     at: http://www.isg.rhul.ac.uk/tls/     
+
+     Thanks go to Nadhem Alfardan and Kenny Paterson of the Information
+     Security Group at Royal Holloway, University of London
+     (www.isg.rhul.ac.uk) for discovering this flaw and Adam Langley and
+     Emilia Käsper for the initial patch.
+     (CVE-2013-0169)
+     [Emilia Käsper, Adam Langley, Ben Laurie, Andy Polyakov, Steve Henson]
+
+  *) Return an error when checking OCSP signatures when key is NULL.
+     This fixes a DoS attack. (CVE-2013-0166)
+     [Steve Henson]
+
+  *) Call OCSP Stapling callback after ciphersuite has been chosen, so
+     the right response is stapled. Also change SSL_get_certificate()
+     so it returns the certificate actually sent.
+     See http://rt.openssl.org/Ticket/Display.html?id=2836.
+     (This is a backport)
+     [Rob Stradling <rob.stradling@comodo.com>]
+
+  *) Fix possible deadlock when decoding public keys.
+     [Steve Henson]
+
+ Changes between 0.9.8w and 0.9.8x [10 May 2012]
+
+  *) Sanity check record length before skipping explicit IV in DTLS
+     to fix DoS attack.
+
+     Thanks to Codenomicon for discovering this issue using Fuzz-o-Matic
+     fuzzing as a service testing platform.
+     (CVE-2012-2333)
+     [Steve Henson]
+
+  *) Initialise tkeylen properly when encrypting CMS messages.
+     Thanks to Solar Designer of Openwall for reporting this issue.
+     [Steve Henson]
+
+ Changes between 0.9.8v and 0.9.8w [23 Apr 2012]
+
+  *) The fix for CVE-2012-2110 did not take into account that the 
+     'len' argument to BUF_MEM_grow and BUF_MEM_grow_clean is an
+     int in OpenSSL 0.9.8, making it still vulnerable. Fix by 
+     rejecting negative len parameter. (CVE-2012-2131)
+     [Tomas Hoger <thoger@redhat.com>]
+
+ Changes between 0.9.8u and 0.9.8v [19 Apr 2012]
+
+  *) Check for potentially exploitable overflows in asn1_d2i_read_bio
+     BUF_mem_grow and BUF_mem_grow_clean. Refuse attempts to shrink buffer
+     in CRYPTO_realloc_clean.
+
+     Thanks to Tavis Ormandy, Google Security Team, for discovering this
+     issue and to Adam Langley <agl@chromium.org> for fixing it.
+     (CVE-2012-2110)
+     [Adam Langley (Google), Tavis Ormandy, Google Security Team]
+
+ Changes between 0.9.8t and 0.9.8u [12 Mar 2012]
+
+  *) Fix MMA (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) weakness
+     in CMS and PKCS7 code. When RSA decryption fails use a random key for
+     content decryption and always return the same error. Note: this attack
+     needs on average 2^20 messages so it only affects automated senders. The
+     old behaviour can be reenabled in the CMS code by setting the
+     CMS_DEBUG_DECRYPT flag: this is useful for debugging and testing where
+     an MMA defence is not necessary.
+     Thanks to Ivan Nestlerode <inestlerode@us.ibm.com> for discovering
+     this issue. (CVE-2012-0884)
+     [Steve Henson]
+
+  *) Fix CVE-2011-4619: make sure we really are receiving a 
+     client hello before rejecting multiple SGC restarts. Thanks to
+     Ivan Nestlerode <inestlerode@us.ibm.com> for discovering this bug.
+     [Steve Henson]
+
  Changes between 0.9.8s and 0.9.8t [18 Jan 2012]
 
   *) Fix for DTLS DoS issue introduced by fix for CVE-2011-4109.
      Development, Cisco Systems, Inc. for discovering this bug and
      preparing a fix. (CVE-2012-0050)
      [Antonio Martin]
-  
+
  Changes between 0.9.8r and 0.9.8s [4 Jan 2012]
 
   *) Nadhem Alfardan and Kenny Paterson have discovered an extension
index 9c803dc0663da83c8dd20e8a2ae6e71f4e5a70b0..daff8e679686ba75086f9b3d935de940ba704ded 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -178,7 +178,7 @@ my %table=(
 "debug-ben-no-opt",    "gcc: -Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -DDEBUG_SAFESTACK -DCRYPTO_MDEBUG -Werror -DL_ENDIAN -DTERMIOS -Wall -g3::(unknown)::::::",
 "debug-ben-strict",    "gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DCONST_STRICT -O2 -Wall -Wshadow -Werror -Wpointer-arith -Wcast-qual -Wwrite-strings -pipe::(unknown)::::::",
 "debug-rse","cc:-DTERMIOS -DL_ENDIAN -pipe -O -g -ggdb3 -Wall::(unknown):::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}",
-"debug-bodo",  "gcc:$gcc_devteam_warn -DBN_DEBUG -DBN_DEBUG_RAND -DCONF_DEBUG -DBIO_PAIR_DEBUG -m64 -DL_ENDIAN -DTERMIO -g -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64",
+"debug-bodo",  "gcc:$gcc_devteam_warn -Wno-error=overlength-strings -DBN_DEBUG -DBN_DEBUG_RAND -DCONF_DEBUG -DBIO_PAIR_DEBUG -m64 -DL_ENDIAN -DTERMIO -g -DMD32_REG_T=int::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64",
 "debug-ulf", "gcc:-DTERMIOS -DL_ENDIAN -march=i486 -Wall -DBN_DEBUG -DBN_DEBUG_RAND -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DOPENSSL_NO_ASM -g -Wformat -Wshadow -Wmissing-prototypes -Wmissing-declarations:::CYGWIN32:::${no_asm}:win32:cygwin-shared:::.dll",
 "debug-steve64", "gcc:$gcc_devteam_warn -m64 -DL_ENDIAN -DTERMIO -DCONF_DEBUG -DDEBUG_SAFESTACK -Wno-overlength-strings -g::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
 "debug-steve32", "gcc:$gcc_devteam_warn -m32 -DL_ENDIAN -DCONF_DEBUG -DDEBUG_SAFESTACK -g -pipe::-D_REENTRANT::-rdynamic -ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:linux-shared:-fPIC:-m32:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
diff --git a/NEWS b/NEWS
index 0269f2277fce22314428197e051cad23e722a227..2d1dd133e6ec3a524dd4504529b0f3c2c68024dc 100644 (file)
--- a/NEWS
+++ b/NEWS
       o Preliminary FIPS capability for unvalidated 2.0 FIPS module.
       o SRP support.
 
+  Major changes between OpenSSL 1.0.0j and OpenSSL 1.0.0k:
+
+      o Fix for SSL/TLS/DTLS CBC plaintext recovery attack CVE-2013-0169
+      o Fix OCSP bad key DoS attack CVE-2013-0166
+
+  Major changes between OpenSSL 1.0.0i and OpenSSL 1.0.0j:
+
+      o Fix DTLS record length checking bug CVE-2012-2333
+
+  Major changes between OpenSSL 1.0.0h and OpenSSL 1.0.0i:
+
+      o Fix for ASN1 overflow bug CVE-2012-2110
+
   Major changes between OpenSSL 1.0.0g and OpenSSL 1.0.0h:
 
       o Fix for CMS/PKCS#7 MMA CVE-2012-0884
       o Opaque PRF Input TLS extension support.
       o Updated time routines to avoid OS limitations.
 
+  Major changes between OpenSSL 0.9.8x and OpenSSL 0.9.8y:
+
+      o Fix for SSL/TLS/DTLS CBC plaintext recovery attack CVE-2013-0169
+      o Fix OCSP bad key DoS attack CVE-2013-0166
+
+  Major changes between OpenSSL 0.9.8w and OpenSSL 0.9.8x:
+
+      o Fix DTLS record length checking bug CVE-2012-2333
+
+  Major changes between OpenSSL 0.9.8v and OpenSSL 0.9.8w:
+
+      o Fix for CVE-2012-2131 (corrected fix for 0.9.8 and CVE-2012-2110)
+
+  Major changes between OpenSSL 0.9.8u and OpenSSL 0.9.8v:
+
+      o Fix for ASN1 overflow bug CVE-2012-2110
+
+  Major changes between OpenSSL 0.9.8t and OpenSSL 0.9.8u:
+
+      o Fix for CMS/PKCS#7 MMA CVE-2012-0884
+      o Corrected fix for CVE-2011-4619
+      o Various DTLS fixes.
+
+  Major changes between OpenSSL 0.9.8s and OpenSSL 0.9.8t:
+
+      o Fix for DTLS DoS issue CVE-2012-0050
+
+  Major changes between OpenSSL 0.9.8r and OpenSSL 0.9.8s:
+
+      o Fix for DTLS plaintext recovery attack CVE-2011-4108
+      o Fix policy check double free error CVE-2011-4109
+      o Clear block padding bytes of SSL 3.0 records CVE-2011-4576
+      o Only allow one SGC handshake restart for SSL/TLS CVE-2011-4619
+      o Check for malformed RFC3779 data CVE-2011-4577
+
   Major changes between OpenSSL 0.9.8q and OpenSSL 0.9.8r:
 
       o Fix for security issue CVE-2011-0014
diff --git a/README b/README
index ad2d90f0d1ddad003c3d5be6894bdbf436ec9973..ac0c464023486503bf542fcd042c74693dad37c1 100644 (file)
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
 
- OpenSSL 1.0.1e 11 Feb 2013
+ OpenSSL 1.0.1f-dev
 
  Copyright (c) 1998-2011 The OpenSSL Project
  Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson
index c1ca99da12e8bfa75bdd71c2ceaee5311c4e5e2e..3aeb46c4e299d8dadfb08394fd8d60ce8bac66eb 100644 (file)
@@ -188,6 +188,7 @@ extern BIO *bio_err;
                        do { CONF_modules_unload(1); destroy_ui_method(); \
                        OBJ_cleanup(); EVP_cleanup(); ENGINE_cleanup(); \
                        CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
+                       RAND_cleanup(); \
                        ERR_free_strings(); zlib_cleanup();} while(0)
 #  else
 #    define apps_startup() \
@@ -198,6 +199,7 @@ extern BIO *bio_err;
                        do { CONF_modules_unload(1); destroy_ui_method(); \
                        OBJ_cleanup(); EVP_cleanup(); \
                        CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
+                       RAND_cleanup(); \
                        ERR_free_strings(); zlib_cleanup(); } while(0)
 #  endif
 #endif
index 1c880d90ba1d142416ca8d1cbd16668be0a8aec8..71e1e48ece40579234bf4578c2d2b02b6fc40b3c 100644 (file)
 #include "apps.h"
 #include <openssl/bio.h>
 #include <openssl/crypto.h>
+#include <openssl/rand.h>
 #include <openssl/lhash.h>
 #include <openssl/conf.h>
 #include <openssl/x509.h>
index b54c6f84a4a095d4fcc93c90a3adb19abf9f1a5e..4d62a7b8cabd3e30465c637ad29707dd50d3cec7 100644 (file)
@@ -112,7 +112,7 @@ int MAIN(int argc, char **argv)
     int maciter = PKCS12_DEFAULT_ITER;
     int twopass = 0;
     int keytype = 0;
-    int cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;
+    int cert_pbe;
     int key_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
     int ret = 1;
     int macver = 1;
@@ -130,6 +130,13 @@ int MAIN(int argc, char **argv)
 
     apps_startup();
 
+#ifdef OPENSSL_FIPS
+    if (FIPS_mode())
+       cert_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
+    else
+#endif
+    cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;
+
     enc = EVP_des_ede3_cbc();
     if (bio_err == NULL ) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
 
diff --git a/config b/config
index 88b9bc69da4c71ba6056e0e904a19bd14f5a0101..41fa2a6b8296d9b6b4cccfd2fd34494b7d0634f6 100755 (executable)
--- a/config
+++ b/config
@@ -739,7 +739,7 @@ case "$GUESSOS" in
                            libc=/usr/lib/libc.so
                        else                                    # OpenBSD
                            # ld searches for highest libc.so.* and so do we
-                           libc=`(ls /usr/lib/libc.so.* | tail -1) 2>/dev/null`
+                           libc=`(ls /usr/lib/libc.so.* /lib/libc.so.* | tail -1) 2>/dev/null`
                        fi
                        case "`(file -L $libc) 2>/dev/null`" in
                        *ELF*)  OUT="BSD-x86-elf" ;;
index c36b6a22705cfa67fcd9f3b8e81e390a85bc2dda..714dcfbbe3b72ff3b629fc60083d37e9314ab664 100644 (file)
@@ -1015,7 +1015,8 @@ foreach (split("\n",$code)) {
                $SIZE_T==4 ? sprintf("extru%s,%d,8,",$1,31-$2)
                :            sprintf("extrd,u%s,%d,8,",$1,63-$2)/e;
 
-       s/,\*/,/ if ($SIZE_T==4);
+       s/,\*/,/                        if ($SIZE_T==4);
+       s/\bbv\b(.*\(%r2\))/bve$1/      if ($SIZE_T==8);
        print $_,"\n";
 }
 close STDOUT;
index ceb02b50ddb60d283345b27ad8a5a3d4a3b92534..41b90f08443f512bb0079910720936afff275fc7 100644 (file)
@@ -83,9 +83,9 @@
 # Add decryption procedure. Performance in CPU cycles spent to decrypt
 # one byte out of 4096-byte buffer with 128-bit key is:
 #
-# Core 2       11.0
-# Nehalem      9.16
-# Atom         20.9
+# Core 2       9.83
+# Nehalem      7.74
+# Atom         19.0
 #
 # November 2011.
 #
@@ -456,6 +456,7 @@ sub MixColumns {
 # modified to emit output in order suitable for feeding back to aesenc[last]
 my @x=@_[0..7];
 my @t=@_[8..15];
+my $inv=@_[16];        # optional
 $code.=<<___;
        pshufd  \$0x93, @x[0], @t[0]    # x0 <<< 32
        pshufd  \$0x93, @x[1], @t[1]
@@ -497,7 +498,8 @@ $code.=<<___;
        pxor    @t[4], @t[0]
         pshufd \$0x4E, @x[2], @x[6]
        pxor    @t[5], @t[1]
-
+___
+$code.=<<___ if (!$inv);
        pxor    @t[3], @x[4]
        pxor    @t[7], @x[5]
        pxor    @t[6], @x[3]
@@ -505,9 +507,20 @@ $code.=<<___;
        pxor    @t[2], @x[6]
         movdqa @t[1], @x[7]
 ___
+$code.=<<___ if ($inv);
+       pxor    @x[4], @t[3]
+       pxor    @t[7], @x[5]
+       pxor    @x[3], @t[6]
+        movdqa @t[0], @x[3]
+       pxor    @t[2], @x[6]
+        movdqa @t[6], @x[2]
+        movdqa @t[1], @x[7]
+        movdqa @x[6], @x[4]
+        movdqa @t[3], @x[6]
+___
 }
 
-sub InvMixColumns {
+sub InvMixColumns_orig {
 my @x=@_[0..7];
 my @t=@_[8..15];
 
@@ -661,6 +674,54 @@ $code.=<<___;
 ___
 }
 
+sub InvMixColumns {
+my @x=@_[0..7];
+my @t=@_[8..15];
+
+# Thanks to Jussi Kivilinna for providing pointer to
+#
+# | 0e 0b 0d 09 |   | 02 03 01 01 |   | 05 00 04 00 |
+# | 09 0e 0b 0d | = | 01 02 03 01 | x | 00 05 00 04 |
+# | 0d 09 0e 0b |   | 01 01 02 03 |   | 04 00 05 00 |
+# | 0b 0d 09 0e |   | 03 01 01 02 |   | 00 04 00 05 |
+
+$code.=<<___;
+       # multiplication by 0x05-0x00-0x04-0x00
+       pshufd  \$0x4E, @x[0], @t[0]
+       pshufd  \$0x4E, @x[6], @t[6]
+       pxor    @x[0], @t[0]
+       pshufd  \$0x4E, @x[7], @t[7]
+       pxor    @x[6], @t[6]
+       pshufd  \$0x4E, @x[1], @t[1]
+       pxor    @x[7], @t[7]
+       pshufd  \$0x4E, @x[2], @t[2]
+       pxor    @x[1], @t[1]
+       pshufd  \$0x4E, @x[3], @t[3]
+       pxor    @x[2], @t[2]
+        pxor   @t[6], @x[0]
+        pxor   @t[6], @x[1]
+       pshufd  \$0x4E, @x[4], @t[4]
+       pxor    @x[3], @t[3]
+        pxor   @t[0], @x[2]
+        pxor   @t[1], @x[3]
+       pshufd  \$0x4E, @x[5], @t[5]
+       pxor    @x[4], @t[4]
+        pxor   @t[7], @x[1]
+        pxor   @t[2], @x[4]
+       pxor    @x[5], @t[5]
+
+        pxor   @t[7], @x[2]
+        pxor   @t[6], @x[3]
+        pxor   @t[6], @x[4]
+        pxor   @t[3], @x[5]
+        pxor   @t[4], @x[6]
+        pxor   @t[7], @x[4]
+        pxor   @t[7], @x[5]
+        pxor   @t[5], @x[7]
+___
+       &MixColumns     (@x,@t,1);      # flipped 2<->3 and 4<->6
+}
+
 sub aesenc {                           # not used
 my @b=@_[0..7];
 my @t=@_[8..15];
@@ -2028,6 +2089,8 @@ ___
 #      const unsigned char iv[16]);
 #
 my ($twmask,$twres,$twtmp)=@XMM[13..15];
+$arg6=~s/d$//;
+
 $code.=<<___;
 .globl bsaes_xts_encrypt
 .type  bsaes_xts_encrypt,\@abi-omnipotent
index 5258d2fbddfa36be538f869a6fc9cd6c8f9209c7..9abaf396e53e4f5f02a05639d66ccdd9cc023495 100644 (file)
@@ -23,7 +23,7 @@ unsigned int _armv7_tick(void);
 
 unsigned int OPENSSL_rdtsc(void)
        {
-       if (OPENSSL_armcap_P|ARMV7_TICK)
+       if (OPENSSL_armcap_P & ARMV7_TICK)
                return _armv7_tick();
        else
                return 0;
index ad0d2506f63203679814cd36018f1dc9c4221b91..297c45a9ff12ebb54df717bd7c1f8487579daad4 100644 (file)
@@ -116,7 +116,7 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
        int pad=0,ret,i,neg;
        unsigned char *p,*n,pb=0;
 
-       if ((a == NULL) || (a->data == NULL)) return(0);
+       if (a == NULL) return(0);
        neg=a->type & V_ASN1_NEG;
        if (a->length == 0)
                ret=1;
index b944a12b8e29d1f12c32068bb128ce2b64752353..caae04ed3a8644190740ae653c847b986bb4f7c9 100644 (file)
@@ -133,7 +133,7 @@ $code.=<<___;
        bnez    $at,1f
        li      $t0,0
        slt     $at,$num,17     # on in-order CPU
-       bnezl   $at,bn_mul_mont_internal
+       bnez    $at,bn_mul_mont_internal
        nop
 1:     jr      $ra
        li      $a0,0
index 38b51645f067eb0d4a83d5d1277631eb575330ea..d2f3ef7bbf2cac96fd022003b4076096300c2f16 100644 (file)
@@ -140,10 +140,10 @@ $code.=<<___;
        .set    reorder
        li      $minus4,-4
        and     $ta0,$a2,$minus4
-       $LD     $t0,0($a1)
        beqz    $ta0,.L_bn_mul_add_words_tail
 
 .L_bn_mul_add_words_loop:
+       $LD     $t0,0($a1)
        $MULTU  $t0,$a3
        $LD     $t1,0($a0)
        $LD     $t2,$BNSZ($a1)
@@ -200,10 +200,9 @@ $code.=<<___;
        $ADDU   $v0,$ta2
        sltu    $at,$ta3,$at
        $ST     $ta3,-$BNSZ($a0)
-       $ADDU   $v0,$at
        .set    noreorder
-       bgtzl   $ta0,.L_bn_mul_add_words_loop
-       $LD     $t0,0($a1)
+       bgtz    $ta0,.L_bn_mul_add_words_loop
+       $ADDU   $v0,$at
 
        beqz    $a2,.L_bn_mul_add_words_return
        nop
@@ -300,10 +299,10 @@ $code.=<<___;
        .set    reorder
        li      $minus4,-4
        and     $ta0,$a2,$minus4
-       $LD     $t0,0($a1)
        beqz    $ta0,.L_bn_mul_words_tail
 
 .L_bn_mul_words_loop:
+       $LD     $t0,0($a1)
        $MULTU  $t0,$a3
        $LD     $t2,$BNSZ($a1)
        $LD     $ta0,2*$BNSZ($a1)
@@ -341,10 +340,9 @@ $code.=<<___;
        $ADDU   $v0,$at
        sltu    $ta3,$v0,$at
        $ST     $v0,-$BNSZ($a0)
-       $ADDU   $v0,$ta3,$ta2
        .set    noreorder
-       bgtzl   $ta0,.L_bn_mul_words_loop
-       $LD     $t0,0($a1)
+       bgtz    $ta0,.L_bn_mul_words_loop
+       $ADDU   $v0,$ta3,$ta2
 
        beqz    $a2,.L_bn_mul_words_return
        nop
@@ -429,10 +427,10 @@ $code.=<<___;
        .set    reorder
        li      $minus4,-4
        and     $ta0,$a2,$minus4
-       $LD     $t0,0($a1)
        beqz    $ta0,.L_bn_sqr_words_tail
 
 .L_bn_sqr_words_loop:
+       $LD     $t0,0($a1)
        $MULTU  $t0,$t0
        $LD     $t2,$BNSZ($a1)
        $LD     $ta0,2*$BNSZ($a1)
@@ -463,11 +461,10 @@ $code.=<<___;
        mflo    $ta3
        mfhi    $ta2
        $ST     $ta3,-2*$BNSZ($a0)
-       $ST     $ta2,-$BNSZ($a0)
 
        .set    noreorder
-       bgtzl   $ta0,.L_bn_sqr_words_loop
-       $LD     $t0,0($a1)
+       bgtz    $ta0,.L_bn_sqr_words_loop
+       $ST     $ta2,-$BNSZ($a0)
 
        beqz    $a2,.L_bn_sqr_words_return
        nop
@@ -547,10 +544,10 @@ $code.=<<___;
        .set    reorder
        li      $minus4,-4
        and     $at,$a3,$minus4
-       $LD     $t0,0($a1)
        beqz    $at,.L_bn_add_words_tail
 
 .L_bn_add_words_loop:
+       $LD     $t0,0($a1)
        $LD     $ta0,0($a2)
        subu    $a3,4
        $LD     $t1,$BNSZ($a1)
@@ -589,11 +586,10 @@ $code.=<<___;
        $ADDU   $t3,$ta3,$v0
        sltu    $v0,$t3,$ta3
        $ST     $t3,-$BNSZ($a0)
-       $ADDU   $v0,$t9
        
        .set    noreorder
-       bgtzl   $at,.L_bn_add_words_loop
-       $LD     $t0,0($a1)
+       bgtz    $at,.L_bn_add_words_loop
+       $ADDU   $v0,$t9
 
        beqz    $a3,.L_bn_add_words_return
        nop
@@ -679,10 +675,10 @@ $code.=<<___;
        .set    reorder
        li      $minus4,-4
        and     $at,$a3,$minus4
-       $LD     $t0,0($a1)
        beqz    $at,.L_bn_sub_words_tail
 
 .L_bn_sub_words_loop:
+       $LD     $t0,0($a1)
        $LD     $ta0,0($a2)
        subu    $a3,4
        $LD     $t1,$BNSZ($a1)
@@ -722,11 +718,10 @@ $code.=<<___;
        $SUBU   $t3,$ta3,$v0
        sgtu    $v0,$t3,$ta3
        $ST     $t3,-$BNSZ($a0)
-       $ADDU   $v0,$t9
 
        .set    noreorder
-       bgtzl   $at,.L_bn_sub_words_loop
-       $LD     $t0,0($a1)
+       bgtz    $at,.L_bn_sub_words_loop
+       $ADDU   $v0,$t9
 
        beqz    $a3,.L_bn_sub_words_return
        nop
@@ -840,8 +835,9 @@ $code.=<<___;
        sltu    $ta0,$a1,$a2
        or      $t8,$ta0
        .set    noreorder
-       beqzl   $at,.L_bn_div_3_words_inner_loop
+       beqz    $at,.L_bn_div_3_words_inner_loop
        $SUBU   $v0,1
+       $ADDU   $v0,1
        .set    reorder
 .L_bn_div_3_words_inner_loop_done:
        .set    noreorder
@@ -902,7 +898,8 @@ $code.=<<___;
        and     $t2,$a0
        $SRL    $at,$a1,$t1
        .set    noreorder
-       bnezl   $t2,.+8
+       beqz    $t2,.+12
+       nop
        break   6               # signal overflow
        .set    reorder
        $SLL    $a0,$t9
@@ -917,7 +914,8 @@ $code.=<<___;
        $SRL    $DH,$a2,4*$BNSZ # bits
        sgeu    $at,$a0,$a2
        .set    noreorder
-       bnezl   $at,.+8
+       beqz    $at,.+12
+       nop
        $SUBU   $a0,$a2
        .set    reorder
 
index 4a766a87fb2e225113843d8f265e93366c7864e1..c02ef6f014668324649265efc84709312158ad3f 100644 (file)
@@ -40,7 +40,7 @@
 # of arithmetic operations, most notably multiplications. It requires
 # more memory references, most notably to tp[num], but this doesn't
 # seem to exhaust memory port capacity. And indeed, dedicated PA-RISC
-# 2.0 code path, provides virtually same performance as pa-risc2[W].s:
+# 2.0 code path provides virtually same performance as pa-risc2[W].s:
 # it's ~10% better for shortest key length and ~10% worse for longest
 # one.
 #
@@ -988,6 +988,8 @@ foreach (split("\n",$code)) {
        # assemble 2.0 instructions in 32-bit mode...
        s/^\s+([a-z]+)([\S]*)\s+([\S]*)/&assemble($1,$2,$3)/e if ($BN_SZ==4);
 
+       s/\bbv\b/bve/gm if ($SIZE_T==8);
+
        print $_,"\n";
 }
 close STDOUT;
index a30d4ef02958fc900504fc555f998b26dc67fb06..226c66c35e35570715d8f7cc41215ef4e6c42a05 100644 (file)
@@ -31,7 +31,8 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
 ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
 die "can't locate x86_64-xlate.pl";
 
-open STDOUT,"| \"$^X\" $xlate $flavour $output";
+open OUT,"| \"$^X\" $xlate $flavour $output";
+*STDOUT=*OUT;
 
 ($lo,$hi)=("%rax","%rdx");     $a=$lo;
 ($i0,$i1)=("%rsi","%rdi");
index 43caee477031e1316571b51aa9d39b96ff02857d..e22968d4a33bd3ad5a77609a1608abc41baf7548 100644 (file)
@@ -286,26 +286,25 @@ const BIGNUM *BN_get0_nist_prime_521(void)
        }
 
 
-static void nist_cp_bn_0(BN_ULONG *buf, BN_ULONG *a, int top, int max)
+static void nist_cp_bn_0(BN_ULONG *dst, const BN_ULONG *src, int top, int max)
        {
        int i;
-       BN_ULONG *_tmp1 = (buf), *_tmp2 = (a);
 
 #ifdef BN_DEBUG
        OPENSSL_assert(top <= max);
 #endif
-       for (i = (top); i != 0; i--)
-               *_tmp1++ = *_tmp2++;
-       for (i = (max) - (top); i != 0; i--)
-               *_tmp1++ = (BN_ULONG) 0;
+       for (i = 0; i < top; i++)
+               dst[i] = src[i];
+       for (; i < max; i++)
+               dst[i] = 0;
        }
 
-static void nist_cp_bn(BN_ULONG *buf, BN_ULONG *a, int top)
+static void nist_cp_bn(BN_ULONG *dst, const BN_ULONG *src, int top)
        { 
        int i;
-       BN_ULONG *_tmp1 = (buf), *_tmp2 = (a);
-       for (i = (top); i != 0; i--)
-               *_tmp1++ = *_tmp2++;
+
+       for (i = 0; i < top; i++)
+               dst[i] = src[i];
        }
 
 #if BN_BITS2 == 64
@@ -451,8 +450,9 @@ int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
         */
        mask  = 0-(PTR_SIZE_INT)bn_sub_words(c_d,r_d,_nist_p_192[0],BN_NIST_192_TOP);
        mask &= 0-(PTR_SIZE_INT)carry;
+       res   = c_d;
        res   = (BN_ULONG *)
-        (((PTR_SIZE_INT)c_d&~mask) | ((PTR_SIZE_INT)r_d&mask));
+        (((PTR_SIZE_INT)res&~mask) | ((PTR_SIZE_INT)r_d&mask));
        nist_cp_bn(r_d, res, BN_NIST_192_TOP);
        r->top = BN_NIST_192_TOP;
        bn_correct_top(r);
@@ -479,8 +479,11 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        int     top = a->top, i;
        int     carry;
        BN_ULONG *r_d, *a_d = a->d;
-       BN_ULONG buf[BN_NIST_224_TOP],
-                c_d[BN_NIST_224_TOP],
+       union   {
+               BN_ULONG        bn[BN_NIST_224_TOP];
+               unsigned int    ui[BN_NIST_224_TOP*sizeof(BN_ULONG)/sizeof(unsigned int)];
+               } buf;
+       BN_ULONG c_d[BN_NIST_224_TOP],
                *res;
        PTR_SIZE_INT mask;
        union { bn_addsub_f f; PTR_SIZE_INT p; } u;
@@ -519,18 +522,18 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        /* copy upper 256 bits of 448 bit number ... */
        nist_cp_bn_0(c_d, a_d + (BN_NIST_224_TOP-1), top - (BN_NIST_224_TOP-1), BN_NIST_224_TOP);
        /* ... and right shift by 32 to obtain upper 224 bits */
-       nist_set_224(buf, c_d, 14, 13, 12, 11, 10, 9, 8);
+       nist_set_224(buf.bn, c_d, 14, 13, 12, 11, 10, 9, 8);
        /* truncate lower part to 224 bits too */
        r_d[BN_NIST_224_TOP-1] &= BN_MASK2l;
 #else
-       nist_cp_bn_0(buf, a_d + BN_NIST_224_TOP, top - BN_NIST_224_TOP, BN_NIST_224_TOP);
+       nist_cp_bn_0(buf.bn, a_d + BN_NIST_224_TOP, top - BN_NIST_224_TOP, BN_NIST_224_TOP);
 #endif
 
 #if defined(NIST_INT64) && BN_BITS2!=64
        {
        NIST_INT64              acc;    /* accumulator */
        unsigned int            *rp=(unsigned int *)r_d;
-       const unsigned int      *bp=(const unsigned int *)buf;
+       const unsigned int      *bp=(const unsigned int *)buf.ui;
 
        acc  = rp[0];   acc -= bp[7-7];
                        acc -= bp[11-7]; rp[0] = (unsigned int)acc; acc >>= 32;
@@ -565,13 +568,13 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        {
        BN_ULONG t_d[BN_NIST_224_TOP];
 
-       nist_set_224(t_d, buf, 10, 9, 8, 7, 0, 0, 0);
+       nist_set_224(t_d, buf.bn, 10, 9, 8, 7, 0, 0, 0);
        carry = (int)bn_add_words(r_d, r_d, t_d, BN_NIST_224_TOP);
-       nist_set_224(t_d, buf, 0, 13, 12, 11, 0, 0, 0);
+       nist_set_224(t_d, buf.bn, 0, 13, 12, 11, 0, 0, 0);
        carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_224_TOP);
-       nist_set_224(t_d, buf, 13, 12, 11, 10, 9, 8, 7);
+       nist_set_224(t_d, buf.bn, 13, 12, 11, 10, 9, 8, 7);
        carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_224_TOP);
-       nist_set_224(t_d, buf, 0, 0, 0, 0, 13, 12, 11);
+       nist_set_224(t_d, buf.bn, 0, 0, 0, 0, 13, 12, 11);
        carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_224_TOP);
 
 #if BN_BITS2==64
@@ -606,7 +609,8 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        /* otherwise it's effectively same as in BN_nist_mod_192... */
        mask  = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_224[0],BN_NIST_224_TOP);
        mask &= 0-(PTR_SIZE_INT)carry;
-       res   = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) |
+       res   = c_d;
+       res   = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) |
         ((PTR_SIZE_INT)r_d&mask));
        nist_cp_bn(r_d, res, BN_NIST_224_TOP);
        r->top = BN_NIST_224_TOP;
@@ -805,7 +809,8 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
 
        mask  = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_256[0],BN_NIST_256_TOP);
        mask &= 0-(PTR_SIZE_INT)carry;
-       res   = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) |
+       res   = c_d;
+       res   = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) |
         ((PTR_SIZE_INT)r_d&mask));
        nist_cp_bn(r_d, res, BN_NIST_256_TOP);
        r->top = BN_NIST_256_TOP;
@@ -1026,7 +1031,8 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
 
        mask  = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP);
        mask &= 0-(PTR_SIZE_INT)carry;
-       res   = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) |
+       res   = c_d;
+       res   = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) |
         ((PTR_SIZE_INT)r_d&mask));
        nist_cp_bn(r_d, res, BN_NIST_384_TOP);
        r->top = BN_NIST_384_TOP;
@@ -1092,7 +1098,8 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
 
        bn_add_words(r_d,r_d,t_d,BN_NIST_521_TOP);
        mask = 0-(PTR_SIZE_INT)bn_sub_words(t_d,r_d,_nist_p_521,BN_NIST_521_TOP);
-       res  = (BN_ULONG *)(((PTR_SIZE_INT)t_d&~mask) |
+       res  = t_d;
+       res  = (BN_ULONG *)(((PTR_SIZE_INT)res&~mask) |
         ((PTR_SIZE_INT)r_d&mask));
        nist_cp_bn(r_d,res,BN_NIST_521_TOP);
        r->top = BN_NIST_521_TOP;
index d7aa79ad7f0a24320c4f34bccba191bbaae34e44..d4a4ce43b3f2070e2c524a2497040e47d1054433 100644 (file)
@@ -179,14 +179,14 @@ int BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
        return(len);
        }
 
-void BUF_reverse(unsigned char *out, unsigned char *in, size_t size)
+void BUF_reverse(unsigned char *out, const unsigned char *in, size_t size)
        {
        size_t i;
        if (in)
                {
                out += size - 1;
                for (i = 0; i < size; i++)
-                       *in++ = *out--;
+                       *out-- = *in++;
                }
        else
                {
index 178e418282b2eb74ca575f61db678a393a151562..f8da32b485074b44e6bb5c0b36ce9e5d1aca2b92 100644 (file)
@@ -88,7 +88,7 @@ int   BUF_MEM_grow_clean(BUF_MEM *str, size_t len);
 char * BUF_strdup(const char *str);
 char * BUF_strndup(const char *str, size_t siz);
 void * BUF_memdup(const void *data, size_t siz);
-void   BUF_reverse(unsigned char *out, unsigned char *in, size_t siz);
+void   BUF_reverse(unsigned char *out, const unsigned char *in, size_t siz);
 
 /* safe string functions */
 size_t BUF_strlcpy(char *dst,const char *src,size_t siz);
index 83909c185359a73046952b2ad9ac38991211b2e7..0ce4524076f138b9986432a901ee7fc4f8124cc5 100644 (file)
@@ -88,7 +88,7 @@ static int eckey_param2type(int *pptype, void **ppval, EC_KEY *ec_key)
                if (!pstr)
                        return 0;
                pstr->length = i2d_ECParameters(ec_key, &pstr->data);
-               if (pstr->length < 0)
+               if (pstr->length <= 0)
                        {
                        ASN1_STRING_free(pstr);
                        ECerr(EC_F_ECKEY_PARAM2TYPE, ERR_R_EC_LIB);
index 175eec53428baa0e51a1817294b3a6dd7ee7e128..145807b611a5aa9efa6b782b2c543d95b8fe3387 100644 (file)
@@ -89,7 +89,8 @@ int EC_GROUP_get_trinomial_basis(const EC_GROUP *group, unsigned int *k)
        if (group == NULL)
                return 0;
 
-       if (EC_GROUP_method_of(group)->group_set_curve != ec_GF2m_simple_group_set_curve
+       if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
+           NID_X9_62_characteristic_two_field
            || !((group->poly[0] != 0) && (group->poly[1] != 0) && (group->poly[2] == 0)))
                {
                ECerr(EC_F_EC_GROUP_GET_TRINOMIAL_BASIS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
@@ -107,7 +108,8 @@ int EC_GROUP_get_pentanomial_basis(const EC_GROUP *group, unsigned int *k1,
        if (group == NULL)
                return 0;
 
-       if (EC_GROUP_method_of(group)->group_set_curve != ec_GF2m_simple_group_set_curve
+       if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
+           NID_X9_62_characteristic_two_field
            || !((group->poly[0] != 0) && (group->poly[1] != 0) && (group->poly[2] != 0) && (group->poly[3] != 0) && (group->poly[4] == 0)))
                {
                ECerr(EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
index 25247b580332fe67cabea5cf668118154131bba8..de9a0cc2b37eec632820acba97ae6b23dbae7b52 100644 (file)
@@ -480,10 +480,10 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx)
        if (EC_METHOD_get_field_type(EC_GROUP_method_of(a)) !=
            EC_METHOD_get_field_type(EC_GROUP_method_of(b)))
                return 1;
-       /* compare the curve name (if present) */
+       /* compare the curve name (if present in both) */
        if (EC_GROUP_get_curve_name(a) && EC_GROUP_get_curve_name(b) &&
-           EC_GROUP_get_curve_name(a) == EC_GROUP_get_curve_name(b))
-               return 0;
+           EC_GROUP_get_curve_name(a) != EC_GROUP_get_curve_name(b))
+               return 1;
 
        if (!ctx)
                ctx_new = ctx = BN_CTX_new();
@@ -993,12 +993,12 @@ int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN
        if (group->meth->point_cmp == 0)
                {
                ECerr(EC_F_EC_POINT_CMP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
-               return 0;
+               return -1;
                }
        if ((group->meth != a->meth) || (a->meth != b->meth))
                {
                ECerr(EC_F_EC_POINT_CMP, EC_R_INCOMPATIBLE_OBJECTS);
-               return 0;
+               return -1;
                }
        return group->meth->point_cmp(group, a, b, ctx);
        }
index 1bfb5d92b340172c8e97ec8d391b9d3e757b60a7..c7869b69efe2f4739df7533059efe4a621f560f1 100644 (file)
@@ -842,7 +842,10 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
                        gctx->ctr = NULL;
                        break;
                        }
+               else
 #endif
+               (void)0;        /* terminate potentially open 'else' */
+
                AES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);
                CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks, (block128_f)AES_encrypt);
 #ifdef AES_CTR_ASM
@@ -1083,14 +1086,17 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
                        xctx->xts.block1 = (block128_f)vpaes_decrypt;
                        }
 
-               vpaes_set_encrypt_key(key + ctx->key_len/2,
+                   vpaes_set_encrypt_key(key + ctx->key_len/2,
                                                ctx->key_len * 4, &xctx->ks2);
-               xctx->xts.block2 = (block128_f)vpaes_encrypt;
+                   xctx->xts.block2 = (block128_f)vpaes_encrypt;
 
-               xctx->xts.key1 = &xctx->ks1;
-               break;
-               }
+                   xctx->xts.key1 = &xctx->ks1;
+                   break;
+                   }
+               else
 #endif
+               (void)0;        /* terminate potentially open 'else' */
+
                if (enc)
                        {
                        AES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);
index 483e04b605b79aab6c521dcaa93500e4a39a67b4..fb2c884a7860178c49ca71b01c1c7f74fde11607 100644 (file)
@@ -328,10 +328,11 @@ static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 
                                if (res!=SHA_CBLOCK) continue;
 
-                               mask = 0-((inp_len+8-j)>>(sizeof(j)*8-1));
+                               /* j is not incremented yet */
+                               mask = 0-((inp_len+7-j)>>(sizeof(j)*8-1));
                                data->u[SHA_LBLOCK-1] |= bitlen&mask;
                                sha1_block_data_order(&key->md,data,1);
-                               mask &= 0-((j-inp_len-73)>>(sizeof(j)*8-1));
+                               mask &= 0-((j-inp_len-72)>>(sizeof(j)*8-1));
                                pmac->u[0] |= key->md.h0 & mask;
                                pmac->u[1] |= key->md.h1 & mask;
                                pmac->u[2] |= key->md.h2 & mask;
index 1e699726627d2bf017af73e02b537fd82fafa70e..8d7b7de292bcf494e1b7adf5f01886bcbfb54dd0 100644 (file)
@@ -101,7 +101,7 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
                              const unsigned char *in, size_t inl)
 {
-       if (inl>=EVP_MAXCHUNK)
+       while (inl>=EVP_MAXCHUNK)
                {
                DES_ede3_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK,
                               &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
@@ -132,7 +132,7 @@ static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
        printf("\n");
        }
 #endif    /* KSSL_DEBUG */
-       if (inl>=EVP_MAXCHUNK)
+       while (inl>=EVP_MAXCHUNK)
                {
                DES_ede3_cbc_encrypt(in, out, (long)EVP_MAXCHUNK,
                             &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
@@ -151,7 +151,7 @@ static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 static int des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
                              const unsigned char *in, size_t inl)
 {
-       if (inl>=EVP_MAXCHUNK)
+       while (inl>=EVP_MAXCHUNK)
                {
                DES_ede3_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK, 
                               &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
index 8c7454ee93407c615dc6be6931007b77e0308080..d5ad96b4033564b74ec8965b93ce68afaac87f5d 100644 (file)
@@ -724,6 +724,7 @@ foreach (split("\n",$code)) {
                s/cmpb,\*/comb,/;
                s/,\*/,/;
        }
+       s/\bbv\b/bve/   if ($SIZE_T==8);
        print $_,"\n";
 }
 
index 3d3782cbe1181b3ac7f9559208f0e4bb48d9eadf..0e54f75470b2fbba3b85289ec845b9e7bfb8ec4e 100644 (file)
@@ -117,7 +117,7 @@ void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
                        unsigned char ivec[16], block128_f block)
 {
        size_t n;
-       union { size_t align; unsigned char c[16]; } tmp;
+       union { size_t t[16/sizeof(size_t)]; unsigned char c[16]; } tmp;
 
        assert(in && out && key && ivec);
 
@@ -137,11 +137,13 @@ void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
                                out += 16;
                        }
                }
-               else {
+               else  if (16%sizeof(size_t) == 0) { /* always true */
                        while (len>=16) {
+                               size_t *out_t=(size_t *)out, *iv_t=(size_t *)iv;
+
                                (*block)(in, out, key);
-                               for(n=0; n<16; n+=sizeof(size_t))
-                                       *(size_t *)(out+n) ^= *(size_t *)(iv+n);
+                               for(n=0; n<16/sizeof(size_t); n++)
+                                       out_t[n] ^= iv_t[n];
                                iv = in;
                                len -= 16;
                                in  += 16;
@@ -165,15 +167,16 @@ void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
                                out += 16;
                        }
                }
-               else {
-                       size_t c;
+               else if (16%sizeof(size_t) == 0) { /* always true */
                        while (len>=16) {
+                               size_t c, *out_t=(size_t *)out, *ivec_t=(size_t *)ivec;
+                               const size_t *in_t=(const size_t *)in;
+
                                (*block)(in, tmp.c, key);
-                               for(n=0; n<16; n+=sizeof(size_t)) {
-                                       c = *(size_t *)(in+n);
-                                       *(size_t *)(out+n) =
-                                       *(size_t *)(tmp.c+n) ^ *(size_t *)(ivec+n);
-                                       *(size_t *)(ivec+n) = c;
+                               for(n=0; n<16/sizeof(size_t); n++) {
+                                       c = in_t[n];
+                                       out_t[n] = tmp.t[n] ^ ivec_t[n];
+                                       ivec_t[n] = c;
                                }
                                len -= 16;
                                in  += 16;
index c9b35e5b35e58fd0c802e5b76c2158a3c3d3771f..3ce11d0d984cbcd34ea507e279677e775065843e 100644 (file)
@@ -87,7 +87,7 @@ int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx,
                ctx->nonce.c[11] = (u8)(mlen>>(32%(sizeof(mlen)*8)));
        }
        else
-               *(u32*)(&ctx->nonce.c[8]) = 0;
+               ctx->nonce.u[1] = 0;
 
        ctx->nonce.c[12] = (u8)(mlen>>24);
        ctx->nonce.c[13] = (u8)(mlen>>16);
index c0e1f3696c6cd6c3a5672baf9be8ecef3b468ccd..2d583de6f61de74d7d197e77c20f7f1eea54c40b 100644 (file)
@@ -108,12 +108,8 @@ size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
        (*cbc)(in,out-16,residue,key,ivec,1);
        memcpy(out,tmp.c,residue);
 #else
-       {
-       size_t n;
-       for (n=0; n<16; n+=sizeof(size_t))
-               *(size_t *)(tmp.c+n) = 0;
+       memset(tmp.c,0,sizeof(tmp));
        memcpy(tmp.c,in,residue);
-       }
        memcpy(out,out-16,residue);
        (*cbc)(tmp.c,out-16,16,key,ivec,1);
 #endif
@@ -144,12 +140,8 @@ size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out,
 #if defined(CBC_HANDLES_TRUNCATED_IO)
        (*cbc)(in,out-16+residue,residue,key,ivec,1);
 #else
-       {
-       size_t n;
-       for (n=0; n<16; n+=sizeof(size_t))
-               *(size_t *)(tmp.c+n) = 0;
+       memset(tmp.c,0,sizeof(tmp));
        memcpy(tmp.c,in,residue);
-       }
        (*cbc)(tmp.c,out-16+residue,16,key,ivec,1);
 #endif
        return len+residue;
@@ -177,8 +169,7 @@ size_t CRYPTO_cts128_decrypt_block(const unsigned char *in, unsigned char *out,
 
        (*block)(in,tmp.c+16,key);
 
-       for (n=0; n<16; n+=sizeof(size_t))
-               *(size_t *)(tmp.c+n) = *(size_t *)(tmp.c+16+n);
+       memcpy(tmp.c,tmp.c+16,16);
        memcpy(tmp.c,in+16,residue);
        (*block)(tmp.c,tmp.c,key);
 
@@ -220,8 +211,7 @@ size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in, unsigned char *o
 
        (*block)(in+residue,tmp.c+16,key);
 
-       for (n=0; n<16; n+=sizeof(size_t))
-               *(size_t *)(tmp.c+n) = *(size_t *)(tmp.c+16+n);
+       memcpy(tmp.c,tmp.c+16,16);
        memcpy(tmp.c,in,residue);
        (*block)(tmp.c,tmp.c,key);
 
@@ -240,7 +230,7 @@ size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in, unsigned char *o
 size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
                        size_t len, const void *key,
                        unsigned char ivec[16], cbc128_f cbc)
-{      size_t residue, n;
+{      size_t residue;
        union { size_t align; unsigned char c[32]; } tmp;
 
        assert (in && out && key && ivec);
@@ -257,8 +247,7 @@ size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
                out += len;
        }
 
-       for (n=16; n<32; n+=sizeof(size_t))
-               *(size_t *)(tmp.c+n) = 0;
+       memset(tmp.c,0,sizeof(tmp));
        /* this places in[16] at &tmp.c[16] and decrypted block at &tmp.c[0] */
        (*cbc)(in,tmp.c,16,key,tmp.c+16,0);
 
@@ -275,7 +264,7 @@ size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
 size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
                        size_t len, const void *key,
                        unsigned char ivec[16], cbc128_f cbc)
-{      size_t residue, n;
+{      size_t residue;
        union { size_t align; unsigned char c[32]; } tmp;
 
        assert (in && out && key && ivec);
@@ -297,8 +286,7 @@ size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
                out += len;
        }
 
-       for (n=16; n<32; n+=sizeof(size_t))
-               *(size_t *)(tmp.c+n) = 0;
+       memset(tmp.c,0,sizeof(tmp));
        /* this places in[16] at &tmp.c[16] and decrypted block at &tmp.c[0] */
        (*cbc)(in+residue,tmp.c,16,key,tmp.c+16,0);
 
index 0e6ff8b0a155e0070d1afaaee767461da72f6ff2..250063de86cce247723f0e86701a73dbcc181840 100644 (file)
@@ -941,15 +941,17 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
                    size_t j=GHASH_CHUNK;
 
                    while (j) {
+                       size_t *out_t=(size_t *)out;
+                       const size_t *in_t=(const size_t *)in;
+
                        (*block)(ctx->Yi.c,ctx->EKi.c,key);
                        ++ctr;
                        if (is_endian.little)
                                PUTU32(ctx->Yi.c+12,ctr);
                        else
                                ctx->Yi.d[3] = ctr;
-                       for (i=0; i<16; i+=sizeof(size_t))
-                               *(size_t *)(out+i) =
-                               *(size_t *)(in+i)^*(size_t *)(ctx->EKi.c+i);
+                       for (i=0; i<16/sizeof(size_t); ++i)
+                               out_t[i] = in_t[i] ^ ctx->EKi.t[i];
                        out += 16;
                        in  += 16;
                        j   -= 16;
@@ -961,15 +963,17 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
                    size_t j=i;
 
                    while (len>=16) {
+                       size_t *out_t=(size_t *)out;
+                       const size_t *in_t=(const size_t *)in;
+
                        (*block)(ctx->Yi.c,ctx->EKi.c,key);
                        ++ctr;
                        if (is_endian.little)
                                PUTU32(ctx->Yi.c+12,ctr);
                        else
                                ctx->Yi.d[3] = ctr;
-                       for (i=0; i<16; i+=sizeof(size_t))
-                               *(size_t *)(out+i) =
-                               *(size_t *)(in+i)^*(size_t *)(ctx->EKi.c+i);
+                       for (i=0; i<16/sizeof(size_t); ++i)
+                               out_t[i] = in_t[i] ^ ctx->EKi.t[i];
                        out += 16;
                        in  += 16;
                        len -= 16;
@@ -978,16 +982,18 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
                }
 #else
                while (len>=16) {
+                       size_t *out_t=(size_t *)out;
+                       const size_t *in_t=(const size_t *)in;
+
                        (*block)(ctx->Yi.c,ctx->EKi.c,key);
                        ++ctr;
                        if (is_endian.little)
                                PUTU32(ctx->Yi.c+12,ctr);
                        else
                                ctx->Yi.d[3] = ctr;
-                       for (i=0; i<16; i+=sizeof(size_t))
-                               *(size_t *)(ctx->Xi.c+i) ^=
-                               *(size_t *)(out+i) =
-                               *(size_t *)(in+i)^*(size_t *)(ctx->EKi.c+i);
+                       for (i=0; i<16/sizeof(size_t); ++i)
+                               ctx->Xi.t[i] ^=
+                               out_t[i] = in_t[i]^ctx->EKi.t[i];
                        GCM_MUL(ctx,Xi);
                        out += 16;
                        in  += 16;
@@ -1091,15 +1097,17 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
 
                    GHASH(ctx,in,GHASH_CHUNK);
                    while (j) {
+                       size_t *out_t=(size_t *)out;
+                       const size_t *in_t=(const size_t *)in;
+
                        (*block)(ctx->Yi.c,ctx->EKi.c,key);
                        ++ctr;
                        if (is_endian.little)
                                PUTU32(ctx->Yi.c+12,ctr);
                        else
                                ctx->Yi.d[3] = ctr;
-                       for (i=0; i<16; i+=sizeof(size_t))
-                               *(size_t *)(out+i) =
-                               *(size_t *)(in+i)^*(size_t *)(ctx->EKi.c+i);
+                       for (i=0; i<16/sizeof(size_t); ++i)
+                               out_t[i] = in_t[i]^ctx->EKi.t[i];
                        out += 16;
                        in  += 16;
                        j   -= 16;
@@ -1109,15 +1117,17 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
                if ((i = (len&(size_t)-16))) {
                    GHASH(ctx,in,i);
                    while (len>=16) {
+                       size_t *out_t=(size_t *)out;
+                       const size_t *in_t=(const size_t *)in;
+
                        (*block)(ctx->Yi.c,ctx->EKi.c,key);
                        ++ctr;
                        if (is_endian.little)
                                PUTU32(ctx->Yi.c+12,ctr);
                        else
                                ctx->Yi.d[3] = ctr;
-                       for (i=0; i<16; i+=sizeof(size_t))
-                               *(size_t *)(out+i) =
-                               *(size_t *)(in+i)^*(size_t *)(ctx->EKi.c+i);
+                       for (i=0; i<16/sizeof(size_t); ++i)
+                               out_t[i] = in_t[i]^ctx->EKi.t[i];
                        out += 16;
                        in  += 16;
                        len -= 16;
@@ -1125,16 +1135,19 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
                }
 #else
                while (len>=16) {
+                       size_t *out_t=(size_t *)out;
+                       const size_t *in_t=(const size_t *)in;
+
                        (*block)(ctx->Yi.c,ctx->EKi.c,key);
                        ++ctr;
                        if (is_endian.little)
                                PUTU32(ctx->Yi.c+12,ctr);
                        else
                                ctx->Yi.d[3] = ctr;
-                       for (i=0; i<16; i+=sizeof(size_t)) {
-                               size_t c = *(size_t *)(in+i);
-                               *(size_t *)(out+i) = c^*(size_t *)(ctx->EKi.c+i);
-                               *(size_t *)(ctx->Xi.c+i) ^= c;
+                       for (i=0; i<16/sizeof(size_t); ++i) {
+                               size_t c = in[i];
+                               out[i] = c^ctx->EKi.t[i];
+                               ctx->Xi.t[i] ^= c;
                        }
                        GCM_MUL(ctx,Xi);
                        out += 16;
@@ -1669,6 +1682,46 @@ static const u8  IV18[]={0x93,0x13,0x22,0x5d,0xf8,0x84,0x06,0xe5,0x55,0x90,0x9c,0
                        0xa2,0x41,0x89,0x97,0x20,0x0e,0xf8,0x2e,0x44,0xae,0x7e,0x3f},
                T18[]= {0xa4,0x4a,0x82,0x66,0xee,0x1c,0x8e,0xb0,0xc8,0xb5,0xd4,0xcf,0x5a,0xe9,0xf1,0x9a};
 
+/* Test Case 19 */
+#define K19 K1
+#define P19 P1
+#define IV19 IV1
+#define C19 C1
+static const u8 A19[]= {0xd9,0x31,0x32,0x25,0xf8,0x84,0x06,0xe5,0xa5,0x59,0x09,0xc5,0xaf,0xf5,0x26,0x9a,
+                       0x86,0xa7,0xa9,0x53,0x15,0x34,0xf7,0xda,0x2e,0x4c,0x30,0x3d,0x8a,0x31,0x8a,0x72,
+                       0x1c,0x3c,0x0c,0x95,0x95,0x68,0x09,0x53,0x2f,0xcf,0x0e,0x24,0x49,0xa6,0xb5,0x25,
+                       0xb1,0x6a,0xed,0xf5,0xaa,0x0d,0xe6,0x57,0xba,0x63,0x7b,0x39,0x1a,0xaf,0xd2,0x55,
+                       0x52,0x2d,0xc1,0xf0,0x99,0x56,0x7d,0x07,0xf4,0x7f,0x37,0xa3,0x2a,0x84,0x42,0x7d,
+                       0x64,0x3a,0x8c,0xdc,0xbf,0xe5,0xc0,0xc9,0x75,0x98,0xa2,0xbd,0x25,0x55,0xd1,0xaa,
+                       0x8c,0xb0,0x8e,0x48,0x59,0x0d,0xbb,0x3d,0xa7,0xb0,0x8b,0x10,0x56,0x82,0x88,0x38,
+                       0xc5,0xf6,0x1e,0x63,0x93,0xba,0x7a,0x0a,0xbc,0xc9,0xf6,0x62,0x89,0x80,0x15,0xad},
+               T19[]= {0x5f,0xea,0x79,0x3a,0x2d,0x6f,0x97,0x4d,0x37,0xe6,0x8e,0x0c,0xb8,0xff,0x94,0x92};
+
+/* Test Case 20 */
+#define K20 K1
+#define A20 A1
+static const u8 IV20[64]={0xff,0xff,0xff,0xff},        /* this results in 0xff in counter LSB */
+               P20[288],
+               C20[]= {0x56,0xb3,0x37,0x3c,0xa9,0xef,0x6e,0x4a,0x2b,0x64,0xfe,0x1e,0x9a,0x17,0xb6,0x14,
+                       0x25,0xf1,0x0d,0x47,0xa7,0x5a,0x5f,0xce,0x13,0xef,0xc6,0xbc,0x78,0x4a,0xf2,0x4f,
+                       0x41,0x41,0xbd,0xd4,0x8c,0xf7,0xc7,0x70,0x88,0x7a,0xfd,0x57,0x3c,0xca,0x54,0x18,
+                       0xa9,0xae,0xff,0xcd,0x7c,0x5c,0xed,0xdf,0xc6,0xa7,0x83,0x97,0xb9,0xa8,0x5b,0x49,
+                       0x9d,0xa5,0x58,0x25,0x72,0x67,0xca,0xab,0x2a,0xd0,0xb2,0x3c,0xa4,0x76,0xa5,0x3c,
+                       0xb1,0x7f,0xb4,0x1c,0x4b,0x8b,0x47,0x5c,0xb4,0xf3,0xf7,0x16,0x50,0x94,0xc2,0x29,
+                       0xc9,0xe8,0xc4,0xdc,0x0a,0x2a,0x5f,0xf1,0x90,0x3e,0x50,0x15,0x11,0x22,0x13,0x76,
+                       0xa1,0xcd,0xb8,0x36,0x4c,0x50,0x61,0xa2,0x0c,0xae,0x74,0xbc,0x4a,0xcd,0x76,0xce,
+                       0xb0,0xab,0xc9,0xfd,0x32,0x17,0xef,0x9f,0x8c,0x90,0xbe,0x40,0x2d,0xdf,0x6d,0x86,
+                       0x97,0xf4,0xf8,0x80,0xdf,0xf1,0x5b,0xfb,0x7a,0x6b,0x28,0x24,0x1e,0xc8,0xfe,0x18,
+                       0x3c,0x2d,0x59,0xe3,0xf9,0xdf,0xff,0x65,0x3c,0x71,0x26,0xf0,0xac,0xb9,0xe6,0x42,
+                       0x11,0xf4,0x2b,0xae,0x12,0xaf,0x46,0x2b,0x10,0x70,0xbe,0xf1,0xab,0x5e,0x36,0x06,
+                       0x87,0x2c,0xa1,0x0d,0xee,0x15,0xb3,0x24,0x9b,0x1a,0x1b,0x95,0x8f,0x23,0x13,0x4c,
+                       0x4b,0xcc,0xb7,0xd0,0x32,0x00,0xbc,0xe4,0x20,0xa2,0xf8,0xeb,0x66,0xdc,0xf3,0x64,
+                       0x4d,0x14,0x23,0xc1,0xb5,0x69,0x90,0x03,0xc1,0x3e,0xce,0xf4,0xbf,0x38,0xa3,0xb6,
+                       0x0e,0xed,0xc3,0x40,0x33,0xba,0xc1,0x90,0x27,0x83,0xdc,0x6d,0x89,0xe2,0xe7,0x74,
+                       0x18,0x8a,0x43,0x9c,0x7e,0xbc,0xc0,0x67,0x2d,0xbd,0xa4,0xdd,0xcf,0xb2,0x79,0x46,
+                       0x13,0xb0,0xbe,0x41,0x31,0x5e,0xf7,0x78,0x70,0x8a,0x70,0xee,0x7d,0x75,0x16,0x5c},
+               T20[]= {0x8b,0x30,0x7f,0x6b,0x33,0x28,0x6d,0x0a,0xb0,0x26,0xa9,0xed,0x3f,0xe1,0xe8,0x5f};
+
 #define TEST_CASE(n)   do {                                    \
        u8 out[sizeof(P##n)];                                   \
        AES_set_encrypt_key(K##n,sizeof(K##n)*8,&key);          \
@@ -1713,6 +1766,8 @@ int main()
        TEST_CASE(16);
        TEST_CASE(17);
        TEST_CASE(18);
+       TEST_CASE(19);
+       TEST_CASE(20);
 
 #ifdef OPENSSL_CPUID_OBJ
        {
@@ -1743,11 +1798,16 @@ int main()
                        ctr_t/(double)sizeof(buf),
                        (gcm_t-ctr_t)/(double)sizeof(buf));
 #ifdef GHASH
-       GHASH(&ctx,buf.c,sizeof(buf));
+       {
+       void (*gcm_ghash_p)(u64 Xi[2],const u128 Htable[16],
+                               const u8 *inp,size_t len)       = ctx.ghash;
+
+       GHASH((&ctx),buf.c,sizeof(buf));
        start = OPENSSL_rdtsc();
-       for (i=0;i<100;++i) GHASH(&ctx,buf.c,sizeof(buf));
+       for (i=0;i<100;++i) GHASH((&ctx),buf.c,sizeof(buf));
        gcm_t = OPENSSL_rdtsc() - start;
        printf("%.2f\n",gcm_t/(double)sizeof(buf)/(double)i);
+       }
 #endif
        }
 #endif
index b6dc3c336fe09c0c627bc431e7e7089227ebf7d5..9d83e128444e0bb583a8313753a0b5fd5e0ec388 100644 (file)
@@ -29,10 +29,7 @@ typedef unsigned char u8;
 #if defined(__i386)    || defined(__i386__)    || \
     defined(__x86_64)  || defined(__x86_64__)  || \
     defined(_M_IX86)   || defined(_M_AMD64)    || defined(_M_X64) || \
-    defined(__s390__)  || defined(__s390x__)   || \
-    ( (defined(__arm__)        || defined(__arm)) && \
-      (defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || \
-       defined(__ARM_ARCH_7R__)        || defined(__ARM_ARCH_7M__)) )
+    defined(__s390__)  || defined(__s390x__)
 # undef STRICT_ALIGNMENT
 #endif
 
@@ -101,8 +98,8 @@ typedef struct { u64 hi,lo; } u128;
 
 struct gcm128_context {
        /* Following 6 names follow names in GCM specification */
-       union { u64 u[2]; u32 d[4]; u8 c[16]; } Yi,EKi,EK0,len,
-                                               Xi,H;
+       union { u64 u[2]; u32 d[4]; u8 c[16]; size_t t[16/sizeof(size_t)]; }
+         Yi,EKi,EK0,len,Xi,H;
        /* Relative position of Xi, H and pre-computed Htable is used
         * in some assembler modules, i.e. don't change the order! */
 #if TABLE_BITS==8
index 5bc8e53e66adf8af2425eb349c6eb20377f25e4b..ef8ff972979ff228e3cb76bedc794195c8095a6f 100644 (file)
  * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for
  *  major minor fix final patch/beta)
  */
-#define OPENSSL_VERSION_NUMBER 0x1000105fL
+#define OPENSSL_VERSION_NUMBER 0x10001060L
 #ifdef OPENSSL_FIPS
-#define OPENSSL_VERSION_TEXT   "OpenSSL 1.0.1e-fips 11 Feb 2013"
+#define OPENSSL_VERSION_TEXT   "OpenSSL 1.0.1f-fips-dev xx XXX xxxx"
 #else
-#define OPENSSL_VERSION_TEXT   "OpenSSL 1.0.1e 11 Feb 2013"
+#define OPENSSL_VERSION_TEXT   "OpenSSL 1.0.1f-dev xx XXX xxxx"
 #endif
 #define OPENSSL_VERSION_PTEXT  " part of " OPENSSL_VERSION_TEXT
 
index 477ec9b87dd7d36ccb190001ec5bd4d00d9d6b26..bfc56fdc7fc04be2f8f92f64a5d7e8645e18a9ce 100644 (file)
@@ -97,33 +97,33 @@ OPENSSL_cleanse
        .PROC
        .CALLINFO       NO_CALLS
        .ENTRY
-       cmpib,*=        0,$len,Ldone
+       cmpib,*=        0,$len,L\$done
        nop
-       cmpib,*>>=      15,$len,Little
+       cmpib,*>>=      15,$len,L\$ittle
        ldi             $SIZE_T-1,%r1
 
-Lalign
+L\$align
        and,*<>         $inp,%r1,%r28
-       b,n             Laligned
+       b,n             L\$aligned
        stb             %r0,0($inp)
        ldo             -1($len),$len
-       b               Lalign
+       b               L\$align
        ldo             1($inp),$inp
 
-Laligned
+L\$aligned
        andcm           $len,%r1,%r28
-Lot
+L\$ot
        $ST             %r0,0($inp)
-       addib,*<>       -$SIZE_T,%r28,Lot
+       addib,*<>       -$SIZE_T,%r28,L\$ot
        ldo             $SIZE_T($inp),$inp
 
        and,*<>         $len,%r1,$len
-       b,n             Ldone
-Little
+       b,n             L\$done
+L\$ittle
        stb             %r0,0($inp)
-       addib,*<>       -1,$len,Little
+       addib,*<>       -1,$len,L\$ittle
        ldo             1($inp),$inp
-Ldone
+L\$done
        bv              ($rp)
        .EXIT
        nop
@@ -151,7 +151,7 @@ OPENSSL_instrument_bus
        ldw             0($out),$tick
        add             $diff,$tick,$tick
        stw             $tick,0($out)
-Loop
+L\$oop
        mfctl           %cr16,$tick
        sub             $tick,$lasttick,$diff
        copy            $tick,$lasttick
@@ -161,7 +161,7 @@ Loop
        add             $diff,$tick,$tick
        stw             $tick,0($out)
 
-       addib,<>        -1,$cnt,Loop
+       addib,<>        -1,$cnt,L\$oop
        addi            4,$out,$out
 
        bv              ($rp)
@@ -190,14 +190,14 @@ OPENSSL_instrument_bus2
        mfctl           %cr16,$tick
        sub             $tick,$lasttick,$diff
        copy            $tick,$lasttick
-Loop2
+L\$oop2
        copy            $diff,$lastdiff
        fdc             0($out)
        ldw             0($out),$tick
        add             $diff,$tick,$tick
        stw             $tick,0($out)
 
-       addib,=         -1,$max,Ldone2
+       addib,=         -1,$max,L\$done2
        nop
 
        mfctl           %cr16,$tick
@@ -208,17 +208,18 @@ Loop2
 
        ldi             1,%r1
        xor             %r1,$tick,$tick
-       addb,<>         $tick,$cnt,Loop2
+       addb,<>         $tick,$cnt,L\$oop2
        shladd,l        $tick,2,$out,$out
-Ldone2
+L\$done2
        bv              ($rp)
        .EXIT
        add             $rv,$cnt,$rv
        .PROCEND
 ___
 }
-$code =~ s/cmpib,\*/comib,/gm if ($SIZE_T==4);
-$code =~ s/,\*/,/gm if ($SIZE_T==4);
+$code =~ s/cmpib,\*/comib,/gm  if ($SIZE_T==4);
+$code =~ s/,\*/,/gm            if ($SIZE_T==4);
+$code =~ s/\bbv\b/bve/gm       if ($SIZE_T==8);
 print $code;
 close STDOUT;
 
index 1b2be527edde007bf86c894d1f3b70f75bc6117e..cc7f24a9c1cf491ae3092b9dc4aa8fe05e927ef0 100644 (file)
@@ -167,6 +167,7 @@ start:
 #ifndef OPENSSL_NO_RSA
                        if (strcmp(name,PEM_STRING_RSA) == 0)
                        {
+                       d2i=(D2I_OF(void))d2i_RSAPrivateKey;
                        if (xi->x_pkey != NULL) 
                                {
                                if (!sk_X509_INFO_push(ret,xi)) goto err;
index 96b131defa0cadb3df00e170698913c5952257f2..a34915d02d14dee31102ea2d8557789cd933011c 100644 (file)
@@ -90,7 +90,14 @@ PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
 
        /* Set defaults */
        if (!nid_cert)
+               {
+#ifdef OPENSSL_FIPS
+               if (FIPS_mode())
+                       nid_cert = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
+               else
+#endif
                nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC;
+               }
        if (!nid_key)
                nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
        if (!iter)
index dc8fcf94c5aa87bbb314b72055d108945dc2a90a..bb5520e80ac161cc498941b73dea9e3665301d10 100644 (file)
@@ -138,6 +138,7 @@ void ERR_load_RAND_strings(void);
 #define RAND_F_SSLEAY_RAND_BYTES                        100
 
 /* Reason codes. */
+#define RAND_R_DUAL_EC_DRBG_DISABLED                    104
 #define RAND_R_ERROR_INITIALISING_DRBG                  102
 #define RAND_R_ERROR_INSTANTIATING_DRBG                         103
 #define RAND_R_NO_FIPS_RANDOM_METHOD_SET                101
index b8586c8f4a9c3832616faf64812f7e8947bc67d5..c4c80fc8ccad4dc0a90de349301519f15152a5bd 100644 (file)
@@ -78,6 +78,7 @@ static ERR_STRING_DATA RAND_str_functs[]=
 
 static ERR_STRING_DATA RAND_str_reasons[]=
        {
+{ERR_REASON(RAND_R_DUAL_EC_DRBG_DISABLED),"dual ec drbg disabled"},
 {ERR_REASON(RAND_R_ERROR_INITIALISING_DRBG),"error initialising drbg"},
 {ERR_REASON(RAND_R_ERROR_INSTANTIATING_DRBG),"error instantiating drbg"},
 {ERR_REASON(RAND_R_NO_FIPS_RANDOM_METHOD_SET),"no fips random method set"},
index 476a0cd187ee7629526042e5de5728e6277a4b7c..5ac0e14caf00bd36539b5180985117bd2f94b8fd 100644 (file)
@@ -269,6 +269,14 @@ int RAND_init_fips(void)
        DRBG_CTX *dctx;
        size_t plen;
        unsigned char pers[32], *p;
+#ifndef OPENSSL_ALLOW_DUAL_EC_DRBG
+       if (fips_drbg_type >> 16)
+               {
+               RANDerr(RAND_F_RAND_INIT_FIPS, RAND_R_DUAL_EC_DRBG_DISABLED);
+               return 0;
+               }
+#endif
+               
        dctx = FIPS_get_default_drbg();
         if (FIPS_drbg_init(dctx, fips_drbg_type, fips_drbg_flags) <= 0)
                {
index 9165067080eff92155ddb6a404f547268fb774fb..ad7e65651cf905c7b551898c923c270a367d77cc 100644 (file)
@@ -307,7 +307,8 @@ L\$opts
        .STRINGZ "RC4 for PA-RISC, CRYPTOGAMS by <appro\@openssl.org>"
 ___
 $code =~ s/\`([^\`]*)\`/eval $1/gem;
-$code =~ s/cmpib,\*/comib,/gm if ($SIZE_T==4);
+$code =~ s/cmpib,\*/comib,/gm  if ($SIZE_T==4);
+$code =~ s/\bbv\b/bve/gm       if ($SIZE_T==8);
 
 print $code;
 close STDOUT;
index 2460910ab2783e5dc198e6437462a18e32f7f9b8..5a2062f903ae8bcb02d82ae21c4766f534e52271 100644 (file)
@@ -351,27 +351,27 @@ static int rsa_pss_param_print(BIO *bp, RSA_PSS_PARAMS *pss,
 
        if (!BIO_indent(bp, indent, 128))
                goto err;
-       if (BIO_puts(bp, "Salt Length: ") <= 0)
+       if (BIO_puts(bp, "Salt Length: 0x") <= 0)
                        goto err;
        if (pss->saltLength)
                {
                if (i2a_ASN1_INTEGER(bp, pss->saltLength) <= 0)
                        goto err;
                }
-       else if (BIO_puts(bp, "20 (default)") <= 0)
+       else if (BIO_puts(bp, "0x14 (default)") <= 0)
                goto err;
        BIO_puts(bp, "\n");
 
        if (!BIO_indent(bp, indent, 128))
                goto err;
-       if (BIO_puts(bp, "Trailer Field: ") <= 0)
+       if (BIO_puts(bp, "Trailer Field: 0x") <= 0)
                        goto err;
        if (pss->trailerField)
                {
                if (i2a_ASN1_INTEGER(bp, pss->trailerField) <= 0)
                        goto err;
                }
-       else if (BIO_puts(bp, "0xbc (default)") <= 0)
+       else if (BIO_puts(bp, "BC (default)") <= 0)
                goto err;
        BIO_puts(bp, "\n");
        
index 5b2ecf56adc7343b8661ac4c9c4222a00dde5a10..157aa5c41d2af2b6019a7365427b6468e2fbc179 100644 (file)
@@ -611,6 +611,8 @@ static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx,
                        pm = RSA_NO_PADDING;
                else if (!strcmp(value, "oeap"))
                        pm = RSA_PKCS1_OAEP_PADDING;
+               else if (!strcmp(value, "oaep"))
+                       pm = RSA_PKCS1_OAEP_PADDING;
                else if (!strcmp(value, "x931"))
                        pm = RSA_X931_PADDING;
                else if (!strcmp(value, "pss"))
index 6d7bf495b20abbfb5b8e40021dae00349c600fac..6e5a328a6f1f377387863fabdb09e382eee5f9fe 100644 (file)
@@ -254,6 +254,7 @@ $code.=<<___;
 ___
 
 $code =~ s/\`([^\`]*)\`/eval $1/gem;
-$code =~ s/,\*/,/gm if ($SIZE_T==4);
+$code =~ s/,\*/,/gm            if ($SIZE_T==4);
+$code =~ s/\bbv\b/bve/gm       if ($SIZE_T==8);
 print $code;
 close STDOUT;
index cfdc45cce6dad0ecf274e15de8b8cef1a4c9f7c5..f15c7ec39b20d9cc2c90b440a7b8ede6e9c3aae9 100755 (executable)
@@ -745,7 +745,7 @@ $code.=<<___;
        mov     %rdi,$ctx       # reassigned argument
        mov     %rsi,$inp       # reassigned argument
        mov     %rdx,$num       # reassigned argument
-       vzeroall
+       vzeroupper
 
        shl     \$6,$num
        add     $inp,$num
@@ -1038,7 +1038,7 @@ ___
        &Xtail_avx(\&body_20_39);
 
 $code.=<<___;
-       vzeroall
+       vzeroupper
 
        add     0($ctx),$A                      # update context
        add     4($ctx),@T[0]
index ba5b250890e00a88d3e1bd40cde7a341fe394024..ffa053bb7d367a864d0a3223691d90da7f8ccf08 100644 (file)
@@ -351,7 +351,7 @@ $code.=<<___;
        $ST     $G,6*$SZ($ctx)
        $ST     $H,7*$SZ($ctx)
 
-       bnel    $inp,@X[15],.Loop
+       bne     $inp,@X[15],.Loop
        $PTR_SUB $Ktbl,`($rounds-16)*$SZ`       # rewind $Ktbl
 
        $REG_L  $ra,$FRAMESIZE-1*$SZREG($sp)
index e24ee58ae97f2a5c2bb78a93e1496462e1caaa28..fc0e15b3c0593a04c803b1284b7d885a91df9314 100755 (executable)
@@ -785,6 +785,8 @@ foreach (split("\n",$code)) {
 
        s/cmpb,\*/comb,/ if ($SIZE_T==4);
 
+       s/\bbv\b/bve/    if ($SIZE_T==8);
+
        print $_,"\n";
 }
 
index 12d71f54e2e53af69071b6dfd0164deaa5d14e04..5195ffef264d647dec2205cfcbbf1df02f1419f5 100644 (file)
@@ -694,6 +694,7 @@ static int check_cert(X509_STORE_CTX *ctx)
        X509_CRL *crl = NULL, *dcrl = NULL;
        X509 *x;
        int ok, cnum;
+       unsigned int last_reasons;
        cnum = ctx->error_depth;
        x = sk_X509_value(ctx->chain, cnum);
        ctx->current_cert = x;
@@ -702,6 +703,7 @@ static int check_cert(X509_STORE_CTX *ctx)
        ctx->current_reasons = 0;
        while (ctx->current_reasons != CRLDP_ALL_REASONS)
                {
+               last_reasons = ctx->current_reasons;
                /* Try to retrieve relevant CRL */
                if (ctx->get_crl)
                        ok = ctx->get_crl(ctx, &crl, x);
@@ -745,6 +747,15 @@ static int check_cert(X509_STORE_CTX *ctx)
                X509_CRL_free(dcrl);
                crl = NULL;
                dcrl = NULL;
+               /* If reasons not updated we wont get anywhere by
+                * another iteration, so exit loop.
+                */
+               if (last_reasons == ctx->current_reasons)
+                       {
+                       ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL;
+                       ok = ctx->verify_cb(0, ctx);
+                       goto err;
+                       }
                }
        err:
        X509_CRL_free(crl);
index b94aeeb873fddf4408129e2d269bf9111478a508..e06602d65abcc05825cb9461eb31fc5f3dc4d103 100644 (file)
@@ -97,6 +97,7 @@ int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
 
 int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx)
        {
+       x->cert_info->enc.modified = 1;
        return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CINF),
                x->cert_info->signature,
                x->sig_alg, x->signature, x->cert_info, ctx);
@@ -123,6 +124,7 @@ int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md)
 
 int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx)
        {
+       x->crl->enc.modified = 1;
        return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CRL_INFO),
                x->crl->sig_alg, x->sig_alg, x->signature, x->crl, ctx);
        }
index c18b0e2486d6ead7578d88a0cb227995b93eb67f..b270b44337d1400960cd3779efd257979fc30d45 100644 (file)
@@ -67,6 +67,7 @@ for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
        &inc    ("esi");                # number of cores
 
        &mov    ("eax",1);
+       &xor    ("ecx","ecx");
        &cpuid  ();
        &bt     ("edx",28);
        &jnc    (&label("generic"));
@@ -91,6 +92,7 @@ for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
 
 &set_label("nocacheinfo");
        &mov    ("eax",1);
+       &xor    ("ecx","ecx");
        &cpuid  ();
        &and    ("edx",0xbfefffff);     # force reserved bits #20, #30 to 0
        &cmp    ("ebp",0);
index d17e4ade943128c4eb812a41737c290b6963b9d0..d1cba9dc5a6d393444f78b23101afdaf7b3436c7 100644 (file)
@@ -7,13 +7,14 @@
 
 #include <openssl/pem.h>
 #include <openssl/conf.h>
+#include <openssl/x509.h>
 #include <openssl/x509v3.h>
 #ifndef OPENSSL_NO_ENGINE
 #include <openssl/engine.h>
 #endif
 
 int mkreq(X509_REQ **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days);
-int add_ext(STACK_OF(X509_REQUEST) *sk, int nid, char *value);
+int add_ext(STACK_OF(X509_EXTENSION) *sk, int nid, char *value);
 
 int main(int argc, char **argv)
        {
@@ -148,7 +149,7 @@ err:
  * because we wont reference any other sections.
  */
 
-int add_ext(STACK_OF(X509_REQUEST) *sk, int nid, char *value)
+int add_ext(STACK_OF(X509_EXTENSION) *sk, int nid, char *value)
        {
        X509_EXTENSION *ex;
        ex = X509V3_EXT_conf_nid(NULL, NULL, nid, value);
index a883f6c09783b7f0c70c9e3fc789b92ad4f1eec9..60e8332ae9ddf099c6dc57f70f2d03ccacd14359 100644 (file)
@@ -278,6 +278,8 @@ happen if extended CRL checking is enabled.
 an application specific error. This will never be returned unless explicitly
 set by an application.
 
+=back
+
 =head1 NOTES
 
 The above functions should be used instead of directly referencing the fields
index 20edff97ffd66a62747af2901617ab6f11f93cad..59a5916de1239d8c343f9a64d7ac8f3b83a598bb 100644 (file)
@@ -95,7 +95,7 @@ is ignored.
 
 ECDSA_verify() verifies that the signature in B<sig> of size
 B<siglen> is a valid ECDSA signature of the hash value
-value B<dgst> of size B<dgstlen> using the public key B<eckey>.
+B<dgst> of size B<dgstlen> using the public key B<eckey>.
 The parameter B<type> is ignored.
 
 ECDSA_do_sign() is wrapper function for ECDSA_do_sign_ex with B<kinv>
@@ -131,16 +131,12 @@ specific)
 
  int        ret;
  ECDSA_SIG *sig;
- EC_KEY    *eckey = EC_KEY_new();
+ EC_KEY    *eckey;
+ eckey = EC_KEY_new_by_curve_name(NID_secp192k1);
  if (eckey == NULL)
        {
        /* error */
        }
- key->group = EC_GROUP_new_by_nid(NID_secp192k1);
- if (key->group == NULL)
-       {
-       /* error */
-       }
  if (!EC_KEY_generate_key(eckey))
        {
        /* error */
index 632b556d1262227feb2038ef48f5484f112748fa..5e6613335c608e2e4ac323d55ba95bb2b028c047 100644 (file)
@@ -66,16 +66,16 @@ values:
 
 =over 4
 
-=item 1
-
-The operation succeeded.
-
 =item 0
 
 A failure while manipulating the STACK_OF(X509_NAME) object occurred or
 the X509_NAME could not be extracted from B<cacert>. Check the error stack
 to find out the reason.
 
+=item 1
+
+The operation succeeded.
+
 =back
 
 =head1 EXAMPLES
index cc588f3a78f3a302a4b422bc2fdc9dc55728e5d9..fded0601b566b65ba84769a7ced7df3df7c4a6e3 100644 (file)
@@ -88,9 +88,10 @@ As of OpenSSL 0.9.8q and 1.0.0c, this option has no effect.
 
 ...
 
-=item SSL_OP_MSIE_SSLV2_RSA_PADDING
+=item SSL_OP_SAFARI_ECDHE_ECDSA_BUG
 
-As of OpenSSL 0.9.7h and 0.9.8a, this option has no effect.
+Don't prefer ECDHE-ECDSA ciphers when the client appears to be Safari on OS X.
+OS X 10.8..10.8.3 has broken support for ECDHE-ECDSA ciphers.
 
 =item SSL_OP_SSLEAY_080_CLIENT_DH_BUG
 
index b80e25be7eaae33449af364ed6b8b7b3df89400f..7e60df5ba85c1bb2290d97d755db9e50418ecf89 100644 (file)
@@ -81,6 +81,8 @@ SSL_CTX_use_psk_identity_hint() and SSL_use_psk_identity_hint() return
 
 Return values from the server callback are interpreted as follows:
 
+=over 4
+
 =item > 0
 
 PSK identity was found and the server callback has provided the PSK
@@ -99,4 +101,6 @@ completely.
 PSK identity was not found. An "unknown_psk_identity" alert message
 will be sent and the connection setup fails.
 
+=back
+
 =cut
index cc724c0d561a0cbfb6709b534a8de59c07376b99..b1c34d15b6e88b2b973af8424c870f015c8e323e 100644 (file)
@@ -44,17 +44,17 @@ The following return values can occur:
 
 =over 4
 
-=item 1
-
-The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
-established.
-
 =item 0
 
 The TLS/SSL handshake was not successful but was shut down controlled and
 by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
 return value B<ret> to find out the reason.
 
+=item 1
+
+The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
+established.
+
 =item E<lt>0
 
 The TLS/SSL handshake was not successful because a fatal error occurred either
index cc56ebb75f3f8367126261092e4bf06b775c13bc..946ca89d7b7d7e604fd7253bbb7f71a2976706a0 100644 (file)
@@ -41,17 +41,17 @@ The following return values can occur:
 
 =over 4
 
-=item 1
-
-The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
-established.
-
 =item 0
 
 The TLS/SSL handshake was not successful but was shut down controlled and
 by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
 return value B<ret> to find out the reason.
 
+=item 1
+
+The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
+established.
+
 =item E<lt>0
 
 The TLS/SSL handshake was not successful, because a fatal error occurred either
index 243576451b7fa77d51f91021d37406f310d9e3dd..7f8cf249ec046fa12b483418f867bfbffeff65e4 100644 (file)
@@ -45,17 +45,17 @@ The following return values can occur:
 
 =over 4
 
-=item 1
-
-The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
-established.
-
 =item 0
 
 The TLS/SSL handshake was not successful but was shut down controlled and
 by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
 return value B<ret> to find out the reason.
 
+=item 1
+
+The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
+established.
+
 =item E<lt>0
 
 The TLS/SSL handshake was not successful because a fatal error occurred either
index 89911acbcac89a89c8de068297be4b7f7858b4ef..42a89b7c6b979e3e96bde7badccbda9ee011d319 100644 (file)
@@ -92,11 +92,6 @@ The following return values can occur:
 
 =over 4
 
-=item 1
-
-The shutdown was successfully completed. The "close notify" alert was sent
-and the peer's "close notify" alert was received.
-
 =item 0
 
 The shutdown is not yet finished. Call SSL_shutdown() for a second time,
@@ -104,6 +99,11 @@ if a bidirectional shutdown shall be performed.
 The output of L<SSL_get_error(3)|SSL_get_error(3)> may be misleading, as an
 erroneous SSL_ERROR_SYSCALL may be flagged even though no error occurred.
 
+=item 1
+
+The shutdown was successfully completed. The "close notify" alert was sent
+and the peer's "close notify" alert was received.
+
 =item -1
 
 The shutdown was not successful because a fatal error occurred either
index 8ad98b363c812270c9c606949ab26394dc3cb844..9339c1afb075adc9613a0cc0f345dd5b52d17d9b 100644 (file)
@@ -2,7 +2,7 @@
 %define libmaj 1
 %define libmin 0
 %define librel 1
-%define librev e
+%define librev f
 Release: 1
 
 %define openssldir /var/ssl
index de8bab873f2cf114d0d1b3e49acfa09bb9d0e4f7..65ec0018ae64baa175f37ece77de8f5883ff516d 100644 (file)
@@ -313,9 +313,10 @@ int dtls1_do_write(SSL *s, int type)
                                s->init_off -= DTLS1_HM_HEADER_LENGTH;
                                s->init_num += DTLS1_HM_HEADER_LENGTH;
 
-                               /* write atleast DTLS1_HM_HEADER_LENGTH bytes */
-                               if ( len <= DTLS1_HM_HEADER_LENGTH)  
-                                       len += DTLS1_HM_HEADER_LENGTH;
+                               if ( s->init_num > curr_mtu)
+                                       len = curr_mtu;
+                               else
+                                       len = s->init_num;
                                }
 
                        dtls1_fix_message_header(s, frag_off, 
index f61f718183083ff23bcbb281c777ee6f9bd364ae..106939f24177b7c727c2ddc4a3344df16d19b14f 100644 (file)
@@ -196,6 +196,7 @@ void dtls1_free(SSL *s)
        pqueue_free(s->d1->buffered_app_data.q);
 
        OPENSSL_free(s->d1);
+       s->d1 = NULL;
        }
 
 void dtls1_clear(SSL *s)
index 0bf87be6d21000f19ae070f1d836a7920ca4f10f..8186462d4a6be97eab48f424eb1b6b6e61299f21 100644 (file)
@@ -847,6 +847,12 @@ start:
                        }
                }
 
+       if (s->d1->listen && rr->type != SSL3_RT_HANDSHAKE)
+               {
+               rr->length = 0;
+               goto start;
+               }
+
        /* we now have a packet which can be read and processed */
 
        if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1051,6 +1057,7 @@ start:
                        !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) &&
                        !s->s3->renegotiate)
                        {
+                       s->d1->handshake_read_seq++;
                        s->new_session = 1;
                        ssl3_renegotiate(s);
                        if (ssl3_renegotiate_check(s))
index 9563066bd1b05fa82c75be7c14b2aba5135dd45b..c0beb4510f63338bf4d3d304c28340e847c4779c 100644 (file)
@@ -276,10 +276,11 @@ int dtls1_accept(SSL *s)
                case SSL3_ST_SW_HELLO_REQ_B:
 
                        s->shutdown=0;
+                       dtls1_clear_record_buffer(s);
                        dtls1_start_timer(s);
                        ret=dtls1_send_hello_request(s);
                        if (ret <= 0) goto end;
-                       s->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C;
+                       s->s3->tmp.next_state=SSL3_ST_SR_CLNT_HELLO_A;
                        s->state=SSL3_ST_SW_FLUSH;
                        s->init_num=0;
 
index 02edf3f9189e3888df67e7074b0b88c3d45fc576..443a31e74627bb27c619dca5b568630df0dab82b 100644 (file)
@@ -148,7 +148,7 @@ int tls1_cbc_remove_padding(const SSL* s,
        unsigned padding_length, good, to_check, i;
        const unsigned overhead = 1 /* padding length byte */ + mac_size;
        /* Check if version requires explicit IV */
-       if (s->version >= TLS1_1_VERSION || s->version == DTLS1_VERSION)
+       if (s->version >= TLS1_1_VERSION || s->version == DTLS1_BAD_VER)
                {
                /* These lengths are all public so we can test them in
                 * non-constant time.
index e7c5dcb809f923eb351406c5e94033255aa7c2ee..86a8bc56a76640aa93606c036b324b8a4de21f0c 100644 (file)
@@ -3037,6 +3037,11 @@ void ssl3_clear(SSL *s)
                s->s3->tmp.ecdh = NULL;
                }
 #endif
+#ifndef OPENSSL_NO_TLSEXT
+#ifndef OPENSSL_NO_EC
+       s->s3->is_probably_safari = 0;
+#endif /* !OPENSSL_NO_EC */
+#endif /* !OPENSSL_NO_TLSEXT */
 
        rp = s->s3->rbuf.buf;
        wp = s->s3->wbuf.buf;
@@ -4016,6 +4021,13 @@ SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
                ii=sk_SSL_CIPHER_find(allow,c);
                if (ii >= 0)
                        {
+#if !defined(OPENSSL_NO_EC) && !defined(OPENSSL_NO_TLSEXT)
+                       if ((alg_k & SSL_kEECDH) && (alg_a & SSL_aECDSA) && s->s3->is_probably_safari)
+                               {
+                               if (!ret) ret=sk_SSL_CIPHER_value(allow,ii);
+                               continue;
+                               }
+#endif
                        ret=sk_SSL_CIPHER_value(allow,ii);
                        break;
                        }
index ae852bf011668c4909e61b4330fec783ccc97d6d..1c12ddd71f1db8b3a2355aefb3ab534705977c6c 100644 (file)
--- a/ssl/ssl.h
+++ b/ssl/ssl.h
@@ -555,7 +555,7 @@ struct ssl_session_st
 #define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG                0x00000008L
 #define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG             0x00000010L
 #define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER              0x00000020L
-#define SSL_OP_MSIE_SSLV2_RSA_PADDING                  0x00000040L /* no effect since 0.9.7h and 0.9.8b */
+#define SSL_OP_SAFARI_ECDHE_ECDSA_BUG                  0x00000040L
 #define SSL_OP_SSLEAY_080_CLIENT_DH_BUG                        0x00000080L
 #define SSL_OP_TLS_D5_BUG                              0x00000100L
 #define SSL_OP_TLS_BLOCK_PADDING_BUG                   0x00000200L
index 247e88c2d631e570ce297f1a3d9a1861e6c9583c..cb8b2492ec976704c89ecc32e8009f051398ead4 100644 (file)
@@ -539,6 +539,15 @@ typedef struct ssl3_state_st
        /* Set if we saw the Next Protocol Negotiation extension from our peer. */
        int next_proto_neg_seen;
 #endif
+
+#ifndef OPENSSL_NO_TLSEXT
+#ifndef OPENSSL_NO_EC
+       /* This is set to true if we believe that this is a version of Safari
+        * running on OS X 10.6 or newer. We wish to know this because Safari
+        * on 10.8 .. 10.8.3 has broken ECDHE-ECDSA support. */
+       char is_probably_safari;
+#endif /* !OPENSSL_NO_EC */
+#endif /* !OPENSSL_NO_TLSEXT */
        } SSL3_STATE;
 
 #endif
index 14d143da0441eee78b3f9b50896a65022edb4cf4..6dbc3c1f7d0a7ea02614a123eb82130ba98f653c 100644 (file)
@@ -1797,7 +1797,9 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)
        CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data);
 
        ret->extra_certs=NULL;
-       ret->comp_methods=SSL_COMP_get_compression_methods();
+       /* No compression for DTLS */
+       if (meth->version != DTLS1_VERSION)
+               ret->comp_methods=SSL_COMP_get_compression_methods();
 
        ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;
 
@@ -2792,9 +2794,7 @@ void ssl_clear_cipher_ctx(SSL *s)
 /* Fix this function so that it takes an optional type parameter */
 X509 *SSL_get_certificate(const SSL *s)
        {
-       if (s->server)
-               return(ssl_get_server_send_cert(s));
-       else if (s->cert != NULL)
+       if (s->cert != NULL)
                return(s->cert->key->x509);
        else
                return(NULL);
index 316bbb0c9582fe962945bd532c93eb3fd93c1d81..4f80be8ee4d8e403c7887b62cba36d92e91bd6b2 100644 (file)
@@ -881,7 +881,13 @@ bad:
                meth=SSLv23_method();
 #else
 #ifdef OPENSSL_NO_SSL2
-       meth=SSLv3_method();
+       if (tls1)
+               meth=TLSv1_method();
+       else
+       if (ssl3)
+               meth=SSLv3_method();
+       else
+               meth=SSLv23_method();
 #else
        meth=SSLv2_method();
 #endif
index e08088c57eff45c7e4d4f5691596001392cae7ec..f93216d4540299356b78271d70484708b50cca82 100644 (file)
@@ -866,6 +866,89 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
        return ret;
        }
 
+#ifndef OPENSSL_NO_EC
+/* ssl_check_for_safari attempts to fingerprint Safari using OS X
+ * SecureTransport using the TLS extension block in |d|, of length |n|.
+ * Safari, since 10.6, sends exactly these extensions, in this order:
+ *   SNI,
+ *   elliptic_curves
+ *   ec_point_formats
+ *
+ * We wish to fingerprint Safari because they broke ECDHE-ECDSA support in 10.8,
+ * but they advertise support. So enabling ECDHE-ECDSA ciphers breaks them.
+ * Sadly we cannot differentiate 10.6, 10.7 and 10.8.4 (which work), from
+ * 10.8..10.8.3 (which don't work).
+ */
+static void ssl_check_for_safari(SSL *s, const unsigned char *data, const unsigned char *d, int n) {
+       unsigned short type, size;
+       static const unsigned char kSafariExtensionsBlock[] = {
+               0x00, 0x0a,  /* elliptic_curves extension */
+               0x00, 0x08,  /* 8 bytes */
+               0x00, 0x06,  /* 6 bytes of curve ids */
+               0x00, 0x17,  /* P-256 */
+               0x00, 0x18,  /* P-384 */
+               0x00, 0x19,  /* P-521 */
+
+               0x00, 0x0b,  /* ec_point_formats */
+               0x00, 0x02,  /* 2 bytes */
+               0x01,        /* 1 point format */
+               0x00,        /* uncompressed */
+       };
+
+       /* The following is only present in TLS 1.2 */
+       static const unsigned char kSafariTLS12ExtensionsBlock[] = {
+               0x00, 0x0d,  /* signature_algorithms */
+               0x00, 0x0c,  /* 12 bytes */
+               0x00, 0x0a,  /* 10 bytes */
+               0x05, 0x01,  /* SHA-384/RSA */
+               0x04, 0x01,  /* SHA-256/RSA */
+               0x02, 0x01,  /* SHA-1/RSA */
+               0x04, 0x03,  /* SHA-256/ECDSA */
+               0x02, 0x03,  /* SHA-1/ECDSA */
+       };
+
+       if (data >= (d+n-2))
+               return;
+       data += 2;
+
+       if (data > (d+n-4))
+               return;
+       n2s(data,type);
+       n2s(data,size);
+
+       if (type != TLSEXT_TYPE_server_name)
+               return;
+
+       if (data+size > d+n)
+               return;
+       data += size;
+
+       if (TLS1_get_client_version(s) >= TLS1_2_VERSION)
+               {
+               const size_t len1 = sizeof(kSafariExtensionsBlock);
+               const size_t len2 = sizeof(kSafariTLS12ExtensionsBlock);
+
+               if (data + len1 + len2 != d+n)
+                       return;
+               if (memcmp(data, kSafariExtensionsBlock, len1) != 0)
+                       return;
+               if (memcmp(data + len1, kSafariTLS12ExtensionsBlock, len2) != 0)
+                       return;
+               }
+       else
+               {
+               const size_t len = sizeof(kSafariExtensionsBlock);
+
+               if (data + len != d+n)
+                       return;
+               if (memcmp(data, kSafariExtensionsBlock, len) != 0)
+                       return;
+               }
+
+       s->s3->is_probably_safari = 1;
+}
+#endif /* !OPENSSL_NO_EC */
+
 int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, int n, int *al)
        {
        unsigned short type;
@@ -886,6 +969,11 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
                               SSL_TLSEXT_HB_DONT_SEND_REQUESTS);
 #endif
 
+#ifndef OPENSSL_NO_EC
+       if (s->options & SSL_OP_SAFARI_ECDHE_ECDSA_BUG)
+               ssl_check_for_safari(s, data, d, n);
+#endif /* !OPENSSL_NO_EC */
+
        if (data >= (d+n-2))
                goto ri_check;
        n2s(data,len);
index c938bcf00df2258645699ae5813d4448cb2d78af..dfef799be2f4fa0f485441e9e587497d1ac74689 100644 (file)
@@ -415,8 +415,10 @@ sub run_smime_tests {
 }
 
 sub cmp_files {
+    use FileHandle;
     my ( $f1, $f2 ) = @_;
-    my ( $fp1, $fp2 );
+    my $fp1 = FileHandle->new();
+    my $fp2 = FileHandle->new();
 
     my ( $rd1, $rd2 );