00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef MBEDTLS_GCM_H
00032 #define MBEDTLS_GCM_H
00033
00034 #include "cipher.h"
00035
00036 #include <stdint.h>
00037
00038 #define MBEDTLS_GCM_ENCRYPT 1
00039 #define MBEDTLS_GCM_DECRYPT 0
00040
00041 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
00042 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
00043 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
00045 #if !defined(MBEDTLS_GCM_ALT)
00046
00047 #ifdef __cplusplus
00048 extern "C" {
00049 #endif
00050
00054 typedef struct {
00055 mbedtls_cipher_context_t cipher_ctx;
00056 uint64_t HL[16];
00057 uint64_t HH[16];
00058 uint64_t len;
00059 uint64_t add_len;
00060 unsigned char base_ectr[16];
00061 unsigned char y[16];
00062 unsigned char buf[16];
00063 int mode;
00066 }
00067 mbedtls_gcm_context;
00068
00080 void mbedtls_gcm_init( mbedtls_gcm_context *ctx );
00081
00096 int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
00097 mbedtls_cipher_id_t cipher,
00098 const unsigned char *key,
00099 unsigned int keybits );
00100
00124 int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
00125 int mode,
00126 size_t length,
00127 const unsigned char *iv,
00128 size_t iv_len,
00129 const unsigned char *add,
00130 size_t add_len,
00131 const unsigned char *input,
00132 unsigned char *output,
00133 size_t tag_len,
00134 unsigned char *tag );
00135
00158 int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
00159 size_t length,
00160 const unsigned char *iv,
00161 size_t iv_len,
00162 const unsigned char *add,
00163 size_t add_len,
00164 const unsigned char *tag,
00165 size_t tag_len,
00166 const unsigned char *input,
00167 unsigned char *output );
00168
00183 int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
00184 int mode,
00185 const unsigned char *iv,
00186 size_t iv_len,
00187 const unsigned char *add,
00188 size_t add_len );
00189
00209 int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
00210 size_t length,
00211 const unsigned char *input,
00212 unsigned char *output );
00213
00227 int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
00228 unsigned char *tag,
00229 size_t tag_len );
00230
00237 void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
00238
00239 #ifdef __cplusplus
00240 }
00241 #endif
00242
00243 #else
00244 #include "gcm_alt.h"
00245 #endif
00246
00247 #ifdef __cplusplus
00248 extern "C" {
00249 #endif
00250
00256 int mbedtls_gcm_self_test( int verbose );
00257
00258 #ifdef __cplusplus
00259 }
00260 #endif
00261
00262
00263 #endif