|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit Service |
084de1 |
* Copyright 2014 Cryptography Research, Inc.
|
|
Packit Service |
084de1 |
*
|
|
Packit Service |
084de1 |
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit Service |
084de1 |
* this file except in compliance with the License. You can obtain a copy
|
|
Packit Service |
084de1 |
* in the file LICENSE in the source distribution or at
|
|
Packit Service |
084de1 |
* https://www.openssl.org/source/license.html
|
|
Packit Service |
084de1 |
*
|
|
Packit Service |
084de1 |
* Originally written by Mike Hamburg
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#ifndef OSSL_CRYPTO_EC_CURVE448_WORD_H
|
|
Packit Service |
084de1 |
# define OSSL_CRYPTO_EC_CURVE448_WORD_H
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
# include <string.h>
|
|
Packit Service |
084de1 |
# include <assert.h>
|
|
Packit Service |
084de1 |
# include <stdlib.h>
|
|
Packit Service |
084de1 |
# include <openssl/e_os2.h>
|
|
Packit Service |
084de1 |
# include "arch_intrinsics.h"
|
|
Packit Service |
084de1 |
# include "curve448utils.h"
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
# if (ARCH_WORD_BITS == 64)
|
|
Packit Service |
084de1 |
typedef uint64_t word_t, mask_t;
|
|
Packit Service |
084de1 |
typedef __uint128_t dword_t;
|
|
Packit Service |
084de1 |
typedef int32_t hsword_t;
|
|
Packit Service |
084de1 |
typedef int64_t sword_t;
|
|
Packit Service |
084de1 |
typedef __int128_t dsword_t;
|
|
Packit Service |
084de1 |
# elif (ARCH_WORD_BITS == 32)
|
|
Packit Service |
084de1 |
typedef uint32_t word_t, mask_t;
|
|
Packit Service |
084de1 |
typedef uint64_t dword_t;
|
|
Packit Service |
084de1 |
typedef int16_t hsword_t;
|
|
Packit Service |
084de1 |
typedef int32_t sword_t;
|
|
Packit Service |
084de1 |
typedef int64_t dsword_t;
|
|
Packit Service |
084de1 |
# else
|
|
Packit Service |
084de1 |
# error "For now, we only support 32- and 64-bit architectures."
|
|
Packit Service |
084de1 |
# endif
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Scalar limbs are keyed off of the API word size instead of the arch word
|
|
Packit Service |
084de1 |
* size.
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
# if C448_WORD_BITS == 64
|
|
Packit Service |
084de1 |
# define SC_LIMB(x) (x)
|
|
Packit Service |
084de1 |
# elif C448_WORD_BITS == 32
|
|
Packit Service |
084de1 |
# define SC_LIMB(x) ((uint32_t)(x)),((x) >> 32)
|
|
Packit Service |
084de1 |
# else
|
|
Packit Service |
084de1 |
# error "For now we only support 32- and 64-bit architectures."
|
|
Packit Service |
084de1 |
# endif
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* The plan on booleans: The external interface uses c448_bool_t, but this
|
|
Packit Service |
084de1 |
* might be a different size than our particular arch's word_t (and thus
|
|
Packit Service |
084de1 |
* mask_t). Also, the caller isn't guaranteed to pass it as nonzero. So
|
|
Packit Service |
084de1 |
* bool_to_mask converts word sizes and checks nonzero. On the flip side,
|
|
Packit Service |
084de1 |
* mask_t is always -1 or 0, but it might be a different size than
|
|
Packit Service |
084de1 |
* c448_bool_t. On the third hand, we have success vs boolean types, but
|
|
Packit Service |
084de1 |
* that's handled in common.h: it converts between c448_bool_t and
|
|
Packit Service |
084de1 |
* c448_error_t.
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
static ossl_inline c448_bool_t mask_to_bool(mask_t m)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
return (c448_sword_t)(sword_t)m;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static ossl_inline mask_t bool_to_mask(c448_bool_t m)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
/* On most arches this will be optimized to a simple cast. */
|
|
Packit Service |
084de1 |
mask_t ret = 0;
|
|
Packit Service |
084de1 |
unsigned int i;
|
|
Packit Service |
084de1 |
unsigned int limit = sizeof(c448_bool_t) / sizeof(mask_t);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (limit < 1)
|
|
Packit Service |
084de1 |
limit = 1;
|
|
Packit Service |
084de1 |
for (i = 0; i < limit; i++)
|
|
Packit Service |
084de1 |
ret |= ~word_is_zero(m >> (i * 8 * sizeof(word_t)));
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
return ret;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#endif /* OSSL_CRYPTO_EC_CURVE448_WORD_H */
|