1
1
/*
2
- * Copyright (c) 2001-2019 , Arm Limited and Contributors. All rights reserved.
2
+ * Copyright (c) 2001-2022 , Arm Limited and Contributors. All rights reserved.
3
3
*
4
4
* SPDX-License-Identifier: BSD-3-Clause
5
5
*/
6
6
7
-
8
7
#ifndef POLY_H
9
8
#define POLY_H
10
9
16
15
#include "cc_error.h"
17
16
#include "mbedtls_cc_poly.h"
18
17
19
-
20
18
#ifdef __cplusplus
21
19
extern "C"
22
20
{
@@ -34,6 +32,32 @@ extern "C"
34
32
#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)))
35
33
#define CC_POLY_PKA_REG_SIZE_IN_BYTES (CC_POLY_PKA_REG_SIZE_IN_WORDS*CC_32BIT_WORD_SIZE)
36
34
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 ;
37
61
38
62
/**
39
63
* @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
52
76
}
53
77
#endif
54
78
55
- #endif // POLY_H
79
+ #endif /* POLY_H */
0 commit comments