Mistake on this page?
Report an issue in GitHub or email us
crys_ec_edw_api.h
Go to the documentation of this file.
1 /**************************************************************************************
2 * Copyright (c) 2016-2017, ARM Limited or its affiliates. All rights reserved *
3 * *
4 * This file and the related binary are licensed under the following license: *
5 * *
6 * ARM Object Code and Header Files License, v1.0 Redistribution. *
7 * *
8 * Redistribution and use of object code, header files, and documentation, without *
9 * modification, are permitted provided that the following conditions are met: *
10 * *
11 * 1) Redistributions must reproduce the above copyright notice and the *
12 * following disclaimer in the documentation and/or other materials *
13 * provided with the distribution. *
14 * *
15 * 2) Unless to the extent explicitly permitted by law, no reverse *
16 * engineering, decompilation, or disassembly of is permitted. *
17 * *
18 * 3) Redistribution and use is permitted solely for the purpose of *
19 * developing or executing applications that are targeted for use *
20 * on an ARM-based product. *
21 * *
22 * DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
23 * CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT *
24 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, *
25 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED *
28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
33 **************************************************************************************/
34 
35 
36 
37 #ifndef CRYS_EC_EDW_API_H
38 #define CRYS_EC_EDW_API_H
39 
40 #include "ssi_pal_types.h"
41 #include "crys_hash.h"
42 #include "crys_rnd.h"
43 #include "crys_pka_defs_hw.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /*!
50 @defgroup cryptocell_ec CryptoCell EC 25519 curve APIs
51 @{
52 @ingroup cryptocell_api
53 @brief This group is the cryptocell EC 25519 curve root group
54 @}
55 
56 @file
57 @brief This file contains the CRYS APIs used for EC EDW (Edwards) ed25519 algorithms.
58 @defgroup crys_ec_edw CryptoCell EC Edwards APIs
59 @{
60 @ingroup cryptocell_ec
61 
62 \note Algorithms of Montgomery and Edwards elliptic curves cryptography were developed by
63  Daniel.J.Bernstein.
64 */
65 
66 /*! EC Edwards ed25519 modulus and order sizes in bits, words and bytes. */
67 /*! EC Edwards modulus size in bits. */
68 #define CRYS_ECEDW_MOD_SIZE_IN_BITS 255U /*!<\internal MOD - EC Edw modulus size*/
69 /*! EC Edwards order size in bits. */
70 #define CRYS_ECEDW_ORD_SIZE_IN_BITS 255U /*!<\internal ORD - EC Edw generator order size*/
71 /*! EC Edwards nodulus size in words. */
72 #define CRYS_ECEDW_MOD_SIZE_IN_32BIT_WORDS ((CRYS_ECEDW_MOD_SIZE_IN_BITS + SASI_BITS_IN_32BIT_WORD - 1) / SASI_BITS_IN_32BIT_WORD)
73 /*! EC Edwards modulus size in bytes. */
74 #define CRYS_ECEDW_MOD_SIZE_IN_BYTES (CRYS_ECEDW_MOD_SIZE_IN_32BIT_WORDS * SASI_32BIT_WORD_SIZE)
75 /*! EC Edwards order size in words. */
76 #define CRYS_ECEDW_ORD_SIZE_IN_32BIT_WORDS ((CRYS_ECEDW_ORD_SIZE_IN_BITS + SASI_BITS_IN_32BIT_WORD - 1) / SASI_BITS_IN_32BIT_WORD)
77 /*! EC Edwards order size in bytes. */
78 #define CRYS_ECEDW_ORD_SIZE_IN_BYTES (CRYS_ECEDW_ORD_SIZE_IN_32BIT_WORDS * SASI_32BIT_WORD_SIZE)
79 
80 /*! Constant sizes of special EC_MONT buffers and arrays */
81 /*! EC Edwards seed size in bytes. */
82 #define CRYS_ECEDW_SEED_BYTES CRYS_ECEDW_MOD_SIZE_IN_BYTES
83 /*! EC Edwards secret key size in bytes. */
84 #define CRYS_ECEDW_SECRET_KEY_BYTES (2 * CRYS_ECEDW_MOD_SIZE_IN_BYTES)
85 /*! EC Edwards signatue size in bytes. */
86 #define CRYS_ECEDW_SIGNATURE_BYTES (2 * CRYS_ECEDW_ORD_SIZE_IN_BYTES)
87 /*! EC Edwards scalar size in bytes. */
88 #define CRYS_ECEDW_SCALAR_BYTES CRYS_ECEDW_ORD_SIZE_IN_BYTES
89 /*! EC Edwards scalar multiplication size in bytes. */
90 #define CRYS_ECEDW_SCALARMULT_BYTES CRYS_ECEDW_MOD_SIZE_IN_BYTES
91 
92 /*! EC_EDW temp buffer size definition. */
93 #define CRYS_ECEDW_TEMP_BUFF_SIZE_IN_32BIT_WORD (10*CRYS_EC_MONT_EDW_MODULUS_MAX_SIZE_IN_WORDS + (sizeof(CRYS_HASHUserContext_t)+SASI_32BIT_WORD_SIZE-1)/SASI_32BIT_WORD_SIZE)
94 
95 /*! EC_EDW temp buffer type definition. */
96 typedef struct {
97  /*! Internal buffer. */
100 
101 
102 /******************************************************************************/
103 /*!
104 @brief The function creates EC Edwards signature on the message.
105 \note Used detached form of signature, separated from the message.
106  Implemented algorithm of Bernstein D. etc. sign ed25519.
107 
108 @return CRYS_OK on success,
109 @return A non-zero value on failure as defined crys_ec_mont_edw_error.h or crys_hash_error.h.
110 */
111 CIMPORT_C CRYSError_t CRYS_ECEDW_Sign (
112  uint8_t *pSign, /*!< [out] Pointer to the detached signature. */
113  size_t *pSignSize, /*!< [in/out] Pointer to the total size of the signature ;
114  In - the buffer size, which (must be at least 2*EC order size);
115  Out - the actual size of output data. */
116  const uint8_t *pMsg, /*!< [in] Pointer to the message. */
117  size_t msgSize, /*!< [in] Message size in bytes: must be less, than
118  (CRYS_HASH_UPDATE_DATA_MAX_SIZE_IN_BYTES - 2*(EC_EDW modulus size)). */
119  const uint8_t *pSignSecrKey, /*!< [in] Pointer to the signer secret key (seed || pulKey) */
120  size_t secrKeySize, /*!< [in] Size of signer secret key in bytes: (must be 2*EC order size). */
121  CRYS_ECEDW_TempBuff_t *pTempBuff /*!< [in] Pointer to the temp buffer. */);
122 
123 
124 
125 /******************************************************************************/
126 /*!
127 @brief The function verifies the EC Edwards ed25519 signature on the message.
128 \note The input signature is in detached form, i.e. separated from the message.
129 
130 @return CRYS_OK on success,
131 @return A non-zero value on failure as defined crys_ec_mont_edw_error.h or crys_hash_error.h.
132 */
134  const uint8_t *pSign, /*!< [in] Pointer to detached signature, i.e. the
135  signature is separated from the message. */
136  size_t signSize, /*!< [in] Size of the signature in bytes, it must be
137  equal to two EC Order size in bytes. */
138  const uint8_t *pSignPublKey, /*!< [in] Pointer to signer public key. */
139  size_t publKeySize, /*!< [in] Size of the signer public key in bytes; must be
140  equal to EC modulus size. */
141  uint8_t *pMsg, /*!< [in] Pointer to the message. */
142  size_t msgSize, /*!< [in] Pointer to the message size in bytes. Must be less than
143  (CRYS_HASH_UPDATE_DATA_MAX_SIZE_IN_BYTES - 2*(EC_EDW modulus size)). */
144  CRYS_ECEDW_TempBuff_t *pTempBuff /*!< [in] Pointer to the temp buffer, for internal use. */);
145 
146 
147 /******************************************************************************/
148 /*!
149 @brief The function randomly generates Ec ed25519 private and public keys
150  using given seed.
151  The generation is performed using EC Edwards ed25519 algorithm.
152 
153 @return CRYS_OK on success,
154 @return A non-zero value on failure as defined crys_ec_mont_edw_error.h or crys_hash_error.h.
155 */
157  const uint8_t *pSeed, /*!< [in] Pointer to the given seed. */
158  size_t seedSize, /*!< [in] Size of the seed in bytes, must be equal the EC order size
159  in bytes. */
160  uint8_t *pSecrKey, /*!< [out] Pointer to the secret key, including the seed, concatenated
161  with the public key. */
162  size_t *pSecrKeySize, /*!< [in/out] Pointer to the size of the secret key buffer in bytes
163  (must be at least 2*EC order size). */
164  uint8_t *pPublKey, /*!< [out] Pointer to the public key. */
165  size_t *pPublKeySize, /*!< [in/out] Pointer to the size of the public key in bytes.
166  In - the size of buffer must be at least EC modulus size;
167  Out - the actual size. */
168  CRYS_ECEDW_TempBuff_t *pTempBuff /*!< [in] Pointer to the temp buffer, for internal use. */);
169 
170 /*******************************************************************/
171 /*!
172  @brief The function randomly generates the EC Edwards ed25519 private and
173  public keys.
174  The generation is performed using EC Edwards ed25519 algorithm.
175 
176 @return CRYS_OK on success,
177 @return A non-zero value on failure as defined crys_ec_mont_edw_error.h, crys_hash_error.h or crys_rnd_error.
178 */
180  uint8_t *pSecrKey, /*!< [out] Pointer to the secret key (including seed and public key). */
181  size_t *pSecrKeySize, /*!< [in/out] Pointer to the size of the secret key in bytes,
182  (must be at least 2*EC order size). */
183  uint8_t *pPublKey, /*!< [out] Pointer to the public key. */
184  size_t *pPublKeySize, /*!< [in/out] - Pointer to the size of the public key in bytes.
185  In - the size of buffer must be at least EC modulus size;
186  Out - the actual size. */
187  void *pRndState, /*!< [in/out] Pointer to the RND state structure. */
188  SaSiRndGenerateVectWorkFunc_t rndGenerateVectFunc, /*!< [in] Pointer to the random vector generation function. */
189  CRYS_ECEDW_TempBuff_t *pTempBuff /*!< [in] Pointer to the temp buffer. */);
190 
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 /**
196 @}
197  */
198 #endif
199 
200 
201 
CRYSError_t CRYS_ECEDW_KeyPair(uint8_t *pSecrKey, size_t *pSecrKeySize, uint8_t *pPublKey, size_t *pPublKeySize, void *pRndState, SaSiRndGenerateVectWorkFunc_t rndGenerateVectFunc, CRYS_ECEDW_TempBuff_t *pTempBuff)
The function randomly generates the EC Edwards ed25519 private and public keys. The generation is per...
The file contains all of the enums and definitions that are used in the PKA related code...
This file contains all of the enums and definitions that are used for the CRYS HASH APIs...
CRYSError_t CRYS_ECEDW_Verify(const uint8_t *pSign, size_t signSize, const uint8_t *pSignPublKey, size_t publKeySize, uint8_t *pMsg, size_t msgSize, CRYS_ECEDW_TempBuff_t *pTempBuff)
The function verifies the EC Edwards ed25519 signature on the message.
#define CRYS_ECEDW_TEMP_BUFF_SIZE_IN_32BIT_WORD
This file contains the CRYS APIs used for random number generation. The random-number generation modu...
uint32_t CRYSError_t
Definition: crys_error.h:253
This file contains the platform dependent definitions and types.
CRYSError_t CRYS_ECEDW_SeedKeyPair(const uint8_t *pSeed, size_t seedSize, uint8_t *pSecrKey, size_t *pSecrKeySize, uint8_t *pPublKey, size_t *pPublKeySize, CRYS_ECEDW_TempBuff_t *pTempBuff)
The function randomly generates Ec ed25519 private and public keys using given seed. The generation is performed using EC Edwards ed25519 algorithm.
uint32_t(* SaSiRndGenerateVectWorkFunc_t)(void *rndState_ptr, uint16_t outSizeBytes, uint8_t *out_ptr)
Definition: crys_rnd.h:206
CRYSError_t CRYS_ECEDW_Sign(uint8_t *pSign, size_t *pSignSize, const uint8_t *pMsg, size_t msgSize, const uint8_t *pSignSecrKey, size_t secrKeySize, CRYS_ECEDW_TempBuff_t *pTempBuff)
The function creates EC Edwards signature on the message.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.