Mistake on this page?
Report an issue in GitHub or email us
crys_srp.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 @file
38 @brief This file contains all of the enums and definitions that are used for the
39  CRYS SRP APIs, as well as the APIs themselves.
40 @defgroup crys_srp CryptoCell SRP APIs
41 @{
42 @ingroup cryptocell_api
43 
44 */
45 #ifndef CRYS_SRP_H
46 #define CRYS_SRP_H
47 
48 
49 #include "ssi_pal_types.h"
50 #include "crys_error.h"
51 #include "crys_pka_defs_hw.h"
52 #include "crys_hash.h"
53 #include "crys_rnd.h"
54 
55 
56 #ifdef __cplusplus
57 extern "C"
58 {
59 #endif
60 
61 /*!\internal The following describes the SRP APIs usage for the Device and the Accessory :*
62 
63  Device (User) Accessory (Host)
64 * -------------- -----------------
65 
66  1. CRYS_SRP_HK_INIT(CRYS_SRP_USER, .......) CRYS_SRP_HK_INIT(CRYS_SRP_HOST, .....)
67 
68  2. CRYS_SRP_PwdVerCreate(..)
69 
70  3. CRYS_SRP_UserPubKeyCreate(..) CRYS_SRP_HostPubKeyCreate(..)
71 
72  4. CRYS_SRP_UserProofCalc(..)
73 
74  5. CRYS_SRP_HostProofVerifyAndCalc(..)
75 
76  6. CRYS_SRP_UserProofVerify(..)
77 
78  7. CRYS_SRP_Clear(..) CRYS_SRP_Clear(..)
79 
80  */
81 
82 /************************ Defines ******************************/
83 /*! The SRP modulus sizes. */
84 /*! 1024 bits modulus size. */
85 #define CRYS_SRP_MODULUS_SIZE_1024_BITS 1024
86 /*! 1536 bits modulus size. */
87 #define CRYS_SRP_MODULUS_SIZE_1536_BITS 1536
88 /*! 2048 bits modulus size. */
89 #define CRYS_SRP_MODULUS_SIZE_2048_BITS 2048
90 /*! 3072 bits modulus size. */
91 #define CRYS_SRP_MODULUS_SIZE_3072_BITS 3072
92 
93 /*! Maximal modulus size in bits. */
94 #define CRYS_SRP_MAX_MODULUS_IN_BITS CRYS_SRP_MODULUS_SIZE_3072_BITS
95 /*! Maximal modulus size in bytes. */
96 #define CRYS_SRP_MAX_MODULUS (CRYS_SRP_MAX_MODULUS_IN_BITS/SASI_BITS_IN_BYTE)
97 /*! Maximal modulus size in words. */
98 #define CRYS_SRP_MAX_MODULUS_IN_WORDS (CRYS_SRP_MAX_MODULUS_IN_BITS/SASI_BITS_IN_32BIT_WORD)
99 
100 /*! The SRP private number size range. */
101 /*! Minimal private number size in bits. */
102 #define CRYS_SRP_PRIV_NUM_MIN_SIZE_IN_BITS (256)
103 /*! Minimal private number size in bytes. */
104 #define CRYS_SRP_PRIV_NUM_MIN_SIZE (CRYS_SRP_PRIV_NUM_MIN_SIZE_IN_BITS/SASI_BITS_IN_BYTE)
105 /*! Minimal private number size in words. */
106 #define CRYS_SRP_PRIV_NUM_MIN_SIZE_IN_WORDS (CRYS_SRP_PRIV_NUM_MIN_SIZE_IN_BITS/SASI_BITS_IN_32BIT_WORD)
107 /*! Maximal private number size in bits. */
108 #define CRYS_SRP_PRIV_NUM_MAX_SIZE_IN_BITS (CRYS_SRP_MAX_MODULUS_IN_BITS)
109 /*! Maximal private number size in bytes. */
110 #define CRYS_SRP_PRIV_NUM_MAX_SIZE (CRYS_SRP_PRIV_NUM_MAX_SIZE_IN_BITS/SASI_BITS_IN_BYTE)
111 /*! Maximal private number size in words. */
112 #define CRYS_SRP_PRIV_NUM_MAX_SIZE_IN_WORDS (CRYS_SRP_PRIV_NUM_MAX_SIZE_IN_BITS/SASI_BITS_IN_32BIT_WORD)
113 
114 /*! Maximal SRP HASH digest size in words. */
115 #define CRYS_SRP_MAX_DIGEST_IN_WORDS CRYS_HASH_RESULT_SIZE_IN_WORDS
116 /*! Maximal SRP HASH digest size in bytes. */
117 #define CRYS_SRP_MAX_DIGEST (CRYS_SRP_MAX_DIGEST_IN_WORDS*SASI_32BIT_WORD_SIZE)
118 
119 /*! Minimal salt size in bytes. */
120 #define CRYS_SRP_MIN_SALT_SIZE (8)
121 /*! Minimal salt size in words. */
122 #define CRYS_SRP_MIN_SALT_SIZE_IN_WORDS (CRYS_SRP_MIN_SALT_SIZE/SASI_32BIT_WORD_SIZE)
123 /*! Maximal salt size in bytes. */
124 #define CRYS_SRP_MAX_SALT_SIZE (64)
125 /*! Maximal salt size in words. */
126 #define CRYS_SRP_MAX_SALT_SIZE_IN_WORDS (CRYS_SRP_MAX_SALT_SIZE/SASI_32BIT_WORD_SIZE)
127 
128 /************************ Typedefs ****************************/
129 /*! SRP modulus buffer definition. */
131 
132 /*! SRP digest buffer definition. */
134 
135 /*! SRP secret buffer definition. */
137 
138 /************************ Enums ********************************/
139 
140 /*!
141 SRP supported versions
142 */
143 typedef enum {
144  CRYS_SRP_VER_3 = 0, /*!< VER 3. */
145  CRYS_SRP_VER_6 = 1, /*!< VER 6. */
146  CRYS_SRP_VER_6A = 2, /*!< VER 6A. */
147  CRYS_SRP_VER_HK = 3, /*!< VER 6A. */
148  /*! Maximal number of supported versions.*/
150  /*! Reserved.*/
151  CRYS_SRP_VersionLast= 0x7FFFFFFF,
152 
154 
155 /*!
156 SRP entity type
157 */
158 typedef enum {
159  CRYS_SRP_HOST = 1, /*!< Host entity, called also server, verifier, or Accessory in Home-Kit */
160  CRYS_SRP_USER = 2, /*!< User entity, called also client, or Device in Home-Kit */
161  /*! Maximal number of entities types.*/
163  /*! Reserved.*/
164  CRYS_SRP_EntityLast= 0x7FFFFFFF,
165 
167 
168 /************************ Structs ******************************/
169 
170 /*! Group parameters for the SRP - defines the modulus and the generator used */
171 typedef struct CRYS_SRP_GroupParam_t {
172  /*! SRP modulus.*/
173  CRYS_SRP_Modulus_t modulus;
174  /*! SRP generator.*/
175  uint8_t gen;
176  /*! SRP modulus size in bits .*/
178  /*! SRP valid Np.*/
179  uint32_t validNp;
180  /*! SRP Np buffer.*/
183 
184 /************************ context Structs ******************************/
185 /*! The SRP context prototype */
186 typedef struct CRYS_SRP_Context_t {
187  /*! SRP entitiy type.*/
189  /*! SRP version.*/
191  /*! Group parameter including the modulus information.*/
193  /*! Hash mode.*/
195  /*! Hash digest size.*/
197  /*! Pointer to RND state.*/
199  /*! Pointer to random vector generation function.*/
201  /*! Modulus.*/
202  CRYS_SRP_Modulus_t ephemPriv; // a or b
203  /*! Modulus size.*/
205  /*! User name digest.*/
206  CRYS_SRP_Digest_t userNameDigest; // M
207  /*! Cred digest.*/
208  CRYS_SRP_Digest_t credDigest; // p
209  /*! SRP K multiplier. */ //
210  CRYS_SRP_Digest_t kMult; // k multiplier
212 
213 
214 /************************ SRP common Functions **********************/
215 /****************************************************************************************************/
216 /*!
217 @brief This function initiates the SRP context.
218 
219 @return CRYS_OK on success.
220 @return A non-zero value on failure as defined crys_srp_error.h or crys_hash_error.h.
221 */
222 CIMPORT_C CRYSError_t CRYS_SRP_Init(
223  CRYS_SRP_Entity_t srpType, /*!< [in] SRP entity type. */
224  CRYS_SRP_Version_t srpVer, /*!< [in] SRP version. */
225  CRYS_SRP_Modulus_t srpModulus, /*!< [in] A pointer to the SRP modulus, BE byte buffer. */
226  uint8_t srpGen, /*!< [in] The SRP generator param. */
227  size_t modSizeInBits, /*!< [in] The SRP modulus size in bits:1024, 1536, 2048 & 3072 */
228  CRYS_HASH_OperationMode_t hashMode, /*!< [in] Enumerator defining the HASH mode. */
229  uint8_t *pUserName, /*!< [in] A Pointer to user name. */
230  size_t userNameSize, /*!< [in] The user name buffer size > 0. */
231  uint8_t *pPwd, /*!< [in] A Pointer to user password. */
232  size_t pwdSize, /*!< [in] The user password buffer size > 0 if pPwd is valid. */
233  void *pRndState, /*!< [in] A Pointer to RND context.*/
234  SaSiRndGenerateVectWorkFunc_t rndGenerateVectFunc, /*!< [in] Pointer to random vector generation function.*/
235  CRYS_SRP_Context_t *pCtx /*!< [out] A Pointer to the SRP host context.*/
236 );
237 
238 /*! MACRO definition for a specific SRP initialization function.*/
239 #define CRYS_SRP_HK_INIT(srpType, srpModulus, srpGen, modSizeInBits, pUserName, userNameSize, pPwd, pwdSize, pRndState, rndGenerateVectFunc, pCtx) \
240  CRYS_SRP_Init(srpType, CRYS_SRP_VER_HK, srpModulus, srpGen, modSizeInBits, CRYS_HASH_SHA512_mode, pUserName, userNameSize, pPwd, pwdSize, pRndState, rndGenerateVectFunc, pCtx)
241 
242 
243 /****************************************************************************************************/
244 /*!
245 @brief This function calculates pSalt & password verifier
246 
247 @return CRYS_OK on success.
248 @return A non-zero value on failure as defined crys_srp_error.h, crys_rnd_error.h or crys_hash_error.h.
249 */
251  size_t saltSize, /*!< [in] The size of the random salt to generate,
252  The range is between CRYS_SRP_MIN_SALT_SIZE
253  to CRYS_SRP_MAX_SALT_SIZE. */
254  uint8_t *pSalt, /*!< [out] A Pointer to the pSalt number (s).*/
255  CRYS_SRP_Modulus_t pwdVerifier, /*!< [out] A Pointer to the password verifier (v). */
256  CRYS_SRP_Context_t *pCtx /*!< [out] A Pointer to the SRP context.*/
257 );
258 
259 
260 /****************************************************************************************************/
261 /*!
262 @brief Clears the SRP context.
263 
264 @return CRYS_OK on success.
265 @return A non-zero value on failure as defined crys_srp_error.h.
266 */
267 CIMPORT_C CRYSError_t CRYS_SRP_Clear(
268  CRYS_SRP_Context_t *pCtx /*!< [in/out] A Pointer to the SRP context.*/
269 );
270 
271 
272 /************************ SRP Host Functions **********************/
273 /****************************************************************************************************/
274 /*!
275 @brief This function generates host public & private ephemeral key, known as B & b in RFC
276 
277 @return CRYS_OK on success.
278 @return A non-zero value on failure as defined crys_srp_error.h or crys_rnd_error.h.
279 */
281  size_t ephemPrivSize, /*!< [in] The size of the generated ephemeral private key (b).
282  The range is between CRYS_SRP_PRIV_NUM_MIN_SIZE to
283  CRYS_SRP_PRIV_NUM_MAX_SIZE */
284  CRYS_SRP_Modulus_t pwdVerifier, /*!< [in] A Pointer to the verifier (v). */
285  CRYS_SRP_Modulus_t hostPubKeyB, /*!< [out] A Pointer to the host ephemeral public key (B). */
286  CRYS_SRP_Context_t *pCtx /*!< [in/out] A Pointer to the SRP context.*/
287 );
288 
289 
290 /*!
291 @brief Verifies the user Proof and calculates the Host message proof.
292 
293 @return CRYS_OK on success.
294 @return A non-zero value on failure as defined crys_srp_error.h or crys_hash_error.h.
295 */
297  size_t saltSize, /*!< [in] The size of the random salt,
298  The range is between CRYS_SRP_MIN_SALT_SIZE
299  to CRYS_SRP_MAX_SALT_SIZE. */
300  uint8_t *pSalt, /*!< [in] A Pointer to the pSalt number.*/
301  CRYS_SRP_Modulus_t pwdVerifier, /*!< [in] A Pointer to the password verifier (v). */
302  CRYS_SRP_Modulus_t userPubKeyA, /*!< [in] A Pointer to the user ephemeral public key (A). */
303  CRYS_SRP_Modulus_t hostPubKeyB, /*!< [in] A Pointer to the host ephemeral public key (B). */
304  CRYS_SRP_Digest_t userProof, /*!< [in] A Pointer to the SRP user proof buffer (M1).*/
305  CRYS_SRP_Digest_t hostProof, /*!< [out] A Pointer to the SRP host proof buffer (M2).*/
306  CRYS_SRP_Secret_t sharedSecret, /*!< [out] A Pointer to the SRP shared secret (K).*/
307  CRYS_SRP_Context_t *pCtx /*!< [in] A Pointer to the SRP context.*/
308 );
309 
310 
311 
312 /************************ SRP User Functions **********************/
313 /****************************************************************************************************/
314 /*!
315 @brief This function generates user public & private ephemeral key, known as A & a in RFC
316 
317 @return CRYS_OK on success.
318 @return A non-zero value on failure as defined crys_srp_error.h or crys_rnd_error.h.
319 */
321  size_t ephemPrivSize, /*!< [in] The size of the generated ephemeral private key (a).
322  The range is between CRYS_SRP_PRIV_NUM_MIN_SIZE to
323  CRYS_SRP_PRIV_NUM_MAX_SIZE */
324  CRYS_SRP_Modulus_t userPubKeyA, /*!< [out] A Pointer to the user ephemeral public key (A). */
325  CRYS_SRP_Context_t *pCtx /*!< [in/out] A Pointer to the SRP context.*/
326 );
327 
328 
329 /****************************************************************************************************/
330 /*!
331 @brief This function calculates the user proof.
332 
333 @return CRYS_OK on success.
334 @return A non-zero value on failure as defined crys_srp_error.h or crys_hash_error.h.
335 */
337  size_t saltSize, /*!< [in] The size of the random salt,
338  The range is between CRYS_SRP_MIN_SALT_SIZE
339  to CRYS_SRP_MAX_SALT_SIZE. */
340  uint8_t *pSalt, /*!< [in] A Pointer to the pSalt number.*/
341  CRYS_SRP_Modulus_t userPubKeyA, /*!< [in] A Pointer to the user public ephmeral key (A).*/
342  CRYS_SRP_Modulus_t hostPubKeyB, /*!< [in] A Pointer to the host public ephmeral key (B).*/
343  CRYS_SRP_Digest_t userProof, /*!< [out] A Pointer to the SRP user proof buffer (M1).*/
344  CRYS_SRP_Secret_t sharedSecret, /*!< [out] A Pointer to the SRP shared secret (K).*/
345  CRYS_SRP_Context_t *pCtx /*!< [out] A Pointer to the SRP context.*/
346 );
347 
348 /****************************************************************************************************/
349 /*!
350 @brief This function verifies the host proof
351 
352 @return CRYS_OK on success.
353 @return A non-zero value on failure as defined crys_srp_error.h or crys_hash_error.h.
354 */
356  CRYS_SRP_Secret_t sharedSecret, /*!< [in] A Pointer to the SRP shared secret (K).*/
357  CRYS_SRP_Modulus_t userPubKeyA, /*!< [in] A Pointer to the user public ephmeral key (A).*/
358  CRYS_SRP_Digest_t userProof, /*!< [in] A Pointer to the SRP user proof buffer (M1).*/
359  CRYS_SRP_Digest_t hostProof, /*!< [in] A Pointer to the SRP host proof buffer (M2).*/
360  CRYS_SRP_Context_t *pCtx /*!< [out] A Pointer to the SRP user context.*/
361 );
362 
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 /**
368 @}
369  */
370 #endif /* #ifndef CRYS_SRP_H */
371 
372 
373 
374 
375 
#define CRYS_SRP_MAX_DIGEST
Definition: crys_srp.h:117
size_t ephemPrivSize
Definition: crys_srp.h:204
CRYSError_t CRYS_SRP_HostProofVerifyAndCalc(size_t saltSize, uint8_t *pSalt, CRYS_SRP_Modulus_t pwdVerifier, CRYS_SRP_Modulus_t userPubKeyA, CRYS_SRP_Modulus_t hostPubKeyB, CRYS_SRP_Digest_t userProof, CRYS_SRP_Digest_t hostProof, CRYS_SRP_Secret_t sharedSecret, CRYS_SRP_Context_t *pCtx)
Verifies the user Proof and calculates the Host message proof.
CRYSError_t CRYS_SRP_UserProofVerify(CRYS_SRP_Secret_t sharedSecret, CRYS_SRP_Modulus_t userPubKeyA, CRYS_SRP_Digest_t userProof, CRYS_SRP_Digest_t hostProof, CRYS_SRP_Context_t *pCtx)
This function verifies the host proof.
CRYSError_t CRYS_SRP_UserPubKeyCreate(size_t ephemPrivSize, CRYS_SRP_Modulus_t userPubKeyA, CRYS_SRP_Context_t *pCtx)
This function generates user public & private ephemeral key, known as A & a in RFC.
CRYS_SRP_Digest_t credDigest
Definition: crys_srp.h:208
#define CRYS_PKA_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS
size_t hashDigestSize
Definition: crys_srp.h:196
The file contains all of the enums and definitions that are used in the PKA related code...
CRYS_HASH_OperationMode_t
Definition: crys_hash.h:145
CRYS_SRP_Modulus_t modulus
Definition: crys_srp.h:173
CRYSError_t CRYS_SRP_Init(CRYS_SRP_Entity_t srpType, CRYS_SRP_Version_t srpVer, CRYS_SRP_Modulus_t srpModulus, uint8_t srpGen, size_t modSizeInBits, CRYS_HASH_OperationMode_t hashMode, uint8_t *pUserName, size_t userNameSize, uint8_t *pPwd, size_t pwdSize, void *pRndState, SaSiRndGenerateVectWorkFunc_t rndGenerateVectFunc, CRYS_SRP_Context_t *pCtx)
This function initiates the SRP context.
SaSiRndGenerateVectWorkFunc_t rndGenerateVectFunc
Definition: crys_srp.h:200
uint8_t CRYS_SRP_Modulus_t[(3072/8)]
Definition: crys_srp.h:130
CRYS_SRP_Modulus_t ephemPriv
Definition: crys_srp.h:202
CRYS_SRP_Entity_t
Definition: crys_srp.h:158
CRYSError_t CRYS_SRP_PwdVerCreate(size_t saltSize, uint8_t *pSalt, CRYS_SRP_Modulus_t pwdVerifier, CRYS_SRP_Context_t *pCtx)
This function calculates pSalt & password verifier.
CRYS_RND_State_t * pRndState
Definition: crys_srp.h:198
uint32_t Np[5]
Definition: crys_srp.h:181
uint8_t CRYS_SRP_Digest_t[(16 *(sizeof(uint32_t)))]
Definition: crys_srp.h:133
CRYS_SRP_GroupParam_t groupParam
Definition: crys_srp.h:192
CRYS_SRP_Version_t
Definition: crys_srp.h:143
struct CRYS_SRP_Context_t CRYS_SRP_Context_t
struct CRYS_SRP_GroupParam_t CRYS_SRP_GroupParam_t
This file contains all of the enums and definitions that are used for the CRYS HASH APIs...
CRYS_HASH_OperationMode_t hashMode
Definition: crys_srp.h:194
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
CRYSError_t CRYS_SRP_Clear(CRYS_SRP_Context_t *pCtx)
Clears the SRP context.
CRYS_SRP_Digest_t kMult
Definition: crys_srp.h:210
uint8_t CRYS_SRP_Secret_t[2 *(16 *(sizeof(uint32_t)))]
Definition: crys_srp.h:136
CRYS_SRP_Digest_t userNameDigest
Definition: crys_srp.h:206
This file contains the platform dependent definitions and types.
CRYSError_t CRYS_SRP_UserProofCalc(size_t saltSize, uint8_t *pSalt, CRYS_SRP_Modulus_t userPubKeyA, CRYS_SRP_Modulus_t hostPubKeyB, CRYS_SRP_Digest_t userProof, CRYS_SRP_Secret_t sharedSecret, CRYS_SRP_Context_t *pCtx)
This function calculates the user proof.
#define CRYS_SRP_MAX_MODULUS
Definition: crys_srp.h:96
CRYS_SRP_Version_t srpVer
Definition: crys_srp.h:190
CRYS_SRP_Entity_t srpType
Definition: crys_srp.h:188
CRYSError_t CRYS_SRP_HostPubKeyCreate(size_t ephemPrivSize, CRYS_SRP_Modulus_t pwdVerifier, CRYS_SRP_Modulus_t hostPubKeyB, CRYS_SRP_Context_t *pCtx)
This function generates host public & private ephemeral key, known as B & b in RFC.
uint32_t(* SaSiRndGenerateVectWorkFunc_t)(void *rndState_ptr, uint16_t outSizeBytes, uint8_t *out_ptr)
Definition: crys_rnd.h:206
This module defines the error return code types and the numbering spaces of the error codes for each ...
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.