Lines Matching refs:ctx
155 void mbedtls_chacha20_init(mbedtls_chacha20_context *ctx)
157 mbedtls_platform_zeroize(ctx->state, sizeof(ctx->state));
158 mbedtls_platform_zeroize(ctx->keystream8, sizeof(ctx->keystream8));
161 ctx->keystream_bytes_used = CHACHA20_BLOCK_SIZE_BYTES;
164 void mbedtls_chacha20_free(mbedtls_chacha20_context *ctx)
166 if (ctx != NULL) {
167 mbedtls_platform_zeroize(ctx, sizeof(mbedtls_chacha20_context));
171 int mbedtls_chacha20_setkey(mbedtls_chacha20_context *ctx,
175 ctx->state[0] = 0x61707865;
176 ctx->state[1] = 0x3320646e;
177 ctx->state[2] = 0x79622d32;
178 ctx->state[3] = 0x6b206574;
181 ctx->state[4] = MBEDTLS_GET_UINT32_LE(key, 0);
182 ctx->state[5] = MBEDTLS_GET_UINT32_LE(key, 4);
183 ctx->state[6] = MBEDTLS_GET_UINT32_LE(key, 8);
184 ctx->state[7] = MBEDTLS_GET_UINT32_LE(key, 12);
185 ctx->state[8] = MBEDTLS_GET_UINT32_LE(key, 16);
186 ctx->state[9] = MBEDTLS_GET_UINT32_LE(key, 20);
187 ctx->state[10] = MBEDTLS_GET_UINT32_LE(key, 24);
188 ctx->state[11] = MBEDTLS_GET_UINT32_LE(key, 28);
193 int mbedtls_chacha20_starts(mbedtls_chacha20_context *ctx,
198 ctx->state[12] = counter;
201 ctx->state[13] = MBEDTLS_GET_UINT32_LE(nonce, 0);
202 ctx->state[14] = MBEDTLS_GET_UINT32_LE(nonce, 4);
203 ctx->state[15] = MBEDTLS_GET_UINT32_LE(nonce, 8);
205 mbedtls_platform_zeroize(ctx->keystream8, sizeof(ctx->keystream8));
208 ctx->keystream_bytes_used = CHACHA20_BLOCK_SIZE_BYTES;
213 int mbedtls_chacha20_update(mbedtls_chacha20_context *ctx,
221 while (size > 0U && ctx->keystream_bytes_used < CHACHA20_BLOCK_SIZE_BYTES) {
223 ^ ctx->keystream8[ctx->keystream_bytes_used];
225 ctx->keystream_bytes_used++;
233 chacha20_block(ctx->state, ctx->keystream8);
234 ctx->state[CHACHA20_CTR_INDEX]++;
236 mbedtls_xor(output + offset, input + offset, ctx->keystream8, 64U);
245 chacha20_block(ctx->state, ctx->keystream8);
246 ctx->state[CHACHA20_CTR_INDEX]++;
248 mbedtls_xor(output + offset, input + offset, ctx->keystream8, size);
250 ctx->keystream_bytes_used = size;
264 mbedtls_chacha20_context ctx;
267 mbedtls_chacha20_init(&ctx);
269 ret = mbedtls_chacha20_setkey(&ctx, key);
274 ret = mbedtls_chacha20_starts(&ctx, nonce, counter);
279 ret = mbedtls_chacha20_update(&ctx, data_len, input, output);
282 mbedtls_chacha20_free(&ctx);