Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * The ChaCha stream cipher (RFC7539)
0004  *
0005  * Copyright (C) 2015 Martin Willi
0006  */
0007 
0008 #include <linux/kernel.h>
0009 #include <linux/export.h>
0010 #include <linux/module.h>
0011 
0012 #include <crypto/algapi.h> // for crypto_xor_cpy
0013 #include <crypto/chacha.h>
0014 
0015 void chacha_crypt_generic(u32 *state, u8 *dst, const u8 *src,
0016               unsigned int bytes, int nrounds)
0017 {
0018     /* aligned to potentially speed up crypto_xor() */
0019     u8 stream[CHACHA_BLOCK_SIZE] __aligned(sizeof(long));
0020 
0021     while (bytes >= CHACHA_BLOCK_SIZE) {
0022         chacha_block_generic(state, stream, nrounds);
0023         crypto_xor_cpy(dst, src, stream, CHACHA_BLOCK_SIZE);
0024         bytes -= CHACHA_BLOCK_SIZE;
0025         dst += CHACHA_BLOCK_SIZE;
0026         src += CHACHA_BLOCK_SIZE;
0027     }
0028     if (bytes) {
0029         chacha_block_generic(state, stream, nrounds);
0030         crypto_xor_cpy(dst, src, stream, bytes);
0031     }
0032 }
0033 EXPORT_SYMBOL(chacha_crypt_generic);
0034 
0035 MODULE_LICENSE("GPL");