123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
-
-
- #include <string.h>
- #include <assert.h>
- #include <gpxe/crypto.h>
- #include <gpxe/cbc.h>
-
-
-
-
- static void cbc_xor ( const void *src, void *dst, size_t len ) {
- const uint32_t *srcl = src;
- uint32_t *dstl = dst;
- unsigned int i;
-
-
- assert ( ( len % sizeof ( *srcl ) ) == 0 );
-
- for ( i = 0 ; i < ( len / sizeof ( *srcl ) ) ; i++ )
- dstl[i] ^= srcl[i];
- }
-
-
- void cbc_encrypt ( void *ctx, const void *src, void *dst, size_t len,
- struct cipher_algorithm *raw_cipher, void *cbc_ctx ) {
- size_t blocksize = raw_cipher->blocksize;
-
- assert ( ( len % blocksize ) == 0 );
-
- while ( len ) {
- cbc_xor ( src, cbc_ctx, blocksize );
- cipher_encrypt ( raw_cipher, ctx, cbc_ctx, dst, blocksize );
- memcpy ( cbc_ctx, dst, blocksize );
- dst += blocksize;
- src += blocksize;
- len -= blocksize;
- }
- }
-
-
- void cbc_decrypt ( void *ctx, const void *src, void *dst, size_t len,
- struct cipher_algorithm *raw_cipher, void *cbc_ctx ) {
- size_t blocksize = raw_cipher->blocksize;
-
- assert ( ( len % blocksize ) == 0 );
-
- while ( len ) {
- cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize );
- cbc_xor ( cbc_ctx, dst, blocksize );
- memcpy ( cbc_ctx, src, blocksize );
- dst += blocksize;
- src += blocksize;
- len -= blocksize;
- }
- }
|