1 /*
2 * Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2014, Intel Corporation. All Rights Reserved.
4 *
5 * Licensed under the OpenSSL license (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
9 *
10 * Originally written by Shay Gueron (1, 2), and Vlad Krasnov (1)
11 * (1) Intel Corporation, Israel Development Center, Haifa, Israel
12 * (2) University of Haifa, Israel
13 *
14 * Reference:
15 * S.Gueron and V.Krasnov, "Fast Prime Field Elliptic Curve Cryptography with
16 * 256 Bit Primes"
17 */
18
19 #ifndef OPENSSL_HEADER_EC_P256_SHARED_H
20 #define OPENSSL_HEADER_EC_P256_SHARED_H
21
22 #include "ring-core/base.h"
23
24 #include "../bn/internal.h"
25
26 #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && \
27 !defined(OPENSSL_SMALL)
28 # define OPENSSL_USE_NISTZ256
29 #endif
30
31 // P-256 field operations.
32 //
33 // An element mod P in P-256 is represented as a little-endian array of
34 // |P256_LIMBS| |BN_ULONG|s, spanning the full range of values.
35 //
36 // The following functions take fully-reduced inputs mod P and give
37 // fully-reduced outputs. They may be used in-place.
38
39 #define P256_LIMBS (256 / BN_BITS2)
40
41 // A P256_POINT represents a P-256 point in Jacobian coordinates.
42 // All coordinates are in the Montgomery domain.
43 typedef struct {
44 BN_ULONG X[P256_LIMBS];
45 BN_ULONG Y[P256_LIMBS];
46 BN_ULONG Z[P256_LIMBS];
47 } P256_POINT;
48
49 typedef unsigned char P256_SCALAR_BYTES[33];
50
p256_scalar_bytes_from_limbs(P256_SCALAR_BYTES bytes_out,const BN_ULONG limbs[P256_LIMBS])51 static inline void p256_scalar_bytes_from_limbs(
52 P256_SCALAR_BYTES bytes_out, const BN_ULONG limbs[P256_LIMBS]) {
53 OPENSSL_memcpy(bytes_out, limbs, 32);
54 bytes_out[32] = 0;
55 }
56
57 #endif
58