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
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_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 * Set key
39 *
40 * @v cipher Cipher algorithm
41 * @v ctx Context
42 * @v key Key
43 * @v keylen Key length
44 * @ret rc Return status code
45 */
46int ecb_setkey ( struct cipher_algorithm *cipher, void *ctx,
47 const void *key, size_t keylen ) {
48 struct cipher_algorithm *raw_cipher = cipher->priv;
49
50 return cipher_setkey ( raw_cipher, ctx, key, keylen );
51}
52
53/**
54 * Encrypt data
55 *
56 * @v cipher Cipher algorithm
57 * @v ctx Context
58 * @v src Data to encrypt
59 * @v dst Buffer for encrypted data
60 * @v len Length of data
61 */
62void ecb_encrypt ( struct cipher_algorithm *cipher, void *ctx,
63 const void *src, void *dst, size_t len ) {
64 struct cipher_algorithm *raw_cipher = cipher->priv;
65 size_t blocksize = raw_cipher->blocksize;
66
67 assert ( ( len % blocksize ) == 0 );
68
69 while ( len ) {
70 cipher_encrypt ( raw_cipher, ctx, src, dst, blocksize );
71 dst += blocksize;
72 src += blocksize;
73 len -= blocksize;
74 }
75}
76
77/**
78 * Decrypt data
79 *
80 * @v cipher Cipher algorithm
81 * @v ctx Context
82 * @v src Data to decrypt
83 * @v dst Buffer for decrypted data
84 * @v len Length of data
85 */
86void ecb_decrypt ( struct cipher_algorithm *cipher, void *ctx,
87 const void *src, void *dst, size_t len ) {
88 struct cipher_algorithm *raw_cipher = cipher->priv;
89 size_t blocksize = raw_cipher->blocksize;
90
91 assert ( ( len % blocksize ) == 0 );
92
93 while ( len ) {
94 cipher_decrypt ( raw_cipher, ctx, src, dst, blocksize );
95 dst += blocksize;
96 src += blocksize;
97 len -= blocksize;
98 }
99}
struct golan_eq_context ctx
Definition CIB_PRM.h:0
union @162305117151260234136356364136041353210355154177 key
static const void * src
Definition string.h:48
Assertions.
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
ring len
Length.
Definition dwmac.h:226
int ecb_setkey(struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
Set key.
Definition ecb.c:46
void ecb_decrypt(struct cipher_algorithm *cipher, void *ctx, const void *src, void *dst, size_t len)
Decrypt data.
Definition ecb.c:86
void ecb_encrypt(struct cipher_algorithm *cipher, void *ctx, const void *src, void *dst, size_t len)
Encrypt data.
Definition ecb.c:62
Electronic codebook (ECB).
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
Cryptographic API.
static int cipher_setkey(struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
Definition crypto.h:310
#define cipher_decrypt(cipher, ctx, src, dst, len)
Definition crypto.h:336
#define cipher_encrypt(cipher, ctx, src, dst, len)
Definition crypto.h:326
A cipher algorithm.
Definition crypto.h:58
void * priv
Algorithm private data.
Definition crypto.h:138
size_t blocksize
Block size.
Definition crypto.h:68