#include <string.h>
#include <assert.h>
#include <gpxe/crypto.h>
#include <gpxe/cbc.h>
Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| static void | cbc_xor (const void *src, void *dst, size_t len) |
| XOR data blocks. | |
| void | cbc_encrypt (void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher, void *cbc_ctx) |
| Encrypt data. | |
| void | cbc_decrypt (void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher, void *cbc_ctx) |
| Decrypt data. | |
Definition in file cbc.c.
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| static void cbc_xor | ( | const void * | src, | |
| void * | dst, | |||
| size_t | len | |||
| ) | [static] |
XOR data blocks.
| src | Input data | |
| dst | Second input data and output data buffer | |
| len | Length of data |
Definition at line 39 of file cbc.c.
References assert.
Referenced by cbc_decrypt(), and cbc_encrypt().
00039 { 00040 const uint32_t *srcl = src; 00041 uint32_t *dstl = dst; 00042 unsigned int i; 00043 00044 /* Assume that block sizes will always be dword-aligned, for speed */ 00045 assert ( ( len % sizeof ( *srcl ) ) == 0 ); 00046 00047 for ( i = 0 ; i < ( len / sizeof ( *srcl ) ) ; i++ ) 00048 dstl[i] ^= srcl[i]; 00049 }
| void cbc_encrypt | ( | void * | ctx, | |
| const void * | src, | |||
| void * | dst, | |||
| size_t | len, | |||
| struct cipher_algorithm * | raw_cipher, | |||
| void * | cbc_ctx | |||
| ) |
Encrypt data.
| ctx | Context | |
| src | Data to encrypt | |
| dst | Buffer for encrypted data | |
| len | Length of data | |
| raw_cipher | Underlying cipher algorithm | |
| cbc_ctx | CBC context |
Definition at line 61 of file cbc.c.
References assert, cipher_algorithm::blocksize, digest_algorithm::blocksize, cbc_xor(), cipher_encrypt, and memcpy.
00062 { 00063 size_t blocksize = raw_cipher->blocksize; 00064 00065 assert ( ( len % blocksize ) == 0 ); 00066 00067 while ( len ) { 00068 cbc_xor ( src, cbc_ctx, blocksize ); 00069 cipher_encrypt ( raw_cipher, ctx, cbc_ctx, dst, blocksize ); 00070 memcpy ( cbc_ctx, dst, blocksize ); 00071 dst += blocksize; 00072 src += blocksize; 00073 len -= blocksize; 00074 } 00075 }
| void cbc_decrypt | ( | void * | ctx, | |
| const void * | src, | |||
| void * | dst, | |||
| size_t | len, | |||
| struct cipher_algorithm * | raw_cipher, | |||
| void * | cbc_ctx | |||
| ) |
Decrypt data.
| ctx | Context | |
| src | Data to decrypt | |
| dst | Buffer for decrypted data | |
| len | Length of data | |
| raw_cipher | Underlying cipher algorithm | |
| cbc_ctx | CBC context |
Definition at line 87 of file cbc.c.
References assert, cipher_algorithm::blocksize, digest_algorithm::blocksize, cbc_xor(), cipher_decrypt, and memcpy.
00088 { 00089 size_t blocksize = raw_cipher->blocksize; 00090 00091 assert ( ( len % blocksize ) == 0 ); 00092 00093 while ( len ) { 00094 cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize ); 00095 cbc_xor ( cbc_ctx, dst, blocksize ); 00096 memcpy ( cbc_ctx, src, blocksize ); 00097 dst += blocksize; 00098 src += blocksize; 00099 len -= blocksize; 00100 } 00101 }
1.5.7.1