1 /*
2 * Copyright (C) 2007 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 /**
27 * @file
28 *
29 * Null crypto algorithm
30 */
31
32 #include <string.h>
33 #include <ipxe/crypto.h>
34
digest_null_init(void * ctx __unused)35 static void digest_null_init ( void *ctx __unused ) {
36 /* Do nothing */
37 }
38
digest_null_update(void * ctx __unused,const void * src __unused,size_t len __unused)39 static void digest_null_update ( void *ctx __unused, const void *src __unused,
40 size_t len __unused ) {
41 /* Do nothing */
42 }
43
digest_null_final(void * ctx __unused,void * out __unused)44 static void digest_null_final ( void *ctx __unused, void *out __unused ) {
45 /* Do nothing */
46 }
47
48 struct digest_algorithm digest_null = {
49 .name = "null",
50 .ctxsize = 0,
51 .blocksize = 1,
52 .digestsize = 0,
53 .init = digest_null_init,
54 .update = digest_null_update,
55 .final = digest_null_final,
56 };
57
cipher_null_setkey(void * ctx __unused,const void * key __unused,size_t keylen __unused)58 static int cipher_null_setkey ( void *ctx __unused, const void *key __unused,
59 size_t keylen __unused ) {
60 /* Do nothing */
61 return 0;
62 }
63
cipher_null_setiv(void * ctx __unused,const void * iv __unused)64 static void cipher_null_setiv ( void *ctx __unused,
65 const void *iv __unused ) {
66 /* Do nothing */
67 }
68
cipher_null_encrypt(void * ctx __unused,const void * src,void * dst,size_t len)69 static void cipher_null_encrypt ( void *ctx __unused, const void *src,
70 void *dst, size_t len ) {
71 memcpy ( dst, src, len );
72 }
73
cipher_null_decrypt(void * ctx __unused,const void * src,void * dst,size_t len)74 static void cipher_null_decrypt ( void *ctx __unused, const void *src,
75 void *dst, size_t len ) {
76 memcpy ( dst, src, len );
77 }
78
79 struct cipher_algorithm cipher_null = {
80 .name = "null",
81 .ctxsize = 0,
82 .blocksize = 1,
83 .setkey = cipher_null_setkey,
84 .setiv = cipher_null_setiv,
85 .encrypt = cipher_null_encrypt,
86 .decrypt = cipher_null_decrypt,
87 };
88
pubkey_null_init(void * ctx __unused,const void * key __unused,size_t key_len __unused)89 static int pubkey_null_init ( void *ctx __unused, const void *key __unused,
90 size_t key_len __unused ) {
91 return 0;
92 }
93
pubkey_null_max_len(void * ctx __unused)94 static size_t pubkey_null_max_len ( void *ctx __unused ) {
95 return 0;
96 }
97
pubkey_null_encrypt(void * ctx __unused,const void * plaintext __unused,size_t plaintext_len __unused,void * ciphertext __unused)98 static int pubkey_null_encrypt ( void *ctx __unused,
99 const void *plaintext __unused,
100 size_t plaintext_len __unused,
101 void *ciphertext __unused ) {
102 return 0;
103 }
104
pubkey_null_decrypt(void * ctx __unused,const void * ciphertext __unused,size_t ciphertext_len __unused,void * plaintext __unused)105 static int pubkey_null_decrypt ( void *ctx __unused,
106 const void *ciphertext __unused,
107 size_t ciphertext_len __unused,
108 void *plaintext __unused ) {
109 return 0;
110 }
111
pubkey_null_sign(void * ctx __unused,struct digest_algorithm * digest __unused,const void * value __unused,void * signature __unused)112 static int pubkey_null_sign ( void *ctx __unused,
113 struct digest_algorithm *digest __unused,
114 const void *value __unused,
115 void *signature __unused ) {
116 return 0;
117 }
118
pubkey_null_verify(void * ctx __unused,struct digest_algorithm * digest __unused,const void * value __unused,const void * signature __unused,size_t signature_len __unused)119 static int pubkey_null_verify ( void *ctx __unused,
120 struct digest_algorithm *digest __unused,
121 const void *value __unused,
122 const void *signature __unused ,
123 size_t signature_len __unused ) {
124 return 0;
125 }
126
pubkey_null_final(void * ctx __unused)127 static void pubkey_null_final ( void *ctx __unused ) {
128 /* Do nothing */
129 }
130
131 struct pubkey_algorithm pubkey_null = {
132 .name = "null",
133 .ctxsize = 0,
134 .init = pubkey_null_init,
135 .max_len = pubkey_null_max_len,
136 .encrypt = pubkey_null_encrypt,
137 .decrypt = pubkey_null_decrypt,
138 .sign = pubkey_null_sign,
139 .verify = pubkey_null_verify,
140 .final = pubkey_null_final,
141 };
142