Blame crypto/ec/curve448/curve448utils.h

Packit c4476c
/*
Packit c4476c
 * Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
 * Copyright 2015 Cryptography Research, Inc.
Packit c4476c
 *
Packit c4476c
 * Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
 * this file except in compliance with the License.  You can obtain a copy
Packit c4476c
 * in the file LICENSE in the source distribution or at
Packit c4476c
 * https://www.openssl.org/source/license.html
Packit c4476c
 *
Packit c4476c
 * Originally written by Mike Hamburg
Packit c4476c
 */
Packit c4476c
Packit c4476c
#ifndef OSSL_CRYPTO_EC_CURVE448UTILS_H
Packit c4476c
# define OSSL_CRYPTO_EC_CURVE448UTILS_H
Packit c4476c
Packit c4476c
# include <openssl/e_os2.h>
Packit c4476c
Packit c4476c
/*
Packit c4476c
 * Internal word types. Somewhat tricky.  This could be decided separately per
Packit c4476c
 * platform.  However, the structs do need to be all the same size and
Packit c4476c
 * alignment on a given platform to support dynamic linking, since even if you
Packit c4476c
 * header was built with eg arch_neon, you might end up linking a library built
Packit c4476c
 * with arch_arm32.
Packit c4476c
 */
Packit c4476c
# ifndef C448_WORD_BITS
Packit c4476c
#  if (defined(__SIZEOF_INT128__) && (__SIZEOF_INT128__ == 16)) \
Packit c4476c
      && !defined(__sparc__) \
Packit c4476c
      && (!defined(__SIZEOF_LONG__) || (__SIZEOF_LONG__ == 8))
Packit c4476c
Packit c4476c
#   define C448_WORD_BITS 64      /* The number of bits in a word */
Packit c4476c
#  else
Packit c4476c
#   define C448_WORD_BITS 32      /* The number of bits in a word */
Packit c4476c
#  endif
Packit c4476c
# endif
Packit c4476c
Packit c4476c
# if C448_WORD_BITS == 64
Packit c4476c
/* Word size for internal computations */
Packit c4476c
typedef uint64_t c448_word_t;
Packit c4476c
/* Signed word size for internal computations */
Packit c4476c
typedef int64_t c448_sword_t;
Packit c4476c
/* "Boolean" type, will be set to all-zero or all-one (i.e. -1u) */
Packit c4476c
typedef uint64_t c448_bool_t;
Packit c4476c
/* Double-word size for internal computations */
Packit c4476c
typedef __uint128_t c448_dword_t;
Packit c4476c
/* Signed double-word size for internal computations */
Packit c4476c
typedef __int128_t c448_dsword_t;
Packit c4476c
# elif C448_WORD_BITS == 32
Packit c4476c
/* Word size for internal computations */
Packit c4476c
typedef uint32_t c448_word_t;
Packit c4476c
/* Signed word size for internal computations */
Packit c4476c
typedef int32_t c448_sword_t;
Packit c4476c
/* "Boolean" type, will be set to all-zero or all-one (i.e. -1u) */
Packit c4476c
typedef uint32_t c448_bool_t;
Packit c4476c
/* Double-word size for internal computations */
Packit c4476c
typedef uint64_t c448_dword_t;
Packit c4476c
/* Signed double-word size for internal computations */
Packit c4476c
typedef int64_t c448_dsword_t;
Packit c4476c
# else
Packit c4476c
#  error "Only supporting C448_WORD_BITS = 32 or 64 for now"
Packit c4476c
# endif
Packit c4476c
Packit c4476c
/* C448_TRUE = -1 so that C448_TRUE & x = x */
Packit c4476c
# define C448_TRUE      (0 - (c448_bool_t)1)
Packit c4476c
Packit c4476c
/* C448_FALSE = 0 so that C448_FALSE & x = 0 */
Packit c4476c
# define C448_FALSE     0
Packit c4476c
Packit c4476c
/* Another boolean type used to indicate success or failure. */
Packit c4476c
typedef enum {
Packit c4476c
    C448_SUCCESS = -1, /**< The operation succeeded. */
Packit c4476c
    C448_FAILURE = 0   /**< The operation failed. */
Packit c4476c
} c448_error_t;
Packit c4476c
Packit c4476c
/* Return success if x is true */
Packit c4476c
static ossl_inline c448_error_t c448_succeed_if(c448_bool_t x)
Packit c4476c
{
Packit c4476c
    return (c448_error_t) x;
Packit c4476c
}
Packit c4476c
Packit c4476c
#endif                          /* __C448_COMMON_H__ */