00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #ifndef MBEDTLS_GCM_H
00059 #define MBEDTLS_GCM_H
00060
00061 #if !defined(MBEDTLS_CONFIG_FILE)
00062 #include "config.h"
00063 #else
00064 #include MBEDTLS_CONFIG_FILE
00065 #endif
00066
00067 #include "cipher.h"
00068
00069 #include <stdint.h>
00070
00071 #define MBEDTLS_GCM_ENCRYPT 1
00072 #define MBEDTLS_GCM_DECRYPT 0
00073
00074 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
00075 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
00076 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
00078 #if !defined(MBEDTLS_GCM_ALT)
00079
00080 #ifdef __cplusplus
00081 extern "C" {
00082 #endif
00083
00087 typedef struct {
00088 mbedtls_cipher_context_t cipher_ctx;
00089 uint64_t HL[16];
00090 uint64_t HH[16];
00091 uint64_t len;
00092 uint64_t add_len;
00093 unsigned char base_ectr[16];
00094 unsigned char y[16];
00095 unsigned char buf[16];
00096 int mode;
00099 }
00100 mbedtls_gcm_context;
00101
00113 void mbedtls_gcm_init( mbedtls_gcm_context *ctx );
00114
00129 int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
00130 mbedtls_cipher_id_t cipher,
00131 const unsigned char *key,
00132 unsigned int keybits );
00133
00178 int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
00179 int mode,
00180 size_t length,
00181 const unsigned char *iv,
00182 size_t iv_len,
00183 const unsigned char *add,
00184 size_t add_len,
00185 const unsigned char *input,
00186 unsigned char *output,
00187 size_t tag_len,
00188 unsigned char *tag );
00189
00217 int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
00218 size_t length,
00219 const unsigned char *iv,
00220 size_t iv_len,
00221 const unsigned char *add,
00222 size_t add_len,
00223 const unsigned char *tag,
00224 size_t tag_len,
00225 const unsigned char *input,
00226 unsigned char *output );
00227
00242 int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
00243 int mode,
00244 const unsigned char *iv,
00245 size_t iv_len,
00246 const unsigned char *add,
00247 size_t add_len );
00248
00268 int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
00269 size_t length,
00270 const unsigned char *input,
00271 unsigned char *output );
00272
00286 int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
00287 unsigned char *tag,
00288 size_t tag_len );
00289
00296 void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
00297
00298 #ifdef __cplusplus
00299 }
00300 #endif
00301
00302 #else
00303 #include "gcm_alt.h"
00304 #endif
00305
00306 #ifdef __cplusplus
00307 extern "C" {
00308 #endif
00309
00315 int mbedtls_gcm_self_test( int verbose );
00316
00317 #ifdef __cplusplus
00318 }
00319 #endif
00320
00321
00322 #endif