pike.git / src / post_modules / Nettle / mac.cmod

version» Context lines:

pike.git/src/post_modules/Nettle/mac.cmod:43:    va_start(args, format);    vfprintf(stderr, format, args);    va_end(args);   }   #else   #define werror(x)   #endif      /*! @module Nettle */    - typedef void (*pike_nettle_set_key_func)(void *ctx, -  ptrdiff_t length, const char *key); + #ifdef HAVE_NETTLE_DSA_COMPAT_H + /* We use the presence of <nettle/dsa-compat.h> to +  * detect Nettle 3.0 or later. +  */    -  + /* In Nettle 3.0 length fields use size_t, where earlier it was unsigned. */ + typedef size_t pike_nettle_size_t; + #else + typedef unsigned pike_nettle_size_t; + #endif +    struct pike_mac   {    const char *name;       unsigned context_size;       unsigned digest_size;       unsigned block_size;       /* Suggested key size; other sizes are sometimes possible. */    unsigned key_size;       unsigned iv_size;    -  pike_nettle_set_key_func set_key; -  pike_nettle_set_key_func set_iv; +  /* NB: Use nettle_hash_update_func here to get both a length field, +  * and a const uint8_t source. +  */ +  nettle_hash_update_func *set_key; +  nettle_hash_update_func *set_iv;       nettle_hash_update_func *update;    nettle_hash_digest_func *digest;   };      #define _PIKE_MAC(name, NAME) { \    #name, \    sizeof(struct name##_ctx), \    NAME##_DIGEST_SIZE, \    NAME##_BLOCK_SIZE, \
pike.git/src/post_modules/Nettle/mac.cmod:247:    void *ctx = THIS->ctx;    const struct pike_mac *meta =    GET_META(Pike_fp->current_object);       if (!ctx || !meta)    Pike_error("State not properly initialized.\n");       iv->flags |= STRING_CLEAR_ON_EXIT;    NO_WIDE_STRING(iv);    -  if (iv->len != meta->iv_size) { +  if (iv->len != meta->iv_size || !meta->iv_size) {    Pike_error("Invalid iv/nonce.\n");    }       meta->set_iv(ctx, iv->len, STR0(iv));       push_object(this_object());    }       /*! @decl State update(string(0..255) data)    *!
pike.git/src/post_modules/Nettle/mac.cmod:391:   /* The algorithm objects can be overloaded in pike. */      #cmod_define TOSTR(DEF) #DEF      #ifdef HAVE_NETTLE_POLY1305_H      #define poly1305_aes_set_iv poly1305_aes_set_nonce   #define POLY1305_AES_BLOCK_SIZE POLY1305_BLOCK_SIZE   #define POLY1305_AES_IV_SIZE POLY1305_AES_NONCE_SIZE    - static void pike_poly1305_aes_set_key(void *ctx, unsigned len, + static void pike_poly1305_aes_set_key(void *ctx, pike_nettle_size_t len,    const uint8_t *key)   {    if (len != POLY1305_AES_KEY_SIZE) {    Pike_error("Invalid key length.\n");    }    poly1305_aes_set_key(ctx, key);   }    - static void pike_poly1305_aes_set_iv(void *ctx, unsigned len, + static void pike_poly1305_aes_set_iv(void *ctx, pike_nettle_size_t len,    const uint8_t *key)   {    if (len != POLY1305_AES_IV_SIZE) {    Pike_error("Invalid iv length.\n");    }    poly1305_aes_set_nonce(ctx, key);   }      #cmod_define PIKE_NAME POLY1305_AES   #cmod_define NETTLE_NAME poly1305_aes