Commit f918504f authored by Matt Caswell's avatar Matt Caswell
Browse files

Remove the curve448 specific constant time implementation

Instead we should use the standard OpenSSL constant time routines.

Reviewed-by: default avatarBernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/5105)
parent e0fa6324
Loading
Loading
Loading
Loading
+3 −5
Changes for crypto/ec/curve448/arch_32/arch_intrinsics.h: 3 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -10,16 +10,14 @@
 * Originally written by Mike Hamburg
 */

#include "internal/constant_time_locl.h"

#ifndef __ARCH_ARCH_32_ARCH_INTRINSICS_H__
# define __ARCH_ARCH_32_ARCH_INTRINSICS_H__

# define ARCH_WORD_BITS 32

static ossl_inline uint32_t word_is_zero(uint32_t a)
{
    /* let's hope the compiler isn't clever enough to optimize this. */
    return (((uint64_t)a) - 1) >> 32;
}
#define word_is_zero(a)     constant_time_is_zero_32(a)

static ossl_inline uint64_t widemul(uint32_t a, uint32_t b)
{
−337

File deleted.

+27 −3
Changes for crypto/ec/curve448/field.h: 27 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
#ifndef __GF_H__
# define __GF_H__

# include "constant_time.h"
# include "internal/constant_time_locl.h"
# include <string.h>
# include <assert.h>
# include "word.h"
@@ -128,7 +128,20 @@ static ossl_inline void gf_mulw(gf c, const gf a, int32_t w)
/* Constant time, x = is_z ? z : y */
static ossl_inline void gf_cond_sel(gf x, const gf y, const gf z, mask_t is_z)
{
    constant_time_select_c448(x, y, z, sizeof(gf), is_z, 0);
    size_t i;

    for (i = 0; i < NLIMBS; i++) {
#if ARCH_WORD_BITS == 32
        x[0].limb[i] = constant_time_select_32((uint32_t)is_z,
                                               (uint32_t)(z[0].limb[i]),
                                               (uint32_t)(y[0].limb[i]));
#else
        /* Must be 64 bit */
        x[0].limb[i] = constant_time_select_64((uint64_t)is_z,
                                               (uint64_t)(z[0].limb[i]),
                                               (uint64_t)(y[0].limb[i]));
#endif
    }
}

/* Constant time, if (neg) x=-x; */
@@ -142,7 +155,18 @@ static ossl_inline void gf_cond_neg(gf x, mask_t neg)
/* Constant time, if (swap) (x,y) = (y,x); */
static ossl_inline void gf_cond_swap(gf x, gf_s * RESTRICT y, mask_t swap)
{
    constant_time_cond_swap(x, y, sizeof(gf_s), swap);
    size_t i;

    for (i = 0; i < NLIMBS; i++) {
#if ARCH_WORD_BITS == 32
        constant_time_cond_swap_32((uint32_t)swap, (uint32_t *)&(x[0].limb[i]),
                                   (uint32_t *)&(y->limb[i]));
#else
        /* Must be 64 bit */
        constant_time_cond_swap_64((uint64_t)swap, (uint64_t *)&(x[0].limb[i]),
                                   (uint64_t *)&(y->limb[i]));
#endif
    }
}

#endif                          /* __GF_H__ */
−1
Changes for crypto/ec/curve448/scalar.c: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@
#include <openssl/crypto.h>

#include "word.h"
#include "constant_time.h"
#include "point_448.h"

static const c448_word_t MONTGOMERY_FACTOR = (c448_word_t) 0x3bd440fae918bc5;
−52
Changes for crypto/ec/curve448/word.h: 0 added lines, 52 removed lines.
Original line number Diff line number Diff line
@@ -92,49 +92,21 @@ typedef word_t vecmask_t __attribute__ ((vector_size(32)));

# if defined(__AVX2__)
#  define VECTOR_ALIGNED __attribute__((aligned(32)))
typedef uint32x8_t big_register_t;
typedef uint64x4_t uint64xn_t;
typedef uint32x8_t uint32xn_t;

static ossl_inline big_register_t br_set_to_mask(mask_t x)
{
    uint32_t y = (uint32_t)x;
    big_register_t ret = { y, y, y, y, y, y, y, y };
    return ret;
}
# elif defined(__SSE2__)
#  define VECTOR_ALIGNED __attribute__((aligned(16)))
typedef uint32x4_t big_register_t;
typedef uint64x2_t uint64xn_t;
typedef uint32x4_t uint32xn_t;

static ossl_inline big_register_t br_set_to_mask(mask_t x)
{
    uint32_t y = x;
    big_register_t ret = { y, y, y, y };
    return ret;
}
# elif defined(__ARM_NEON__)
#  define VECTOR_ALIGNED __attribute__((aligned(16)))
typedef uint32x4_t big_register_t;
typedef uint64x2_t uint64xn_t;
typedef uint32x4_t uint32xn_t;

static ossl_inline big_register_t br_set_to_mask(mask_t x)
{
    return vdupq_n_u32(x);
}
# elif !defined(_MSC_VER) \
       && (defined(_WIN64) || defined(__amd64__) || defined(__X86_64__) \
           || defined(__aarch64__))
#  define VECTOR_ALIGNED __attribute__((aligned(8)))
typedef uint64_t big_register_t, uint64xn_t;

typedef uint32_t uint32xn_t;
static ossl_inline big_register_t br_set_to_mask(mask_t x)
{
    return (big_register_t) x;
}
# else
#  ifdef __GNUC__
#   define VECTOR_ALIGNED __attribute__((aligned(4)))
@@ -147,32 +119,8 @@ static ossl_inline big_register_t br_set_to_mask(mask_t x)
#  endif
typedef uint64_t uint64xn_t;
typedef uint32_t uint32xn_t;
typedef uint32_t big_register_t;

static ossl_inline big_register_t br_set_to_mask(mask_t x)
{
    return (big_register_t) x;
}
# endif

# if defined(__AVX2__)
static ossl_inline big_register_t br_is_zero(big_register_t x)
{
    return (big_register_t) (x == br_set_to_mask(0));
}
# elif defined(__SSE2__)
static ossl_inline big_register_t br_is_zero(big_register_t x)
{
    return (big_register_t) _mm_cmpeq_epi32((__m128i) x, _mm_setzero_si128());
}
# elif defined(__ARM_NEON__)
static ossl_inline big_register_t br_is_zero(big_register_t x)
{
    return vceqq_u32(x, x ^ x);
}
# else
#  define br_is_zero word_is_zero
# endif

/* PERF: vectorize vs unroll */
# ifdef __clang__