These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / ipxe / src / crypto / ecb.c
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
26 #include <assert.h>
27 #include <ipxe/crypto.h>
28 #include <ipxe/ecb.h>
29
30 /** @file
31  *
32  * Electronic codebook (ECB)
33  *
34  */
35
36 /**
37  * Encrypt data
38  *
39  * @v ctx               Context
40  * @v src               Data to encrypt
41  * @v dst               Buffer for encrypted data
42  * @v len               Length of data
43  * @v raw_cipher        Underlying cipher algorithm
44  */
45 void ecb_encrypt ( void *ctx, const void *src, void *dst, size_t len,
46                    struct cipher_algorithm *raw_cipher ) {
47         size_t blocksize = raw_cipher->blocksize;
48
49         assert ( ( len % blocksize ) == 0 );
50
51         while ( len ) {
52                 cipher_encrypt ( raw_cipher, ctx, src, dst, blocksize );
53                 dst += blocksize;
54                 src += blocksize;
55                 len -= blocksize;
56         }
57 }
58
59 /**
60  * Decrypt data
61  *
62  * @v ctx               Context
63  * @v src               Data to decrypt
64  * @v dst               Buffer for decrypted data
65  * @v len               Length of data
66  * @v raw_cipher        Underlying cipher algorithm
67  */
68 void ecb_decrypt ( void *ctx, const void *src, void *dst, size_t len,
69                    struct cipher_algorithm *raw_cipher ) {
70         size_t blocksize = raw_cipher->blocksize;
71
72         assert ( ( len % blocksize ) == 0 );
73
74         while ( len ) {
75                 cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize );
76                 dst += blocksize;
77                 src += blocksize;
78                 len -= blocksize;
79         }
80 }