Browse Source

[crypto] Split crypto_algorithm into {digest,cipher,pubkey}_algorithm

The various types of cryptographic algorithm are fundamentally
different, and it was probably a mistake to try to handle them via a
single common type.

pubkey_algorithm is a placeholder type for now.
tags/v0.9.7
Michael Brown 15 years ago
parent
commit
a3219b24a8

+ 3
- 3
src/crypto/axtls_aes.c View File

59
 	AES_cbc_decrypt ( &aesctx->ctx, data, dst, len );
59
 	AES_cbc_decrypt ( &aesctx->ctx, data, dst, len );
60
 }
60
 }
61
 
61
 
62
-struct crypto_algorithm aes_cbc_algorithm = {
62
+struct cipher_algorithm aes_cbc_algorithm = {
63
 	.name		= "aes_cbc",
63
 	.name		= "aes_cbc",
64
 	.ctxsize	= sizeof ( struct aes_cbc_context ),
64
 	.ctxsize	= sizeof ( struct aes_cbc_context ),
65
 	.blocksize	= 16,
65
 	.blocksize	= 16,
66
 	.setkey		= aes_cbc_setkey,
66
 	.setkey		= aes_cbc_setkey,
67
 	.setiv		= aes_cbc_setiv,
67
 	.setiv		= aes_cbc_setiv,
68
-	.encode		= aes_cbc_encrypt,
69
-	.decode		= aes_cbc_decrypt,
68
+	.encrypt	= aes_cbc_encrypt,
69
+	.decrypt	= aes_cbc_decrypt,
70
 };
70
 };

+ 3
- 4
src/crypto/axtls_sha1.c View File

6
 	SHA1Init ( ctx );
6
 	SHA1Init ( ctx );
7
 }
7
 }
8
 
8
 
9
-static void sha1_update ( void *ctx, const void *data, void *dst __unused,
10
-			  size_t len ) {
9
+static void sha1_update ( void *ctx, const void *data, size_t len ) {
11
 	SHA1Update ( ctx, data, len );
10
 	SHA1Update ( ctx, data, len );
12
 }
11
 }
13
 
12
 
15
 	SHA1Final ( ctx, out );
14
 	SHA1Final ( ctx, out );
16
 }
15
 }
17
 
16
 
18
-struct crypto_algorithm sha1_algorithm = {
17
+struct digest_algorithm sha1_algorithm = {
19
 	.name		= "sha1",
18
 	.name		= "sha1",
20
 	.ctxsize	= SHA1_CTX_SIZE,
19
 	.ctxsize	= SHA1_CTX_SIZE,
21
 	.blocksize	= 64,
20
 	.blocksize	= 64,
22
 	.digestsize	= SHA1_DIGEST_SIZE,
21
 	.digestsize	= SHA1_DIGEST_SIZE,
23
 	.init		= sha1_init,
22
 	.init		= sha1_init,
24
-	.encode		= sha1_update,
23
+	.update		= sha1_update,
25
 	.final		= sha1_final,
24
 	.final		= sha1_final,
26
 };
25
 };

+ 1
- 1
src/crypto/chap.c View File

42
  * eventually be freed by a call to chap_finish().
42
  * eventually be freed by a call to chap_finish().
43
  */
43
  */
