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
00145 int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
00146 int mode,
00147 size_t length,
00148 const unsigned char *iv,
00149 size_t iv_len,
00150 const unsigned char *add,
00151 size_t add_len,
00152 const unsigned char *input,
00153 unsigned char *output,
00154 size_t tag_len,
00155 unsigned char *tag );
00156
00184 int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
00185 size_t length,
00186 const unsigned char *iv,
00187 size_t iv_len,
00188 const unsigned char *add,
00189 size_t add_len,
00190 const unsigned char *tag,
00191 size_t tag_len,
00192 const unsigned char *input,
00193 unsigned char *output );
00194
00209 int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
00210 int mode,
00211 const unsigned char *iv,
00212 size_t iv_len,
00213 const unsigned char *add,
00214 size_t add_len );
00215
00235 int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
00236 size_t length,
00237 const unsigned char *input,
00238 unsigned char *output );
00239
00253 int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
00254 unsigned char *tag,
00255 size_t tag_len );
00256
00263 void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
00264
00265 #ifdef __cplusplus
00266 }
00267 #endif
00268
00269 #else
00270 #include "gcm_alt.h"
00271 #endif
00272
00273 #ifdef __cplusplus
00274 extern "C" {
00275 #endif
00276
00282 int mbedtls_gcm_self_test( int verbose );
00283
00284 #ifdef __cplusplus
00285 }
00286 #endif
00287
00288
00289 #endif