Skip to content

Commit 3ece164

Browse files
committed
CC312: Define a Poly1305 context
To support a multipart flow for the Poly1305 algorithm, the Poly module must expose a context to be retained across calls, i.e. to preserve the state of the operation on the PKA engine. Signed-off-by: Antonio de Angelis <[email protected]> Change-Id: I5b41450a15a8ca163072f16d04568dcadec213b7
1 parent 6f7d168 commit 3ece164

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

lib/ext/cryptocell-312-runtime/codesafe/src/crypto_api/cc3x_sym/driver/chacha_driver.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
2+
* Copyright (c) 2001-2022, Arm Limited and Contributors. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
@@ -260,5 +260,3 @@ drvError_t ProcessChacha(ChachaContext_t *chachaCtx, CCBuffInfo_t *pInputBuffInf
260260

261261
return drvRc;
262262
}
263-
264-

lib/ext/cryptocell-312-runtime/codesafe/src/crypto_api/cc3x_sym/driver/chacha_driver.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
#include "driver_defs.h"
1111

12+
#ifdef __cplusplus
13+
extern "C"
14+
{
15+
#endif
16+
1217
/******************************************************************************
1318
* TYPE DEFINITIONS
1419
******************************************************************************/
@@ -39,7 +44,6 @@ typedef struct ChachaContext {
3944
ChachaState_t state;
4045
} ChachaContext_t;
4146

42-
4347
/******************************************************************************
4448
* FUNCTION PROTOTYPES
4549
******************************************************************************/
@@ -55,6 +59,8 @@ typedef struct ChachaContext {
5559
*/
5660
drvError_t ProcessChacha(ChachaContext_t *chachaCtx, CCBuffInfo_t *pInputBuffInfo, CCBuffInfo_t *pOutputBuffInfo, uint32_t inDataSize);
5761

62+
#ifdef __cplusplus
63+
}
64+
#endif
5865

5966
#endif /* _CHACHA_DRIVER_H */
60-

lib/ext/cryptocell-312-runtime/codesafe/src/crypto_api/pki/poly/poly.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
2+
* Copyright (c) 2001-2022, Arm Limited and Contributors. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
@@ -279,9 +279,8 @@ CCError_t PolyMacCalc(mbedtls_poly_key key, /*!< [in] Poniter to 256 bit
279279
//7. copy acc into macRes
280280
PkaCopyDataFromPkaReg(macRes, CC_POLY_MAC_SIZE_IN_WORDS, ACC_REG);
281281

282-
end_func:
282+
end_func:
283283
PkaFinishAndMutexUnlock(pkaRegsNum);
284284
return rc;
285-
286285
}
287286

lib/ext/cryptocell-312-runtime/codesafe/src/crypto_api/pki/poly/poly.h

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/*
2-
* Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
2+
* Copyright (c) 2001-2022, Arm Limited and Contributors. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

7-
87
#ifndef POLY_H
98
#define POLY_H
109

@@ -16,7 +15,6 @@
1615
#include "cc_error.h"
1716
#include "mbedtls_cc_poly.h"
1817

19-
2018
#ifdef __cplusplus
2119
extern "C"
2220
{
@@ -34,6 +32,32 @@ extern "C"
3432
#define CC_POLY_PKA_REG_SIZE_IN_WORDS (CC_POLY_PKA_REG_SIZE_IN_PKA_WORDS * (CALC_FULL_32BIT_WORDS(CC_PKA_WORD_SIZE_IN_BITS)))
3533
#define CC_POLY_PKA_REG_SIZE_IN_BYTES (CC_POLY_PKA_REG_SIZE_IN_WORDS*CC_32BIT_WORD_SIZE)
3634

35+
/**
36+
* PKA register contexts. Between multipart calls, the PKA engine needs to save
37+
* and restore the register context. It's composed of the clamped key pair
38+
* (r,s) 256 bit long and the value of the accumulator register which is mod P,
39+
* where P is 2^130-5, which in full words is 160 bit long, 5 32-bit words.
40+
*/
41+
typedef struct PolyPkaContext {
42+
uint32_t key[8]; /*!< (r,s) concatenated with r already clamped */
43+
uint32_t acc[5]; /*!< Value of the accumulator modulus P, i.e. [0,2^130-5)*/
44+
} PolyPkaContext_t;
45+
46+
/**
47+
* State information required to support multipart APIs in AEAD for MAC
48+
* computation. As Poly1305 operates on CC_POLY_BLOCK_SIZE_IN BYTES of data
49+
* it needs to cache up to CC_POLY_BLOCK_SIZE_IN_BYTES-1 of the input. But
50+
* for practical reasons (i.e. working on 4-byte aligned buffers) we store an
51+
* entire block of 16 bytes that can be processed in one go without additional
52+
* copies
53+
*/
54+
typedef struct PolyState {
55+
uint32_t msg_state[CC_POLY_BLOCK_SIZE_IN_WORDS]; /*!< Equals 16 bytes of
56+
* data
57+
*/
58+
uint8_t msg_state_size; /*!< Size of the message buffered in msg_state */
59+
PolyPkaContext_t context; /*!< PKA registers context (clamped key, acc) */
60+
} PolyState_t;
3761

3862
/**
3963
* @brief Generates the POLY mac according to RFC 7539 section 2.5.1
@@ -52,4 +76,4 @@ CCError_t PolyMacCalc(mbedtls_poly_key key, /*!< [in] Poniter to 256 bit
5276
}
5377
#endif
5478

55-
#endif //POLY_H
79+
#endif /* POLY_H */

0 commit comments

Comments
 (0)