2017-12-01 18:12:25 +00:00
|
|
|
/*
|
2018-01-18 13:12:46 +00:00
|
|
|
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2017-12-01 18:12:25 +00:00
|
|
|
* Copyright 2015 Cryptography Research, Inc.
|
2017-11-15 15:27:21 +00:00
|
|
|
*
|
2017-12-01 18:12:25 +00:00
|
|
|
* 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
|
2017-11-15 15:27:21 +00:00
|
|
|
*
|
2017-12-01 18:12:25 +00:00
|
|
|
* Originally written by Mike Hamburg
|
2017-11-15 15:27:21 +00:00
|
|
|
*/
|
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
#ifndef __C448_COMMON_H__
|
|
|
|
# define __C448_COMMON_H__ 1
|
2017-11-15 15:27:21 +00:00
|
|
|
|
2017-12-04 11:38:58 +00:00
|
|
|
# include <openssl/e_os2.h>
|
2017-11-15 15:27:21 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-12-04 11:38:58 +00:00
|
|
|
/*
|
|
|
|
* Internal word types. Somewhat tricky. This could be decided separately per
|
|
|
|
* platform. However, the structs do need to be all the same size and
|
|
|
|
* alignment on a given platform to support dynamic linking, since even if you
|
|
|
|
* header was built with eg arch_neon, you might end up linking a library built
|
|
|
|
* with arch_arm32.
|
2017-11-15 15:27:21 +00:00
|
|
|
*/
|
2017-12-05 16:37:57 +00:00
|
|
|
# ifndef C448_WORD_BITS
|
2017-12-04 13:30:53 +00:00
|
|
|
# if (defined(__ILP64__) || defined(__amd64__) || defined(__x86_64__) \
|
|
|
|
|| (((__UINT_FAST32_MAX__)>>30)>>30))
|
2017-12-05 16:37:57 +00:00
|
|
|
# define C448_WORD_BITS 64 /* The number of bits in a word */
|
2017-12-04 11:38:58 +00:00
|
|
|
# else
|
2017-12-05 16:37:57 +00:00
|
|
|
# define C448_WORD_BITS 32 /* The number of bits in a word */
|
2017-12-04 11:38:58 +00:00
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
# if C448_WORD_BITS == 64
|
2017-12-04 13:30:53 +00:00
|
|
|
/* Word size for internal computations */
|
2017-12-05 16:37:57 +00:00
|
|
|
typedef uint64_t c448_word_t;
|
2017-12-04 13:30:53 +00:00
|
|
|
/* Signed word size for internal computations */
|
2017-12-05 16:37:57 +00:00
|
|
|
typedef int64_t c448_sword_t;
|
2017-12-04 13:30:53 +00:00
|
|
|
/* "Boolean" type, will be set to all-zero or all-one (i.e. -1u) */
|
2017-12-05 16:37:57 +00:00
|
|
|
typedef uint64_t c448_bool_t;
|
2017-12-04 13:30:53 +00:00
|
|
|
/* Double-word size for internal computations */
|
2017-12-05 16:37:57 +00:00
|
|
|
typedef __uint128_t c448_dword_t;
|
2017-12-04 13:30:53 +00:00
|
|
|
/* Signed double-word size for internal computations */
|
2017-12-05 16:37:57 +00:00
|
|
|
typedef __int128_t c448_dsword_t;
|
|
|
|
# elif C448_WORD_BITS == 32
|
2017-12-04 13:30:53 +00:00
|
|
|
/* Word size for internal computations */
|
2017-12-05 16:37:57 +00:00
|
|
|
typedef uint32_t c448_word_t;
|
2017-12-04 13:30:53 +00:00
|
|
|
/* Signed word size for internal computations */
|
2017-12-05 16:37:57 +00:00
|
|
|
typedef int32_t c448_sword_t;
|
2017-12-04 13:30:53 +00:00
|
|
|
/* "Boolean" type, will be set to all-zero or all-one (i.e. -1u) */
|
2017-12-05 16:37:57 +00:00
|
|
|
typedef uint32_t c448_bool_t;
|
2017-12-04 13:30:53 +00:00
|
|
|
/* Double-word size for internal computations */
|
2017-12-05 16:37:57 +00:00
|
|
|
typedef uint64_t c448_dword_t;
|
2017-12-04 13:30:53 +00:00
|
|
|
/* Signed double-word size for internal computations */
|
2017-12-05 16:37:57 +00:00
|
|
|
typedef int64_t c448_dsword_t;
|
2017-12-04 11:38:58 +00:00
|
|
|
# else
|
2017-12-05 16:37:57 +00:00
|
|
|
# error "Only supporting C448_WORD_BITS = 32 or 64 for now"
|
2017-12-04 11:38:58 +00:00
|
|
|
# endif
|
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
/* C448_TRUE = -1 so that C448_TRUE & x = x */
|
2017-12-12 14:17:40 +00:00
|
|
|
static const c448_bool_t C448_TRUE = 0 - (c448_bool_t)1;
|
2017-11-15 15:27:21 +00:00
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
/* C448_FALSE = 0 so that C448_FALSE & x = 0 */
|
|
|
|
static const c448_bool_t C448_FALSE = 0;
|
2017-11-15 15:27:21 +00:00
|
|
|
|
2017-12-04 13:30:53 +00:00
|
|
|
/* Another boolean type used to indicate success or failure. */
|
2017-11-15 15:27:21 +00:00
|
|
|
typedef enum {
|
2017-12-05 16:37:57 +00:00
|
|
|
C448_SUCCESS = -1, /**< The operation succeeded. */
|
|
|
|
C448_FAILURE = 0 /**< The operation failed. */
|
|
|
|
} c448_error_t;
|
2017-11-15 15:27:21 +00:00
|
|
|
|
2017-12-04 13:30:53 +00:00
|
|
|
/* Return success if x is true */
|
2017-12-05 16:37:57 +00:00
|
|
|
static ossl_inline c448_error_t c448_succeed_if(c448_bool_t x)
|
2017-12-04 11:38:58 +00:00
|
|
|
{
|
2017-12-05 16:37:57 +00:00
|
|
|
return (c448_error_t) x;
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
2017-12-04 11:38:58 +00:00
|
|
|
|
2017-12-05 16:37:57 +00:00
|
|
|
#endif /* __C448_COMMON_H__ */
|