Missing NULL check on OBJ_dup result in x509_name_canon
[openssl.git] / crypto / ppccap.c
index 76cfdbde8b7ab3f192008dd4af5fb720aeca8c14..712ee799d6dfd830140df627f19d5e8525baaafd 100644 (file)
@@ -1,3 +1,12 @@
+/*
+ * Copyright 2009-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -79,6 +88,7 @@ void sha512_block_data_order(void *ctx, const void *inp, size_t len)
         sha512_block_ppc(ctx, inp, len);
 }
 
+#ifndef OPENSSL_NO_CHACHA
 void ChaCha20_ctr32_int(unsigned char *out, const unsigned char *inp,
                         size_t len, const unsigned int key[8],
                         const unsigned int counter[4]);
@@ -93,7 +103,9 @@ void ChaCha20_ctr32(unsigned char *out, const unsigned char *inp,
         ? ChaCha20_ctr32_vmx(out, inp, len, key, counter)
         : ChaCha20_ctr32_int(out, inp, len, key, counter);
 }
+#endif
 
+#ifndef OPENSSL_NO_POLY1305
 void poly1305_init_int(void *ctx, const unsigned char key[16]);
 void poly1305_blocks(void *ctx, const unsigned char *inp, size_t len,
                          unsigned int padbit);
@@ -117,6 +129,7 @@ int poly1305_init(void *ctx, const unsigned char key[16], void *func[2])
     }
     return 1;
 }
+#endif
 
 static sigjmp_buf ill_jmp;
 static void ill_handler(int sig)
@@ -128,6 +141,7 @@ void OPENSSL_fpu_probe(void);
 void OPENSSL_ppc64_probe(void);
 void OPENSSL_altivec_probe(void);
 void OPENSSL_crypto207_probe(void);
+void OPENSSL_madd300_probe(void);
 
 /*
  * Use a weak reference to getauxval() so we can use it if it is available
@@ -151,6 +165,7 @@ static unsigned long (*getauxval) (unsigned long) = NULL;
 
 #define HWCAP2                  26      /* AT_HWCAP2 */
 #define HWCAP_VEC_CRYPTO        (1U << 25)
+#define HWCAP_ARCH_3_00         (1U << 23)
 
 # if defined(__GNUC__) && __GNUC__>=2
 __attribute__ ((constructor))
@@ -208,6 +223,9 @@ void OPENSSL_cpuid_setup(void)
     if (__power_set(0xffffffffU<<16))           /* POWER8 and later */
         OPENSSL_ppccap_P |= PPC_CRYPTO207;
 
+    if (__power_set(0xffffffffU<<17))           /* POWER9 and later */
+        OPENSSL_ppccap_P |= PPC_MADD300;
+
     return;
 # endif
 #endif
@@ -216,7 +234,7 @@ void OPENSSL_cpuid_setup(void)
         unsigned long hwcap = getauxval(HWCAP);
 
         if (hwcap & HWCAP_FPU) {
-           OPENSSL_ppccap_P |= PPC_FPU;
+            OPENSSL_ppccap_P |= PPC_FPU;
 
             if (sizeof(size_t) == 4) {
                 /* In 32-bit case PPC_FPU64 is always fastest [if option] */
@@ -236,6 +254,10 @@ void OPENSSL_cpuid_setup(void)
                 OPENSSL_ppccap_P |= PPC_CRYPTO207;
         }
 
+        if (hwcap & HWCAP_ARCH_3_00) {
+            OPENSSL_ppccap_P |= PPC_MADD300;
+        }
+
         return;
     }
 
@@ -285,6 +307,11 @@ void OPENSSL_cpuid_setup(void)
         }
     }
 
+    if (sigsetjmp(ill_jmp, 1) == 0) {
+        OPENSSL_madd300_probe();
+        OPENSSL_ppccap_P |= PPC_MADD300;
+    }
+
     sigaction(SIGILL, &ill_oact, NULL);
     sigprocmask(SIG_SETMASK, &oset, NULL);
 }