Lines Matching refs:ctx
183 void mbedtls_chacha20_init( mbedtls_chacha20_context *ctx ) in mbedtls_chacha20_init() argument
185 CHACHA20_VALIDATE( ctx != NULL ); in mbedtls_chacha20_init()
187 mbedtls_platform_zeroize( ctx->state, sizeof( ctx->state ) ); in mbedtls_chacha20_init()
188 mbedtls_platform_zeroize( ctx->keystream8, sizeof( ctx->keystream8 ) ); in mbedtls_chacha20_init()
191 ctx->keystream_bytes_used = CHACHA20_BLOCK_SIZE_BYTES; in mbedtls_chacha20_init()
194 void mbedtls_chacha20_free( mbedtls_chacha20_context *ctx ) in mbedtls_chacha20_free() argument
196 if( ctx != NULL ) in mbedtls_chacha20_free()
198 mbedtls_platform_zeroize( ctx, sizeof( mbedtls_chacha20_context ) ); in mbedtls_chacha20_free()
202 int mbedtls_chacha20_setkey( mbedtls_chacha20_context *ctx, in mbedtls_chacha20_setkey() argument
205 CHACHA20_VALIDATE_RET( ctx != NULL ); in mbedtls_chacha20_setkey()
209 ctx->state[0] = 0x61707865; in mbedtls_chacha20_setkey()
210 ctx->state[1] = 0x3320646e; in mbedtls_chacha20_setkey()
211 ctx->state[2] = 0x79622d32; in mbedtls_chacha20_setkey()
212 ctx->state[3] = 0x6b206574; in mbedtls_chacha20_setkey()
215 ctx->state[4] = BYTES_TO_U32_LE( key, 0 ); in mbedtls_chacha20_setkey()
216 ctx->state[5] = BYTES_TO_U32_LE( key, 4 ); in mbedtls_chacha20_setkey()
217 ctx->state[6] = BYTES_TO_U32_LE( key, 8 ); in mbedtls_chacha20_setkey()
218 ctx->state[7] = BYTES_TO_U32_LE( key, 12 ); in mbedtls_chacha20_setkey()
219 ctx->state[8] = BYTES_TO_U32_LE( key, 16 ); in mbedtls_chacha20_setkey()
220 ctx->state[9] = BYTES_TO_U32_LE( key, 20 ); in mbedtls_chacha20_setkey()
221 ctx->state[10] = BYTES_TO_U32_LE( key, 24 ); in mbedtls_chacha20_setkey()
222 ctx->state[11] = BYTES_TO_U32_LE( key, 28 ); in mbedtls_chacha20_setkey()
227 int mbedtls_chacha20_starts( mbedtls_chacha20_context* ctx, in mbedtls_chacha20_starts() argument
231 CHACHA20_VALIDATE_RET( ctx != NULL ); in mbedtls_chacha20_starts()
235 ctx->state[12] = counter; in mbedtls_chacha20_starts()
238 ctx->state[13] = BYTES_TO_U32_LE( nonce, 0 ); in mbedtls_chacha20_starts()
239 ctx->state[14] = BYTES_TO_U32_LE( nonce, 4 ); in mbedtls_chacha20_starts()
240 ctx->state[15] = BYTES_TO_U32_LE( nonce, 8 ); in mbedtls_chacha20_starts()
242 mbedtls_platform_zeroize( ctx->keystream8, sizeof( ctx->keystream8 ) ); in mbedtls_chacha20_starts()
245 ctx->keystream_bytes_used = CHACHA20_BLOCK_SIZE_BYTES; in mbedtls_chacha20_starts()
250 int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx, in mbedtls_chacha20_update() argument
258 CHACHA20_VALIDATE_RET( ctx != NULL ); in mbedtls_chacha20_update()
263 while( size > 0U && ctx->keystream_bytes_used < CHACHA20_BLOCK_SIZE_BYTES ) in mbedtls_chacha20_update()
266 ^ ctx->keystream8[ctx->keystream_bytes_used]; in mbedtls_chacha20_update()
268 ctx->keystream_bytes_used++; in mbedtls_chacha20_update()
277 chacha20_block( ctx->state, ctx->keystream8 ); in mbedtls_chacha20_update()
278 ctx->state[CHACHA20_CTR_INDEX]++; in mbedtls_chacha20_update()
282 output[offset + i ] = input[offset + i ] ^ ctx->keystream8[i ]; in mbedtls_chacha20_update()
283 output[offset + i+1] = input[offset + i+1] ^ ctx->keystream8[i+1]; in mbedtls_chacha20_update()
284 output[offset + i+2] = input[offset + i+2] ^ ctx->keystream8[i+2]; in mbedtls_chacha20_update()
285 output[offset + i+3] = input[offset + i+3] ^ ctx->keystream8[i+3]; in mbedtls_chacha20_update()
286 output[offset + i+4] = input[offset + i+4] ^ ctx->keystream8[i+4]; in mbedtls_chacha20_update()
287 output[offset + i+5] = input[offset + i+5] ^ ctx->keystream8[i+5]; in mbedtls_chacha20_update()
288 output[offset + i+6] = input[offset + i+6] ^ ctx->keystream8[i+6]; in mbedtls_chacha20_update()
289 output[offset + i+7] = input[offset + i+7] ^ ctx->keystream8[i+7]; in mbedtls_chacha20_update()
300 chacha20_block( ctx->state, ctx->keystream8 ); in mbedtls_chacha20_update()
301 ctx->state[CHACHA20_CTR_INDEX]++; in mbedtls_chacha20_update()
305 output[offset + i] = input[offset + i] ^ ctx->keystream8[i]; in mbedtls_chacha20_update()
308 ctx->keystream_bytes_used = size; in mbedtls_chacha20_update()
322 mbedtls_chacha20_context ctx; in mbedtls_chacha20_crypt() local
330 mbedtls_chacha20_init( &ctx ); in mbedtls_chacha20_crypt()
332 ret = mbedtls_chacha20_setkey( &ctx, key ); in mbedtls_chacha20_crypt()
336 ret = mbedtls_chacha20_starts( &ctx, nonce, counter ); in mbedtls_chacha20_crypt()
340 ret = mbedtls_chacha20_update( &ctx, data_len, input, output ); in mbedtls_chacha20_crypt()
343 mbedtls_chacha20_free( &ctx ); in mbedtls_chacha20_crypt()