@@ -41,6 +41,129 @@ typedef struct ChachaPolyContext_t {
41
41
bool bAuthenticateInput ; /*!< True when input is used for AEAD authent */
42
42
} ChachaPolyContext_t ;
43
43
44
+ /**
45
+ * \brief Generates an OTK as per RFC7539. This function must be called only
46
+ * after the key has been set on the Chacha20 context
47
+ *
48
+ * \note This function implements the block which generates the one time key
49
+ * to be used for Poly1305 as part of RFC7539 to be generated through
50
+ * Chacha20, i.e.
51
+ * poly1305_key_gen(key, nonce):
52
+ * counter = 0;
53
+ * block = chacha_block(key, counter, nonce)
54
+ * return block[0..31]
55
+ *
56
+ * \param[in,out] context Pointer to the Chacha context to be used for the
57
+ * encryption. Note that this is the Chacha and not
58
+ * the ChachaPoly context because encryption only is
59
+ * required
60
+ * \param[out] otk Buffer to hold the one time key produced.
61
+ * \param[in] otk_size Size in bytes of the otk buffer. Must be at least 32
62
+ */
63
+ psa_status_t cc3xx_chacha20_poly1305_gen_otk (
64
+ ChachaContext_t * context ,
65
+ uint8_t * otk ,
66
+ size_t otk_size );
67
+
68
+ /**
69
+ * \brief Sets the value of the one time key (OTK) to be used by the Poly1305
70
+ * algorithm in a multipart flow.
71
+ *
72
+ * \param[in,out] state Pointer to the Poly1305 state to be used
73
+ * \param[in] otk Buffer containing the OTK to be set in the state
74
+ * \param[in] otk_length Size in bytes of the data in the otk buffer. Must
75
+ * be 32.
76
+ *
77
+ * \return psa_status_t
78
+ */
79
+ psa_status_t cc3xx_chacha20_poly1305_set_otk (
80
+ PolyState_t * state ,
81
+ const uint8_t * otk ,
82
+ size_t otk_length );
83
+
84
+ /**
85
+ * \brief Sets the lengths for the data to be authenticate and for the
86
+ * data to be encrypted. These lengths are used by the algorithm
87
+ * to build the associated AEAD construction as per RFC7539 that
88
+ * is authenticated with Poly1305.
89
+ *
90
+ * \param[in,out] context Context for the multipart Chacha20Poly1305
91
+ * \param[in] ad_length Expected byte length of the additional data
92
+ * \param[in] plaintext_length Expected byte length of the data to encrypt
93
+ *
94
+ * \return psa_status_t
95
+ */
96
+ psa_status_t cc3xx_chacha20_poly1305_set_lengths (
97
+ ChachaPolyContext_t * context ,
98
+ size_t ad_length ,
99
+ size_t plaintext_length );
100
+
101
+ /**
102
+ * \brief Updates the additional data to be authenticated with a new chunk of
103
+ * information
104
+ *
105
+ * \param[in,out] context Context for the multipart Chacha20Poly1305
106
+ * \param[in] input Buffer containing the chunk of additional data
107
+ * \param[in] input_length Size in bytes of the data in the input buffer
108
+ *
109
+ * \return psa_status_t
110
+ */
111
+ psa_status_t cc3xx_chacha20_poly1305_update_ad (
112
+ ChachaPolyContext_t * context ,
113
+ const uint8_t * input ,
114
+ size_t input_length );
115
+
116
+ /**
117
+ * \brief Updates the data to be encrypted or decrypted, based on the type of
118
+ * multipart operation, with a new chunk of information
119
+ *
120
+ * \param[in,out] context Context for the multipart Chacha20Poly1305
121
+ * \param[in] input Buffer containing the chunk of new data
122
+ * \param[in] input_length Size in bytes of the data pointed in input
123
+ * \param[out] output Buffer to hold the processed data
124
+ * \param[in] output_size Size in bytes of the output buffer
125
+ * \param[out] output_length Length in bytes of the processed data
126
+ *
127
+ * \return psa_status_t
128
+ */
129
+ psa_status_t cc3xx_chacha20_poly1305_update (
130
+ ChachaPolyContext_t * context ,
131
+ const uint8_t * input ,
132
+ size_t input_length ,
133
+ uint8_t * output ,
134
+ size_t output_size ,
135
+ size_t * output_length );
136
+
137
+ /**
138
+ * \brief Finalize the multipart AEAD producing the authentication tag
139
+ *
140
+ * \param[in,out] context Context for the multipart Chacha20Poly1305
141
+ * \param[out] tag Buffer containing the produced tag from Poly1305
142
+ * \param[in] tag_size Size in bytes of the tag buffer. Must be >= 16
143
+ * \param[out] tag_length Length in bytes of the tag. On success is 16
144
+ *
145
+ * \return psa_status_t
146
+ */
147
+ psa_status_t cc3xx_chacha20_poly1305_finish (
148
+ ChachaPolyContext_t * context ,
149
+ uint8_t * tag ,
150
+ size_t tag_size ,
151
+ size_t * tag_length );
152
+
153
+ /**
154
+ * \brief Verifies that the tag given as parameter matches the one from the
155
+ * finalization of the multipart AEAD operation
156
+ *
157
+ * \param[in,out] context Context for the multipart Chacha20Poly1305
158
+ * \param[in] tag Buffer containing the tag to verify
159
+ * \param[in] tag_size Size in bytes of the tag buffer
160
+ *
161
+ * \return psa_status_t
162
+ */
163
+ psa_status_t cc3xx_chacha20_poly1305_verify (
164
+ ChachaPolyContext_t * context ,
165
+ const uint8_t * tag ,
166
+ size_t tag_size );
44
167
/**
45
168
* \brief Encrypt and create auth tag with Chacha20-Poly1305
46
169
*/
0 commit comments