44
 int chap_init ( struct chap_response *chap,
44
 int chap_init ( struct chap_response *chap,
45
-		struct crypto_algorithm *digest ) {
45
+		struct digest_algorithm *digest ) {
46
 	size_t state_len;
46
 	size_t state_len;
47
 	void *state;
47
 	void *state;
48
 
48
 

+ 6
- 6
src/crypto/cipher.c View File

2
 #include <errno.h>
2
 #include <errno.h>
3
 #include <gpxe/crypto.h>
3
 #include <gpxe/crypto.h>
4
 
4
 
5
-int cipher_encrypt ( struct crypto_algorithm *crypto,
5
+int cipher_encrypt ( struct cipher_algorithm *cipher,
6
 		     void *ctx, const void *src, void *dst,
6
 		     void *ctx, const void *src, void *dst,
7
 		     size_t len ) {
7
 		     size_t len ) {
8
-	if ( ( len & ( crypto->blocksize - 1 ) ) ) {
8
+	if ( ( len & ( cipher->blocksize - 1 ) ) ) {
9
 		return -EINVAL;
9
 		return -EINVAL;
10
 	}
10
 	}
11
-	crypto->encode ( ctx, src, dst, len );
11
+	cipher->encrypt ( ctx, src, dst, len );
12
 	return 0;
12
 	return 0;
13
 }
13
 }
14
 
14
 
15
-int cipher_decrypt ( struct crypto_algorithm *crypto,
15
+int cipher_decrypt ( struct cipher_algorithm *cipher,
16
 		     void *ctx, const void *src, void *dst,
16
 		     void *ctx, const void *src, void *dst,
17
 		     size_t len ) {
17
 		     size_t len ) {
18
-	if ( ( len & ( crypto->blocksize - 1 ) ) ) {
18
+	if ( ( len & ( cipher->blocksize - 1 ) ) ) {
19
 		return -EINVAL;
19
 		return -EINVAL;
20
 	}
20
 	}
21
-	crypto->decode ( ctx, src, dst, len );
21
+	cipher->decrypt ( ctx, src, dst, len );
22
 	return 0;
22
 	return 0;
23
 }
23
 }
24
 
24
 

+ 39
- 23
src/crypto/crypto_null.c View File

25
 #include <string.h>
25
 #include <string.h>
26
 #include <gpxe/crypto.h>
26
 #include <gpxe/crypto.h>
27
 
27
 
28
-static void null_init ( void *ctx __unused ) {
28
+static void digest_null_init ( void *ctx __unused ) {
29
 	/* Do nothing */
29
 	/* Do nothing */
30
 }
30
 }
31
 
31
 
32
-static int null_setkey ( void *ctx __unused, const void *key __unused,
33
-			 size_t keylen __unused ) {
32
+static void digest_null_update ( void *ctx __unused, const void *src __unused,
33
+				 size_t len __unused ) {
34
 	/* Do nothing */
34
 	/* Do nothing */
35
-	return 0;
36
 }
35
 }
37
 
36
 
38
-static void null_setiv ( void *ctx __unused, const void *iv __unused ) {
37
+static void digest_null_final ( void *ctx __unused, void *out __unused ) {
39
 	/* Do nothing */
38
 	/* Do nothing */
40
 }
39
 }
41
 
40
 
42
-static void null_encode ( void *ctx __unused, const void *src,
43
-			  void *dst, size_t len ) {
44
-	if ( dst )
45
-		memcpy ( dst, src, len );
46
-}
41
+struct digest_algorithm digest_null = {
42
+	.name = "null",
43
+	.ctxsize = 0,
44
+	.blocksize = 1,
45
+	.digestsize = 0,
46
+	.init = digest_null_init,
47
+	.update = digest_null_update,
48
+	.final = digest_null_final,
49
+};
47
 
50
 
48
-static void null_decode ( void *ctx __unused, const void *src,
49
-			  void *dst, size_t len ) {
50
-	if ( dst )
51
-		memcpy ( dst, src, len );
51
+static int cipher_null_setkey ( void *ctx __unused, const void *key __unused,
52
+				size_t keylen __unused ) {
53
+	/* Do nothing */
54
+	return 0;
52
 }
55
 }
53
 
56
 
54
-static void null_final ( void *ctx __unused, void *out __unused ) {
57
+static void cipher_null_setiv ( void *ctx __unused,
58
+				const void *iv __unused ) {
55
 	/* Do nothing */
59
 	/* Do nothing */
56
 }
60
 }
57
 
61
 
58
-struct crypto_algorithm crypto_null = {
62
+static void cipher_null_encrypt ( void *ctx __unused, const void *src,
63
+				  void *dst, size_t len ) {
64
+	memcpy ( dst, src, len );
65
+}
66
+
67
+static void cipher_null_decrypt ( void *ctx __unused, const void *src,
68
+				  void *dst, size_t len ) {
69
+	memcpy ( dst, src, len );
70
+}
71
+
72
+struct cipher_algorithm cipher_null = {
59
 	.name = "null",
73
 	.name = "null",
60
 	.ctxsize = 0,
74
 	.ctxsize = 0,
61
 	.blocksize = 1,
75
 	.blocksize = 1,
62
-	.digestsize = 0,
63
-	.init = null_init,
64
-	.setkey = null_setkey,
65
-	.setiv = null_setiv,
66
-	.encode = null_encode,
67
-	.decode = null_decode,
68
-	.final = null_final,
76
+	.setkey = cipher_null_setkey,
77
+	.setiv = cipher_null_setiv,
78
+	.encrypt = cipher_null_encrypt,
79
+	.decrypt = cipher_null_decrypt,
80
+};
81
+
82
+struct pubkey_algorithm pubkey_null = {
83
+	.name = "null",
84
+	.ctxsize = 0,
69
 };
85
 };

+ 3
- 3
src/crypto/hmac.c View File

35
  * @v key		Key
35
  * @v key		Key
36
  * @v key_len		Length of key
36
  * @v key_len		Length of key
37
  */
37
  */
38
-static void hmac_reduce_key ( struct crypto_algorithm *digest,
38
+static void hmac_reduce_key ( struct digest_algorithm *digest,
39
 			      void *key, size_t *key_len ) {
39
 			      void *key, size_t *key_len ) {
40
 	uint8_t digest_ctx[digest->ctxsize];
40
 	uint8_t digest_ctx[digest->ctxsize];
41
 
41
 
58
  * will be replaced with its own digest, and key_len will be updated
58
  * will be replaced with its own digest, and key_len will be updated
59
  * accordingly).
59
  * accordingly).
60
  */
60
  */
61
-void hmac_init ( struct crypto_algorithm *digest, void *digest_ctx,
61
+void hmac_init ( struct digest_algorithm *digest, void *digest_ctx,
62
 		 void *key, size_t *key_len ) {
62
 		 void *key, size_t *key_len ) {
63
 	unsigned char k_ipad[digest->blocksize];
63
 	unsigned char k_ipad[digest->blocksize];
64
 	unsigned int i;
64
 	unsigned int i;
93
  * will be replaced with its own digest, and key_len will be updated
93
  * will be replaced with its own digest, and key_len will be updated
94
  * accordingly).
94
  * accordingly).
95
  */
95
  */
96
-void hmac_final ( struct crypto_algorithm *digest, void *digest_ctx,
96
+void hmac_final ( struct digest_algorithm *digest, void *digest_ctx,
97
 		  void *key, size_t *key_len, void *hmac ) {
97
 		  void *key, size_t *key_len, void *hmac ) {
98
 	unsigned char k_opad[digest->blocksize];
98
 	unsigned char k_opad[digest->blocksize];
99
 	unsigned int i;
99
 	unsigned int i;

+ 3
- 4
src/crypto/md5.c View File

167
 	mctx->byte_count = 0;
167
 	mctx->byte_count = 0;
168
 }
168
 }
169
 
169
 
170
-static void md5_update(void *context, const void *data, void *dst __unused,
171
-		       size_t len)
170
+static void md5_update(void *context, const void *data, size_t len)
172
 {
171
 {
173
 	struct md5_ctx *mctx = context;
172
 	struct md5_ctx *mctx = context;
174
 	const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
173
 	const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
224
 	memset(mctx, 0, sizeof(*mctx));
223
 	memset(mctx, 0, sizeof(*mctx));
225
 }
224
 }
226
 
225
 
227
-struct crypto_algorithm md5_algorithm = {
226
+struct digest_algorithm md5_algorithm = {
228
 	.name		= "md5",
227
 	.name		= "md5",
229
 	.ctxsize	= MD5_CTX_SIZE,
228
 	.ctxsize	= MD5_CTX_SIZE,
230
 	.blocksize	= ( MD5_BLOCK_WORDS * 4 ),
229
 	.blocksize	= ( MD5_BLOCK_WORDS * 4 ),
231
 	.digestsize	= MD5_DIGEST_SIZE,
230
 	.digestsize	= MD5_DIGEST_SIZE,
232
 	.init		= md5_init,
231
 	.init		= md5_init,
233
-	.encode		= md5_update,
232
+	.update		= md5_update,
234
 	.final		= md5_final,
233
 	.final		= md5_final,
235
 };
234
 };

+ 2
- 2
src/include/gpxe/aes.h View File

1
 #ifndef _GPXE_AES_H
1
 #ifndef _GPXE_AES_H
2
 #define _GPXE_AES_H
2
 #define _GPXE_AES_H
3
 
3
 
4
-struct crypto_algorithm;
4
+struct cipher_algorithm;
5
 
5
 
6
-extern struct crypto_algorithm aes_cbc_algorithm;
6
+extern struct cipher_algorithm aes_cbc_algorithm;
7
 
7
 
8
 #endif /* _GPXE_AES_H */
8
 #endif /* _GPXE_AES_H */

+ 3
- 3
src/include/gpxe/chap.h View File

10
 #include <stdint.h>
10
 #include <stdint.h>
11
 #include <gpxe/md5.h>
11
 #include <gpxe/md5.h>
12
 
12
 
13
-struct crypto_algorithm;
13
+struct digest_algorithm;
14
 
14
 
15
 /** A CHAP response */
15
 /** A CHAP response */
16
 struct chap_response {
16
 struct chap_response {
17
 	/** Digest algorithm used for the response */
17
 	/** Digest algorithm used for the response */
18
-	struct crypto_algorithm *digest;
18
+	struct digest_algorithm *digest;
19
 	/** Context used by the digest algorithm */
19
 	/** Context used by the digest algorithm */
20
 	uint8_t *digest_context;
20
 	uint8_t *digest_context;
21
 	/** CHAP response */
21
 	/** CHAP response */
25
 };
25
 };
26
 
26
 
27
 extern int chap_init ( struct chap_response *chap,
27
 extern int chap_init ( struct chap_response *chap,
28
-		       struct crypto_algorithm *digest );
28
+		       struct digest_algorithm *digest );
29
 extern void chap_update ( struct chap_response *chap, const void *data,
29
 extern void chap_update ( struct chap_response *chap, const void *data,
30
 			  size_t len );
30
 			  size_t len );
31
 extern void chap_respond ( struct chap_response *chap );
31
 extern void chap_respond ( struct chap_response *chap );

+ 68
- 43
src/include/gpxe/crypto.h View File

10
 #include <stdint.h>
10
 #include <stdint.h>
11
 #include <stddef.h>
11
 #include <stddef.h>
12
 
12
 
13
-/** A cryptographic algorithm */
14
-struct crypto_algorithm {
13
+/** A message digest algorithm */
14
+struct digest_algorithm {
15
 	/** Algorithm name */
15
 	/** Algorithm name */
16
 	const char *name;
16
 	const char *name;
17
 	/** Context size */
17
 	/** Context size */
18
 	size_t ctxsize;
18
 	size_t ctxsize;
19
 	/** Block size */
19
 	/** Block size */
20
 	size_t blocksize;
20
 	size_t blocksize;
21
-	/** Final output size */
21
+	/** Digest size */
22
 	size_t digestsize;
22
 	size_t digestsize;
23
-	/** Initialise algorithm
23
+	/** Initialise digest
24
 	 *
24
 	 *
25
 	 * @v ctx		Context
25
 	 * @v ctx		Context
26
 	 */
26
 	 */
27
 	void ( * init ) ( void *ctx );
27
 	void ( * init ) ( void *ctx );
28
+	/** Update digest with new data
29
+	 *
30
+	 * @v ctx		Context
31
+	 * @v src		Data to digest
32
+	 * @v len		Length of data
33
+	 *
34
+	 * @v len is not necessarily a multiple of @c blocksize.
35
+	 */
36
+	void ( * update ) ( void *ctx, const void *src, size_t len );
37
+	/** Finalise digest
38
+	 *
39
+	 * @v ctx		Context
40
+	 * @v out		Buffer for digest output
41
+	 */
42
+	void ( * final ) ( void *ctx, void *out );
43
+};
44
+
45
+/** A cipher algorithm */
46
+struct cipher_algorithm {
47
+	/** Algorithm name */
48
+	const char *name;
49
+	/** Context size */
50
+	size_t ctxsize;
51
+	/** Block size */
52
+	size_t blocksize;
28
 	/** Set key
53
 	/** Set key
29
 	 *
54
 	 *
30
 	 * @v ctx		Context
55
 	 * @v ctx		Context
38
 	 * @v ctx		Context
63
 	 * @v ctx		Context
39
 	 * @v iv		Initialisation vector
64
 	 * @v iv		Initialisation vector
40
 	 */
65
 	 */
41
-	void ( *setiv ) ( void *ctx, const void *iv );
42
-	/** Encode data
66
+	void ( * setiv ) ( void *ctx, const void *iv );
67
+	/** Encrypt data
43
 	 *
68
 	 *
44
 	 * @v ctx		Context
69
 	 * @v ctx		Context
45
-	 * @v src		Data to encode
46
-	 * @v dst		Encoded data, or NULL
70
+	 * @v src		Data to encrypt
71
+	 * @v dst		Buffer for encrypted data
47
 	 * @v len		Length of data
72
 	 * @v len		Length of data
48
 	 * @ret rc		Return status code
73
 	 * @ret rc		Return status code
49
 	 *
74
 	 *
50
-	 * For a cipher algorithm, the enciphered data should be
51
-	 * placed in @c dst.  For a digest algorithm, only the digest
52
-	 * state should be updated, and @c dst will be NULL.
53
-	 *
54
 	 * @v len is guaranteed to be a multiple of @c blocksize.
75
 	 * @v len is guaranteed to be a multiple of @c blocksize.
55
 	 */
76
 	 */
56
-	void ( * encode ) ( void *ctx, const void *src, void *dst,
57
-			    size_t len );
58
-	/** Decode data
77
+	void ( * encrypt ) ( void *ctx, const void *src, void *dst,
78
+			     size_t len );
79
+	/** Decrypt data
59
 	 *
80
 	 *
60
 	 * @v ctx		Context
81
 	 * @v ctx		Context
61
-	 * @v src		Data to decode
62
-	 * @v dst		Decoded data
82
+	 * @v src		Data to decrypt
83
+	 * @v dst		Buffer for decrypted data
63
 	 * @v len		Length of data
84
 	 * @v len		Length of data
64
 	 * @ret rc		Return status code
85
 	 * @ret rc		Return status code
65
 	 *
86
 	 *
66
 	 * @v len is guaranteed to be a multiple of @c blocksize.
87
 	 * @v len is guaranteed to be a multiple of @c blocksize.
67
 	 */
88
 	 */
68
-	void ( * decode ) ( void *ctx, const void *src, void *dst,
69
-			    size_t len );
70
-	/** Finalise algorithm
71
-	 *
72
-	 * @v ctx		Context
73
-	 * @v out		Algorithm final output
74
-	 */
75
-	void ( * final ) ( void *ctx, void *out );
89
+	void ( * decrypt ) ( void *ctx, const void *src, void *dst,
90
+			     size_t len );
91
+};
92
+
93
+/** A public key algorithm */
94
+struct pubkey_algorithm {
95
+	/** Algorithm name */
96
+	const char *name;
97
+	/** Context size */
98
+	size_t ctxsize;
76
 };
99
 };
77
 
100
 
78
-static inline void digest_init ( struct crypto_algorithm *crypto,
101
+static inline void digest_init ( struct digest_algorithm *digest,
79
 				 void *ctx ) {
102
 				 void *ctx ) {
80
-	crypto->init ( ctx );
103
+	digest->init ( ctx );
81
 }
104
 }
82
 
105
 
83
-static inline void digest_update ( struct crypto_algorithm *crypto,
106
+static inline void digest_update ( struct digest_algorithm *digest,
84
 				   void *ctx, const void *data, size_t len ) {
107
 				   void *ctx, const void *data, size_t len ) {
85
-	crypto->encode ( ctx, data, NULL, len );
108
+	digest->update ( ctx, data, len );
86
 }
109
 }
87
 
110
 
88
-static inline void digest_final ( struct crypto_algorithm *crypto,
111
+static inline void digest_final ( struct digest_algorithm *digest,
89
 				  void *ctx, void *out ) {
112
 				  void *ctx, void *out ) {
90
-	crypto->final ( ctx, out );
113
+	digest->final ( ctx, out );
91
 }
114
 }
92
 
115
 
93
-static inline void cipher_setiv ( struct crypto_algorithm *crypto,
94
-				  void *ctx, const void *iv ) {
95
-	crypto->setiv ( ctx, iv );
96
-}
97
-
98
-static inline int cipher_setkey ( struct crypto_algorithm *crypto,
116
+static inline int cipher_setkey ( struct cipher_algorithm *cipher,
99
 				  void *ctx, const void *key, size_t keylen ) {
117
 				  void *ctx, const void *key, size_t keylen ) {
100
-	return crypto->setkey ( ctx, key, keylen );
118
+	return cipher->setkey ( ctx, key, keylen );
101
 }
119
 }
102
 
120
 
103
-static inline int is_stream_cipher ( struct crypto_algorithm *crypto ) {
104
-	return ( crypto->blocksize == 1 );
121
+static inline void cipher_setiv ( struct cipher_algorithm *cipher,
122
+				  void *ctx, const void *iv ) {
123
+	cipher->setiv ( ctx, iv );
105
 }
124
 }
106
 
125
 
107
-extern struct crypto_algorithm crypto_null;
126
+static inline int is_stream_cipher ( struct cipher_algorithm *cipher ) {
127
+	return ( cipher->blocksize == 1 );
128
+}
108
 
129
 
109
-extern int cipher_encrypt ( struct crypto_algorithm *crypto,
130
+extern int cipher_encrypt ( struct cipher_algorithm *cipher,
110
 			    void *ctx, const void *src, void *dst,
131
 			    void *ctx, const void *src, void *dst,
111
 			    size_t len );
132
 			    size_t len );
112
-extern int cipher_decrypt ( struct crypto_algorithm *crypto,
133
+extern int cipher_decrypt ( struct cipher_algorithm *cipher,
113
 			    void *ctx, const void *src, void *dst,
134
 			    void *ctx, const void *src, void *dst,
114
 			    size_t len );
135
 			    size_t len );
115
 
136
 
137
+extern struct digest_algorithm digest_null;
138
+extern struct cipher_algorithm cipher_null;
139
+extern struct pubkey_algorithm pubkey_null;
140
+
116
 #endif /* _GPXE_CRYPTO_H */
141
 #endif /* _GPXE_CRYPTO_H */

+ 3
- 3
src/include/gpxe/hmac.h View File

16
  * @v data		Data
16
  * @v data		Data
17
  * @v len		Length of data
17
  * @v len		Length of data
18
  */
18
  */
19
-static inline void hmac_update ( struct crypto_algorithm *digest,
19
+static inline void hmac_update ( struct digest_algorithm *digest,
20
 				 void *digest_ctx, const void *data,
20
 				 void *digest_ctx, const void *data,
21
 				 size_t len ) {
21
 				 size_t len ) {
22
 	digest_update ( digest, digest_ctx, data, len );
22
 	digest_update ( digest, digest_ctx, data, len );
23
 }
23
 }
24
 
24
 
25
-extern void hmac_init ( struct crypto_algorithm *digest, void *digest_ctx,
25
+extern void hmac_init ( struct digest_algorithm *digest, void *digest_ctx,
26
 			void *key, size_t *key_len );
26
 			void *key, size_t *key_len );
27
-extern void hmac_final ( struct crypto_algorithm *digest, void *digest_ctx,
27
+extern void hmac_final ( struct digest_algorithm *digest, void *digest_ctx,
28
 			 void *key, size_t *key_len, void *hmac );
28
 			 void *key, size_t *key_len, void *hmac );
29
 
29
 
30
 #endif /* _GPXE_HMAC_H */
30
 #endif /* _GPXE_HMAC_H */

+ 2
- 2
src/include/gpxe/md5.h View File

1
 #ifndef _GPXE_MD5_H
1
 #ifndef _GPXE_MD5_H
2
 #define _GPXE_MD5_H
2
 #define _GPXE_MD5_H
3
 
3
 
4
-struct crypto_algorithm;
4
+struct digest_algorithm;
5
 
5
 
6
 #include <stdint.h>
6
 #include <stdint.h>
7
 
7
 
17
 
17
 
18
 #define MD5_CTX_SIZE sizeof ( struct md5_ctx )
18
 #define MD5_CTX_SIZE sizeof ( struct md5_ctx )
19
 
19
 
20
-extern struct crypto_algorithm md5_algorithm;
20
+extern struct digest_algorithm md5_algorithm;
21
 
21
 
22
 #endif /* _GPXE_MD5_H */
22
 #endif /* _GPXE_MD5_H */

+ 2
- 2
src/include/gpxe/rsa.h View File

1
 #ifndef _GPXE_RSA_H
1
 #ifndef _GPXE_RSA_H
2
 #define _GPXE_RSA_H
2
 #define _GPXE_RSA_H
3
 
3
 
4
-struct crypto_algorithm;
4
+struct pubkey_algorithm;
5
 
5
 
6
-extern struct crypto_algorithm rsa_algorithm;
6
+extern struct pubkey_algorithm rsa_algorithm;
7
 
7
 
8
 #include "crypto/axtls/crypto.h"
8
 #include "crypto/axtls/crypto.h"
9
 
9
 

+ 2
- 2
src/include/gpxe/sha1.h View File

3
 
3
 
4
 #include "crypto/axtls/crypto.h"
4
 #include "crypto/axtls/crypto.h"
5
 
5
 
6
-struct crypto_algorithm;
6
+struct digest_algorithm;
7
 
7
 
8
 #define SHA1_CTX_SIZE sizeof ( SHA1_CTX )
8
 #define SHA1_CTX_SIZE sizeof ( SHA1_CTX )
9
 #define SHA1_DIGEST_SIZE SHA1_SIZE
9
 #define SHA1_DIGEST_SIZE SHA1_SIZE
10
 
10
 
11
-extern struct crypto_algorithm sha1_algorithm;
11
+extern struct digest_algorithm sha1_algorithm;
12
 
12
 
13
 #endif /* _GPXE_SHA1_H */
13
 #endif /* _GPXE_SHA1_H */

+ 3
- 3
src/include/gpxe/tls.h View File

91
 /** A TLS cipher specification */
91
 /** A TLS cipher specification */
92
 struct tls_cipherspec {
92
 struct tls_cipherspec {
93
 	/** Public-key encryption algorithm */
93
 	/** Public-key encryption algorithm */
94
-	struct crypto_algorithm *pubkey;
94
+	struct pubkey_algorithm *pubkey;
95
 	/** Bulk encryption cipher algorithm */
95
 	/** Bulk encryption cipher algorithm */
96
-	struct crypto_algorithm *cipher;
96
+	struct cipher_algorithm *cipher;
97
 	/** MAC digest algorithm */
97
 	/** MAC digest algorithm */
98
-	struct crypto_algorithm *digest;
98
+	struct digest_algorithm *digest;
99
 	/** Key length */
99
 	/** Key length */
100
 	size_t key_len;
100
 	size_t key_len;
101
 	/** Dynamically-allocated storage */
101
 	/** Dynamically-allocated storage */

+ 17
- 17
src/net/tls.c View File

136
  * @v digest_ctx	Digest context
136
  * @v digest_ctx	Digest context
137
  * @v args		( data, len ) pairs of data, terminated by NULL
137
  * @v args		( data, len ) pairs of data, terminated by NULL
138
  */
138
  */
139
-static void tls_hmac_update_va ( struct crypto_algorithm *digest,
139
+static void tls_hmac_update_va ( struct digest_algorithm *digest,
140
 				 void *digest_ctx, va_list args ) {
140
 				 void *digest_ctx, va_list args ) {
141
 	void *data;
141
 	void *data;
142
 	size_t len;
142
 	size_t len;
159
  * @v seeds		( data, len ) pairs of seed data, terminated by NULL
159
  * @v seeds		( data, len ) pairs of seed data, terminated by NULL
160
  */
160
  */
161
 static void tls_p_hash_va ( struct tls_session *tls,
161
 static void tls_p_hash_va ( struct tls_session *tls,
162
-			    struct crypto_algorithm *digest,
162
+			    struct digest_algorithm *digest,
163
 			    void *secret, size_t secret_len,
163
 			    void *secret, size_t secret_len,
164
 			    void *out, size_t out_len,
164
 			    void *out, size_t out_len,
165
 			    va_list seeds ) {
165
 			    va_list seeds ) {
409
 			       struct tls_cipherspec *cipherspec ) {
409
 			       struct tls_cipherspec *cipherspec ) {
410
 	free ( cipherspec->dynamic );
410
 	free ( cipherspec->dynamic );
411
 	memset ( cipherspec, 0, sizeof ( cipherspec ) );
411
 	memset ( cipherspec, 0, sizeof ( cipherspec ) );
412
-	cipherspec->pubkey = &crypto_null;
413
-	cipherspec->cipher = &crypto_null;
414
-	cipherspec->digest = &crypto_null;
412
+	cipherspec->pubkey = &pubkey_null;
413
+	cipherspec->cipher = &cipher_null;
414
+	cipherspec->digest = &digest_null;
415
 }
415
 }
416
 
416
 
417
 /**
417
 /**
427
  */
427
  */
428
 static int tls_set_cipher ( struct tls_session *tls,
428
 static int tls_set_cipher ( struct tls_session *tls,
429
 			    struct tls_cipherspec *cipherspec,
429
 			    struct tls_cipherspec *cipherspec,
430
-			    struct crypto_algorithm *pubkey,
431
-			    struct crypto_algorithm *cipher,
432
-			    struct crypto_algorithm *digest,
430
+			    struct pubkey_algorithm *pubkey,
431
+			    struct cipher_algorithm *cipher,
432
+			    struct digest_algorithm *digest,
433
 			    size_t key_len ) {
433
 			    size_t key_len ) {
434
 	size_t total;
434
 	size_t total;
435
 	void *dynamic;
435
 	void *dynamic;
473
  */
473
  */
474
 static int tls_select_cipher ( struct tls_session *tls,
474
 static int tls_select_cipher ( struct tls_session *tls,
475
 			       unsigned int cipher_suite ) {
475
 			       unsigned int cipher_suite ) {
476
-	struct crypto_algorithm *pubkey = &crypto_null;
477
-	struct crypto_algorithm *cipher = &crypto_null;
478
-	struct crypto_algorithm *digest = &crypto_null;
476
+	struct pubkey_algorithm *pubkey = &pubkey_null;
477
+	struct cipher_algorithm *cipher = &cipher_null;
478
+	struct digest_algorithm *digest = &digest_null;
479
 	unsigned int key_len = 0;
479
 	unsigned int key_len = 0;
480
 	int rc;
480
 	int rc;
481
 
481
 
524
 
524
 
525
 	/* Sanity check */
525
 	/* Sanity check */
526
 	if ( /* FIXME (when pubkey is not hard-coded to RSA):
526
 	if ( /* FIXME (when pubkey is not hard-coded to RSA):
527
-	      * ( pending->pubkey == &crypto_null ) || */
528
-	     ( pending->cipher == &crypto_null ) ||
529
-	     ( pending->digest == &crypto_null ) ) {
527
+	      * ( pending->pubkey == &pubkey_null ) || */
528
+	     ( pending->cipher == &cipher_null ) ||
529
+	     ( pending->digest == &digest_null ) ) {
530
 		DBGC ( tls, "TLS %p refusing to use null cipher\n", tls );
530
 		DBGC ( tls, "TLS %p refusing to use null cipher\n", tls );
531
 		return -ENOTSUP;
531
 		return -ENOTSUP;
532
 	}
532
 	}
567
  * far.
567
  * far.
568
  */
568
  */
569
 static void tls_verify_handshake ( struct tls_session *tls, void *out ) {
569
 static void tls_verify_handshake ( struct tls_session *tls, void *out ) {
570
-	struct crypto_algorithm *md5 = &md5_algorithm;
571
-	struct crypto_algorithm *sha1 = &sha1_algorithm;
570
+	struct digest_algorithm *md5 = &md5_algorithm;
571
+	struct digest_algorithm *sha1 = &sha1_algorithm;
572
 	uint8_t md5_ctx[md5->ctxsize];
572
 	uint8_t md5_ctx[md5->ctxsize];
573
 	uint8_t sha1_ctx[sha1->ctxsize];
573
 	uint8_t sha1_ctx[sha1->ctxsize];
574
 	void *md5_digest = out;
574
 	void *md5_digest = out;
1060
 		       struct tls_cipherspec *cipherspec,
1060
 		       struct tls_cipherspec *cipherspec,
1061
 		       uint64_t seq, struct tls_header *tlshdr,
1061
 		       uint64_t seq, struct tls_header *tlshdr,
1062
 		       const void *data, size_t len, void *hmac ) {
1062
 		       const void *data, size_t len, void *hmac ) {
1063
-	struct crypto_algorithm *digest = cipherspec->digest;
1063
+	struct digest_algorithm *digest = cipherspec->digest;
1064
 	uint8_t digest_ctx[digest->ctxsize];
1064
 	uint8_t digest_ctx[digest->ctxsize];
1065
 
1065
 
1066
 	hmac_init ( digest, digest_ctx, cipherspec->mac_secret,
1066
 	hmac_init ( digest, digest_ctx, cipherspec->mac_secret,

Loading…
Cancel
Save