00001
00027 #ifndef POLARSSL_GCM_H
00028 #define POLARSSL_GCM_H
00029
00030 #include "cipher.h"
00031
00032 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
00033 #include <basetsd.h>
00034 typedef UINT32 uint32_t;
00035 typedef UINT64 uint64_t;
00036 #else
00037 #include <stdint.h>
00038 #endif
00039
00040 #define GCM_ENCRYPT 1
00041 #define GCM_DECRYPT 0
00042
00043 #define POLARSSL_ERR_GCM_AUTH_FAILED -0x0012
00044 #define POLARSSL_ERR_GCM_BAD_INPUT -0x0014
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049
00053 typedef struct {
00054 cipher_context_t cipher_ctx;
00055 uint64_t HL[16];
00056 uint64_t HH[16];
00057 uint64_t len;
00058 uint64_t add_len;
00059 unsigned char base_ectr[16];
00060 unsigned char y[16];
00061 unsigned char buf[16];
00062 int mode;
00063 }
00064 gcm_context;
00065
00076 int gcm_init( gcm_context *ctx, cipher_id_t cipher, const unsigned char *key,
00077 unsigned int keysize );
00078
00101 int gcm_crypt_and_tag( gcm_context *ctx,
00102 int mode,
00103 size_t length,
00104 const unsigned char *iv,
00105 size_t iv_len,
00106 const unsigned char *add,
00107 size_t add_len,
00108 const unsigned char *input,
00109 unsigned char *output,
00110 size_t tag_len,
00111 unsigned char *tag );
00112
00134 int gcm_auth_decrypt( gcm_context *ctx,
00135 size_t length,
00136 const unsigned char *iv,
00137 size_t iv_len,
00138 const unsigned char *add,
00139 size_t add_len,
00140 const unsigned char *tag,
00141 size_t tag_len,
00142 const unsigned char *input,
00143 unsigned char *output );
00144
00157 int gcm_starts( gcm_context *ctx,
00158 int mode,
00159 const unsigned char *iv,
00160 size_t iv_len,
00161 const unsigned char *add,
00162 size_t add_len );
00163
00181 int gcm_update( gcm_context *ctx,
00182 size_t length,
00183 const unsigned char *input,
00184 unsigned char *output );
00185
00197 int gcm_finish( gcm_context *ctx,
00198 unsigned char *tag,
00199 size_t tag_len );
00200
00206 void gcm_free( gcm_context *ctx );
00207
00213 int gcm_self_test( int verbose );
00214
00215 #ifdef __cplusplus
00216 }
00217 #endif
00218
00219 #endif