Browse Source

Added cipher wrapper functions

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
811db204a6
1 changed files with 26 additions and 0 deletions
  1. 26
    0
      src/include/gpxe/crypto.h

+ 26
- 0
src/include/gpxe/crypto.h View File

@@ -8,6 +8,8 @@
8 8
  */
9 9
 
10 10
 #include <stdint.h>
11
+#include <stddef.h>
12
+#include <errno.h>
11 13
 
12 14
 /** A cryptographic algorithm */
13 15
 struct crypto_algorithm {
@@ -83,4 +85,28 @@ static inline void digest_final ( struct crypto_algorithm *crypto,
83 85
 	crypto->final ( ctx, out );
84 86
 }
85 87
 
88
+static inline int cipher_encrypt ( struct crypto_algorithm *crypto,
89
+				   void *ctx, const void *src, void *dst,
90
+				   size_t len ) {
91
+	if ( ( len & ( crypto->blocksize - 1 ) ) ) {
92
+		return -EINVAL;
93
+	}
94
+	crypto->encode ( ctx, src, dst, len );
95
+	return 0;
96
+}
97
+
98
+static inline int cipher_decrypt ( struct crypto_algorithm *crypto,
99
+				   void *ctx, const void *src, void *dst,
100
+				   size_t len ) {
101
+	if ( ( len & ( crypto->blocksize - 1 ) ) ) {
102
+		return -EINVAL;
103
+	}
104
+	crypto->decode ( ctx, src, dst, len );
105
+	return 0;
106
+}
107
+
108
+static inline int is_stream_cipher ( struct crypto_algorithm *crypto ) {
109
+	return ( crypto->blocksize == 1 );
110
+}
111
+
86 112
 #endif /* _GPXE_CRYPTO_H */

Loading…
Cancel
Save