iPXE
ecb.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 FILE_SECBOOT ( PERMITTED );
26 
27 #include <assert.h>
28 #include <ipxe/crypto.h>
29 #include <ipxe/ecb.h>
30 
31 /** @file
32  *
33  * Electronic codebook (ECB)
34  *
35  */
36 
37 /**
38  * Encrypt data
39  *
40  * @v ctx Context
41  * @v src Data to encrypt
42  * @v dst Buffer for encrypted data
43  * @v len Length of data
44  * @v raw_cipher Underlying cipher algorithm
45  */
46 void ecb_encrypt ( void *ctx, const void *src, void *dst, size_t len,
47  struct cipher_algorithm *raw_cipher ) {
48  size_t blocksize = raw_cipher->blocksize;
49 
50  assert ( ( len % blocksize ) == 0 );
51 
52  while ( len ) {
53  cipher_encrypt ( raw_cipher, ctx, src, dst, blocksize );
54  dst += blocksize;
55  src += blocksize;
56  len -= blocksize;
57  }
58 }
59 
60 /**
61  * Decrypt data
62  *
63  * @v ctx Context
64  * @v src Data to decrypt
65  * @v dst Buffer for decrypted data
66  * @v len Length of data
67  * @v raw_cipher Underlying cipher algorithm
68  */
69 void ecb_decrypt ( void *ctx, const void *src, void *dst, size_t len,
70  struct cipher_algorithm *raw_cipher ) {
71  size_t blocksize = raw_cipher->blocksize;
72 
73  assert ( ( len % blocksize ) == 0 );
74 
75  while ( len ) {
76  cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize );
77  dst += blocksize;
78  src += blocksize;
79  len -= blocksize;
80  }
81 }
size_t blocksize
Block size.
Definition: crypto.h:61
void ecb_decrypt(void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher)
Decrypt data.
Definition: ecb.c:69
Cryptographic API.
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
Electronic codebook (ECB)
#define cipher_encrypt(cipher, ctx, src, dst, len)
Definition: crypto.h:251
FILE_SECBOOT(PERMITTED)
Assertions.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static const void * src
Definition: string.h:48
ring len
Length.
Definition: dwmac.h:231
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define cipher_decrypt(cipher, ctx, src, dst, len)
Definition: crypto.h:261
A cipher algorithm.
Definition: crypto.h:51
void ecb_encrypt(void *ctx, const void *src, void *dst, size_t len, struct cipher_algorithm *raw_cipher)
Encrypt data.
Definition: ecb.c:46