Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
8 deleted
32 edited
153 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/heimdal/lib/hcrypto/aes.c

    r414 r745  
    120120    }
    121121}
     122
     123void
     124AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
     125                 unsigned long size, const AES_KEY *key,
     126                 unsigned char *iv, int forward_encrypt)
     127{
     128    int i;
     129
     130    for (i = 0; i < size; i++) {
     131        unsigned char tmp[AES_BLOCK_SIZE + 1];
     132
     133        memcpy(tmp, iv, AES_BLOCK_SIZE);
     134        AES_encrypt(iv, iv, key);
     135        if (!forward_encrypt) {
     136            tmp[AES_BLOCK_SIZE] = in[i];
     137        }
     138        out[i] = in[i] ^ iv[0];
     139        if (forward_encrypt) {
     140            tmp[AES_BLOCK_SIZE] = out[i];
     141        }
     142        memcpy(iv, &tmp[1], AES_BLOCK_SIZE);
     143    }
     144}
  • trunk/server/source4/heimdal/lib/hcrypto/aes.h

    r414 r745  
    4343#define AES_decrypt hc_AES_decrypt
    4444#define AES_cbc_encrypt hc_AES_cbc_encrypt
     45#define AES_cfb8_encrypt hc_AES_cfb8_encrypt
    4546
    4647/*
     
    7071
    7172void AES_cbc_encrypt(const unsigned char *, unsigned char *,
    72                      const unsigned long, const AES_KEY *,
     73                     unsigned long, const AES_KEY *,
    7374                     unsigned char *, int);
     75void AES_cfb8_encrypt(const unsigned char *, unsigned char *,
     76                      unsigned long, const AES_KEY *,
     77                      unsigned char *, int);
    7478
    7579#ifdef  __cplusplus
  • trunk/server/source4/heimdal/lib/hcrypto/bn.c

    r414 r745  
    4141
    4242#include <krb5-types.h>
     43#include <roken.h>
    4344#include <rfc2459_asn1.h> /* XXX */
    4445#include <der.h>
  • trunk/server/source4/heimdal/lib/hcrypto/camellia.h

    r414 r745  
    6767
    6868void CAMELLIA_cbc_encrypt(const unsigned char *, unsigned char *,
    69                           const unsigned long, const CAMELLIA_KEY *,
     69                          unsigned long, const CAMELLIA_KEY *,
    7070                          unsigned char *, int);
    7171
  • trunk/server/source4/heimdal/lib/hcrypto/des.c

    r414 r745  
    9292#include <krb5-types.h>
    9393#include <assert.h>
     94
     95#include <roken.h>
    9496
    9597#include "des.h"
     
    181183DES_is_weak_key(DES_cblock *key)
    182184{
     185    int weak = 0;
    183186    int i;
    184187
    185     for (i = 0; i < sizeof(weak_keys)/sizeof(weak_keys[0]); i++) {
    186         if (memcmp(weak_keys[i], key, DES_CBLOCK_LEN) == 0)
    187             return 1;
    188     }
    189     return 0;
     188    for (i = 0; i < sizeof(weak_keys)/sizeof(weak_keys[0]); i++)
     189        weak ^= (ct_memcmp(weak_keys[i], key, DES_CBLOCK_LEN) == 0);
     190
     191    return !!weak;
    190192}
    191193
  • trunk/server/source4/heimdal/lib/hcrypto/dh.c

    r414 r745  
    3838#include <stdio.h>
    3939#include <stdlib.h>
     40#include <krb5-types.h>
     41#include <rfc2459_asn1.h>
     42
    4043#include <dh.h>
    4144
     
    302305        goto out;
    303306
    304     if (BN_cmp(bn, pub_key) == 0) {
     307    if (BN_cmp(bn, dh->g) == 0) {
    305308        unsigned i, n = BN_num_bits(pub_key);
    306309        unsigned bits = 0;
     
    310313                bits++;
    311314
    312         if (bits > 1) {
     315        if (bits < 2) {
    313316            *codes |= DH_CHECK_PUBKEY_TOO_SMALL;
    314317            goto out;
     
    443446};
    444447
    445 extern const DH_METHOD _hc_dh_imath_method;
    446 static const DH_METHOD *dh_default_method = &_hc_dh_imath_method;
     448extern const DH_METHOD _hc_dh_ltm_method;
     449static const DH_METHOD *dh_default_method = &_hc_dh_ltm_method;
    447450
    448451/**
     
    488491}
    489492
     493/*
     494 *
     495 */
     496
     497static int
     498bn2heim_int(BIGNUM *bn, heim_integer *integer)
     499{
     500    integer->length = BN_num_bytes(bn);
     501    integer->data = malloc(integer->length);
     502    if (integer->data == NULL) {
     503        integer->length = 0;
     504        return ENOMEM;
     505    }
     506    BN_bn2bin(bn, integer->data);
     507    integer->negative = BN_is_negative(bn);
     508    return 0;
     509}
     510
     511/**
     512 *
     513 */
     514
     515int
     516i2d_DHparams(DH *dh, unsigned char **pp)
     517{
     518    DHParameter data;
     519    size_t size;
     520    int ret;
     521
     522    memset(&data, 0, sizeof(data));
     523
     524    if (bn2heim_int(dh->p, &data.prime) ||
     525        bn2heim_int(dh->g, &data.base))
     526    {
     527        free_DHParameter(&data);
     528        return -1;
     529    }
     530
     531    if (pp == NULL) {
     532        size = length_DHParameter(&data);
     533        free_DHParameter(&data);
     534    } else {
     535        void *p;
     536        size_t len;
     537
     538        ASN1_MALLOC_ENCODE(DHParameter, p, len, &data, &size, ret);
     539        free_DHParameter(&data);
     540        if (ret)
     541            return -1;
     542        if (len != size)
     543            abort();
     544
     545        memcpy(*pp, p, size);
     546        free(p);
     547
     548        *pp += size;
     549    }
     550
     551    return size;
     552}
  • trunk/server/source4/heimdal/lib/hcrypto/dh.h

    r414 r745  
    4141/* symbol renaming */
    4242#define DH_null_method hc_DH_null_method
    43 #define DH_imath_method hc_DH_imath_method
     43#define DH_tfm_method hc_DH_tfm_method
     44#define DH_ltm_method hc_DH_ltm_method
    4445#define DH_new hc_DH_new
    4546#define DH_new_method hc_DH_new_method
     
    5758#define DH_generate_key hc_DH_generate_key
    5859#define DH_compute_key hc_DH_compute_key
     60#define i2d_DHparams hc_i2d_DHparams
    5961
    6062/*
     
    115117
    116118const DH_METHOD *DH_null_method(void);
    117 const DH_METHOD *DH_imath_method(void);
     119const DH_METHOD *DH_tfm_method(void);
     120const DH_METHOD *DH_ltm_method(void);
    118121
    119122DH *    DH_new(void);
     
    138141int     DH_compute_key(unsigned char *,const BIGNUM *,DH *);
    139142
     143int     i2d_DHparams(DH *, unsigned char **);
     144
    140145#endif /* _HEIM_DH_H */
    141146
  • trunk/server/source4/heimdal/lib/hcrypto/engine.c

    r414 r745  
    5656    const RAND_METHOD *rand;
    5757};
     58
     59ENGINE  *
     60ENGINE_new(void)
     61{
     62    ENGINE *engine;
     63
     64    engine = calloc(1, sizeof(*engine));
     65    engine->references = 1;
     66
     67    return engine;
     68}
     69
     70int
     71ENGINE_free(ENGINE *engine)
     72{
     73    return ENGINE_finish(engine);
     74}
    5875
    5976int
     
    196213
    197214    dup = ENGINE_by_id(engine->id);
    198     if (dup) {
    199         ENGINE_finish(dup);
     215    if (dup)
    200216        return 0;
    201     }
    202217
    203218    d = realloc(engines, (num_engines + 1) * sizeof(*engines));
     
    216231    int ret;
    217232
    218     engine = calloc(1, sizeof(*engine));
     233    engine = ENGINE_new();
    219234    if (engine == NULL)
    220235        return;
     
    222237    ENGINE_set_id(engine, "builtin");
    223238    ENGINE_set_name(engine,
    224                     "Heimdal crypto builtin engine version " PACKAGE_VERSION);
    225     ENGINE_set_RSA(engine, RSA_imath_method());
    226     ENGINE_set_DH(engine, DH_imath_method());
     239                    "Heimdal crypto builtin (ltm) engine version " PACKAGE_VERSION);
     240    ENGINE_set_RSA(engine, RSA_ltm_method());
     241    ENGINE_set_DH(engine, DH_ltm_method());
    227242
    228243    ret = add_engine(engine);
    229244    if (ret != 1)
    230245        ENGINE_finish(engine);
     246
     247#ifdef USE_HCRYPTO_TFM
     248    /*
     249     * TFM
     250     */
     251
     252    engine = ENGINE_new();
     253    if (engine == NULL)
     254        return;
     255
     256    ENGINE_set_id(engine, "tfm");
     257    ENGINE_set_name(engine,
     258                    "Heimdal crypto tfm engine version " PACKAGE_VERSION);
     259    ENGINE_set_RSA(engine, RSA_tfm_method());
     260    ENGINE_set_DH(engine, DH_tfm_method());
     261
     262    ret = add_engine(engine);
     263    if (ret != 1)
     264        ENGINE_finish(engine);
     265#endif /* USE_HCRYPTO_TFM */
     266
     267#ifdef USE_HCRYPTO_LTM
     268    /*
     269     * ltm
     270     */
     271
     272    engine = ENGINE_new();
     273    if (engine == NULL)
     274        return;
     275
     276    ENGINE_set_id(engine, "ltm");
     277    ENGINE_set_name(engine,
     278                    "Heimdal crypto ltm engine version " PACKAGE_VERSION);
     279    ENGINE_set_RSA(engine, RSA_ltm_method());
     280    ENGINE_set_DH(engine, DH_ltm_method());
     281
     282    ret = add_engine(engine);
     283    if (ret != 1)
     284        ENGINE_finish(engine);
     285#endif
     286
     287#ifdef HAVE_GMP
     288    /*
     289     * gmp
     290     */
     291
     292    engine = ENGINE_new();
     293    if (engine == NULL)
     294        return;
     295
     296    ENGINE_set_id(engine, "gmp");
     297    ENGINE_set_name(engine,
     298                    "Heimdal crypto gmp engine version " PACKAGE_VERSION);
     299    ENGINE_set_RSA(engine, RSA_gmp_method());
     300
     301    ret = add_engine(engine);
     302    if (ret != 1)
     303        ENGINE_finish(engine);
     304#endif
    231305}
    232306
  • trunk/server/source4/heimdal/lib/hcrypto/engine.h

    r414 r745  
    5555#define ENGINE_set_name hc_ENGINE_set_name
    5656#define ENGINE_set_destroy_function hc_ENGINE_set_destroy_function
     57#define ENGINE_new hc_ENGINE_new
     58#define ENGINE_free hc_ENGINE_free
    5759#define ENGINE_up_ref hc_ENGINE_up_ref
    5860#define ENGINE_get_default_DH hc_ENGINE_get_default_DH
     
    6769typedef struct hc_engine ENGINE;
    6870
     71#define NID_md2                 0
     72#define NID_md4                 1
     73#define NID_md5                 2
     74#define NID_sha1                4
     75#define NID_sha256              5
     76
     77/*
     78 *
     79 */
     80
    6981#include <hcrypto/rsa.h>
    7082#include <hcrypto/dsa.h>
     
    7789typedef unsigned long (*openssl_v_check)(unsigned long);
    7890
     91ENGINE  *
     92        ENGINE_new(void);
     93int ENGINE_free(ENGINE *);
    7994void    ENGINE_add_conf_module(void);
    8095void    ENGINE_load_builtin_engines(void);
  • trunk/server/source4/heimdal/lib/hcrypto/evp-hcrypto.c

    r414 r745  
    4343
    4444#include <evp.h>
     45#include <evp-hcrypto.h>
    4546
    4647#include <krb5-types.h>
    4748
     49#include <des.h>
     50#include "camellia.h"
    4851#include <aes.h>
     52
     53#include <rc2.h>
     54#include <rc4.h>
     55
     56#include <sha.h>
     57#include <md2.h>
     58#include <md4.h>
     59#include <md5.h>
    4960
    5061/*
     
    7384{
    7485    AES_KEY *k = ctx->cipher_data;
    75     AES_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
    76     return 1;
    77 }
    78 
    79 static int
    80 aes_cleanup(EVP_CIPHER_CTX *ctx)
    81 {
    82     memset(ctx->cipher_data, 0, sizeof(AES_KEY));
     86    if (ctx->flags & EVP_CIPH_CFB8_MODE)
     87        AES_cfb8_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
     88    else
     89        AES_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
    8390    return 1;
    8491}
     
    103110        aes_init,
    104111        aes_do_cipher,
    105         aes_cleanup,
     112        NULL,
    106113        sizeof(AES_KEY),
    107114        NULL,
     
    133140        aes_init,
    134141        aes_do_cipher,
    135         aes_cleanup,
     142        NULL,
    136143        sizeof(AES_KEY),
    137144        NULL,
     
    162169        aes_init,
    163170        aes_do_cipher,
    164         aes_cleanup,
     171        NULL,
    165172        sizeof(AES_KEY),
    166173        NULL,
     
    171178    return &aes_256_cbc;
    172179}
     180
     181/**
     182 * The AES-128 CFB8 cipher type (hcrypto)
     183 *
     184 * @return the AES-128 EVP_CIPHER pointer.
     185 *
     186 * @ingroup hcrypto_evp
     187 */
     188
     189const EVP_CIPHER *
     190EVP_hcrypto_aes_128_cfb8(void)
     191{
     192    static const EVP_CIPHER aes_128_cfb8 = {
     193        0,
     194        1,
     195        16,
     196        16,
     197        EVP_CIPH_CFB8_MODE,
     198        aes_init,
     199        aes_do_cipher,
     200        NULL,
     201        sizeof(AES_KEY),
     202        NULL,
     203        NULL,
     204        NULL,
     205        NULL
     206    };
     207
     208    return &aes_128_cfb8;
     209}
     210
     211/**
     212 * The AES-192 CFB8 cipher type (hcrypto)
     213 *
     214 * @return the AES-192 EVP_CIPHER pointer.
     215 *
     216 * @ingroup hcrypto_evp
     217 */
     218
     219const EVP_CIPHER *
     220EVP_hcrypto_aes_192_cfb8(void)
     221{
     222    static const EVP_CIPHER aes_192_cfb8 = {
     223        0,
     224        1,
     225        24,
     226        16,
     227        EVP_CIPH_CFB8_MODE,
     228        aes_init,
     229        aes_do_cipher,
     230        NULL,
     231        sizeof(AES_KEY),
     232        NULL,
     233        NULL,
     234        NULL,
     235        NULL
     236    };
     237    return &aes_192_cfb8;
     238}
     239
     240/**
     241 * The AES-256 CFB8 cipher type (hcrypto)
     242 *
     243 * @return the AES-256 EVP_CIPHER pointer.
     244 *
     245 * @ingroup hcrypto_evp
     246 */
     247
     248const EVP_CIPHER *
     249EVP_hcrypto_aes_256_cfb8(void)
     250{
     251    static const EVP_CIPHER aes_256_cfb8 = {
     252        0,
     253        1,
     254        32,
     255        16,
     256        EVP_CIPH_CFB8_MODE,
     257        aes_init,
     258        aes_do_cipher,
     259        NULL,
     260        sizeof(AES_KEY),
     261        NULL,
     262        NULL,
     263        NULL,
     264        NULL
     265    };
     266    return &aes_256_cfb8;
     267}
     268
     269/**
     270 * The message digest SHA256 - hcrypto
     271 *
     272 * @return the message digest type.
     273 *
     274 * @ingroup hcrypto_evp
     275 */
     276
     277const EVP_MD *
     278EVP_hcrypto_sha256(void)
     279{
     280    static const struct hc_evp_md sha256 = {
     281        32,
     282        64,
     283        sizeof(SHA256_CTX),
     284        (hc_evp_md_init)SHA256_Init,
     285        (hc_evp_md_update)SHA256_Update,
     286        (hc_evp_md_final)SHA256_Final,
     287        NULL
     288    };
     289    return &sha256;
     290}
     291
     292/**
     293 * The message digest SHA384 - hcrypto
     294 *
     295 * @return the message digest type.
     296 *
     297 * @ingroup hcrypto_evp
     298 */
     299
     300const EVP_MD *
     301EVP_hcrypto_sha384(void)
     302{
     303    static const struct hc_evp_md sha384 = {
     304        48,
     305        128,
     306        sizeof(SHA384_CTX),
     307        (hc_evp_md_init)SHA384_Init,
     308        (hc_evp_md_update)SHA384_Update,
     309        (hc_evp_md_final)SHA384_Final,
     310        NULL
     311    };
     312    return &sha384;
     313}
     314
     315/**
     316 * The message digest SHA512 - hcrypto
     317 *
     318 * @return the message digest type.
     319 *
     320 * @ingroup hcrypto_evp
     321 */
     322
     323const EVP_MD *
     324EVP_hcrypto_sha512(void)
     325{
     326    static const struct hc_evp_md sha512 = {
     327        64,
     328        128,
     329        sizeof(SHA512_CTX),
     330        (hc_evp_md_init)SHA512_Init,
     331        (hc_evp_md_update)SHA512_Update,
     332        (hc_evp_md_final)SHA512_Final,
     333        NULL
     334    };
     335    return &sha512;
     336}
     337
     338/**
     339 * The message digest SHA1 - hcrypto
     340 *
     341 * @return the message digest type.
     342 *
     343 * @ingroup hcrypto_evp
     344 */
     345
     346const EVP_MD *
     347EVP_hcrypto_sha1(void)
     348{
     349    static const struct hc_evp_md sha1 = {
     350        20,
     351        64,
     352        sizeof(SHA_CTX),
     353        (hc_evp_md_init)SHA1_Init,
     354        (hc_evp_md_update)SHA1_Update,
     355        (hc_evp_md_final)SHA1_Final,
     356        NULL
     357    };
     358    return &sha1;
     359}
     360
     361/**
     362 * The message digest MD5 - hcrypto
     363 *
     364 * @return the message digest type.
     365 *
     366 * @ingroup hcrypto_evp
     367 */
     368
     369const EVP_MD *
     370EVP_hcrypto_md5(void)
     371{
     372    static const struct hc_evp_md md5 = {
     373        16,
     374        64,
     375        sizeof(MD5_CTX),
     376        (hc_evp_md_init)MD5_Init,
     377        (hc_evp_md_update)MD5_Update,
     378        (hc_evp_md_final)MD5_Final,
     379        NULL
     380    };
     381    return &md5;
     382}
     383
     384/**
     385 * The message digest MD4 - hcrypto
     386 *
     387 * @return the message digest type.
     388 *
     389 * @ingroup hcrypto_evp
     390 */
     391
     392const EVP_MD *
     393EVP_hcrypto_md4(void)
     394{
     395    static const struct hc_evp_md md4 = {
     396        16,
     397        64,
     398        sizeof(MD4_CTX),
     399        (hc_evp_md_init)MD4_Init,
     400        (hc_evp_md_update)MD4_Update,
     401        (hc_evp_md_final)MD4_Final,
     402        NULL
     403    };
     404    return &md4;
     405}
     406
     407/**
     408 * The message digest MD2 - hcrypto
     409 *
     410 * @return the message digest type.
     411 *
     412 * @ingroup hcrypto_evp
     413 */
     414
     415const EVP_MD *
     416EVP_hcrypto_md2(void)
     417{
     418    static const struct hc_evp_md md2 = {
     419        16,
     420        16,
     421        sizeof(MD2_CTX),
     422        (hc_evp_md_init)MD2_Init,
     423        (hc_evp_md_update)MD2_Update,
     424        (hc_evp_md_final)MD2_Final,
     425        NULL
     426    };
     427    return &md2;
     428}
     429
     430/*
     431 *
     432 */
     433
     434static int
     435des_cbc_init(EVP_CIPHER_CTX *ctx,
     436             const unsigned char * key,
     437             const unsigned char * iv,
     438             int encp)
     439{
     440    DES_key_schedule *k = ctx->cipher_data;
     441    DES_cblock deskey;
     442    memcpy(&deskey, key, sizeof(deskey));
     443    DES_set_key_unchecked(&deskey, k);
     444    return 1;
     445}
     446
     447static int
     448des_cbc_do_cipher(EVP_CIPHER_CTX *ctx,
     449                  unsigned char *out,
     450                  const unsigned char *in,
     451                  unsigned int size)
     452{
     453    DES_key_schedule *k = ctx->cipher_data;
     454    DES_cbc_encrypt(in, out, size,
     455                    k, (DES_cblock *)ctx->iv, ctx->encrypt);
     456    return 1;
     457}
     458
     459/**
     460 * The DES cipher type
     461 *
     462 * @return the DES-CBC EVP_CIPHER pointer.
     463 *
     464 * @ingroup hcrypto_evp
     465 */
     466
     467const EVP_CIPHER *
     468EVP_hcrypto_des_cbc(void)
     469{
     470    static const EVP_CIPHER des_cbc = {
     471        0,
     472        8,
     473        8,
     474        8,
     475        EVP_CIPH_CBC_MODE,
     476        des_cbc_init,
     477        des_cbc_do_cipher,
     478        NULL,
     479        sizeof(DES_key_schedule),
     480        NULL,
     481        NULL,
     482        NULL,
     483        NULL
     484    };
     485    return &des_cbc;
     486}
     487
     488/*
     489 *
     490 */
     491
     492struct des_ede3_cbc {
     493    DES_key_schedule ks[3];
     494};
     495
     496static int
     497des_ede3_cbc_init(EVP_CIPHER_CTX *ctx,
     498                  const unsigned char * key,
     499                  const unsigned char * iv,
     500                  int encp)
     501{
     502    struct des_ede3_cbc *k = ctx->cipher_data;
     503    DES_cblock deskey;
     504
     505    memcpy(&deskey, key, sizeof(deskey));
     506    DES_set_odd_parity(&deskey);
     507    DES_set_key_unchecked(&deskey, &k->ks[0]);
     508
     509    memcpy(&deskey, key + 8, sizeof(deskey));
     510    DES_set_odd_parity(&deskey);
     511    DES_set_key_unchecked(&deskey, &k->ks[1]);
     512
     513    memcpy(&deskey, key + 16, sizeof(deskey));
     514    DES_set_odd_parity(&deskey);
     515    DES_set_key_unchecked(&deskey, &k->ks[2]);
     516
     517    return 1;
     518}
     519
     520static int
     521des_ede3_cbc_do_cipher(EVP_CIPHER_CTX *ctx,
     522                       unsigned char *out,
     523                       const unsigned char *in,
     524                       unsigned int size)
     525{
     526    struct des_ede3_cbc *k = ctx->cipher_data;
     527    DES_ede3_cbc_encrypt(in, out, size,
     528                         &k->ks[0], &k->ks[1], &k->ks[2],
     529                         (DES_cblock *)ctx->iv, ctx->encrypt);
     530    return 1;
     531}
     532
     533/**
     534 * The tripple DES cipher type - hcrypto
     535 *
     536 * @return the DES-EDE3-CBC EVP_CIPHER pointer.
     537 *
     538 * @ingroup hcrypto_evp
     539 */
     540
     541const EVP_CIPHER *
     542EVP_hcrypto_des_ede3_cbc(void)
     543{
     544    static const EVP_CIPHER des_ede3_cbc = {
     545        0,
     546        8,
     547        24,
     548        8,
     549        EVP_CIPH_CBC_MODE,
     550        des_ede3_cbc_init,
     551        des_ede3_cbc_do_cipher,
     552        NULL,
     553        sizeof(struct des_ede3_cbc),
     554        NULL,
     555        NULL,
     556        NULL,
     557        NULL
     558    };
     559    return &des_ede3_cbc;
     560}
     561
     562/*
     563 *
     564 */
     565
     566struct rc2_cbc {
     567    unsigned int maximum_effective_key;
     568    RC2_KEY key;
     569};
     570
     571static int
     572rc2_init(EVP_CIPHER_CTX *ctx,
     573         const unsigned char * key,
     574         const unsigned char * iv,
     575         int encp)
     576{
     577    struct rc2_cbc *k = ctx->cipher_data;
     578    k->maximum_effective_key = EVP_CIPHER_CTX_key_length(ctx) * 8;
     579    RC2_set_key(&k->key,
     580                EVP_CIPHER_CTX_key_length(ctx),
     581                key,
     582                k->maximum_effective_key);
     583    return 1;
     584}
     585
     586static int
     587rc2_do_cipher(EVP_CIPHER_CTX *ctx,
     588              unsigned char *out,
     589              const unsigned char *in,
     590              unsigned int size)
     591{
     592    struct rc2_cbc *k = ctx->cipher_data;
     593    RC2_cbc_encrypt(in, out, size, &k->key, ctx->iv, ctx->encrypt);
     594    return 1;
     595}
     596
     597/**
     598 * The RC2 cipher type - hcrypto
     599 *
     600 * @return the RC2 EVP_CIPHER pointer.
     601 *
     602 * @ingroup hcrypto_evp
     603 */
     604
     605const EVP_CIPHER *
     606EVP_hcrypto_rc2_cbc(void)
     607{
     608    static const EVP_CIPHER rc2_cbc = {
     609        0,
     610        RC2_BLOCK_SIZE,
     611        RC2_KEY_LENGTH,
     612        RC2_BLOCK_SIZE,
     613        EVP_CIPH_CBC_MODE|EVP_CIPH_VARIABLE_LENGTH,
     614        rc2_init,
     615        rc2_do_cipher,
     616        NULL,
     617        sizeof(struct rc2_cbc),
     618        NULL,
     619        NULL,
     620        NULL,
     621        NULL
     622    };
     623    return &rc2_cbc;
     624}
     625
     626/**
     627 * The RC2-40 cipher type
     628 *
     629 * @return the RC2-40 EVP_CIPHER pointer.
     630 *
     631 * @ingroup hcrypto_evp
     632 */
     633
     634const EVP_CIPHER *
     635EVP_hcrypto_rc2_40_cbc(void)
     636{
     637    static const EVP_CIPHER rc2_40_cbc = {
     638        0,
     639        RC2_BLOCK_SIZE,
     640        5,
     641        RC2_BLOCK_SIZE,
     642        EVP_CIPH_CBC_MODE,
     643        rc2_init,
     644        rc2_do_cipher,
     645        NULL,
     646        sizeof(struct rc2_cbc),
     647        NULL,
     648        NULL,
     649        NULL,
     650        NULL
     651    };
     652    return &rc2_40_cbc;
     653}
     654
     655/**
     656 * The RC2-64 cipher type
     657 *
     658 * @return the RC2-64 EVP_CIPHER pointer.
     659 *
     660 * @ingroup hcrypto_evp
     661 */
     662
     663const EVP_CIPHER *
     664EVP_hcrypto_rc2_64_cbc(void)
     665{
     666    static const EVP_CIPHER rc2_64_cbc = {
     667        0,
     668        RC2_BLOCK_SIZE,
     669        8,
     670        RC2_BLOCK_SIZE,
     671        EVP_CIPH_CBC_MODE,
     672        rc2_init,
     673        rc2_do_cipher,
     674        NULL,
     675        sizeof(struct rc2_cbc),
     676        NULL,
     677        NULL,
     678        NULL,
     679        NULL
     680    };
     681    return &rc2_64_cbc;
     682}
     683
     684static int
     685camellia_init(EVP_CIPHER_CTX *ctx,
     686         const unsigned char * key,
     687         const unsigned char * iv,
     688         int encp)
     689{
     690    CAMELLIA_KEY *k = ctx->cipher_data;
     691    k->bits = ctx->cipher->key_len * 8;
     692    CAMELLIA_set_key(key, ctx->cipher->key_len * 8, k);
     693    return 1;
     694}
     695
     696static int
     697camellia_do_cipher(EVP_CIPHER_CTX *ctx,
     698              unsigned char *out,
     699              const unsigned char *in,
     700              unsigned int size)
     701{
     702    CAMELLIA_KEY *k = ctx->cipher_data;
     703    CAMELLIA_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
     704    return 1;
     705}
     706
     707/**
     708 * The Camellia-128 cipher type - hcrypto
     709 *
     710 * @return the Camellia-128 EVP_CIPHER pointer.
     711 *
     712 * @ingroup hcrypto_evp
     713 */
     714
     715const EVP_CIPHER *
     716EVP_hcrypto_camellia_128_cbc(void)
     717{
     718    static const EVP_CIPHER cipher = {
     719        0,
     720        16,
     721        16,
     722        16,
     723        EVP_CIPH_CBC_MODE,
     724        camellia_init,
     725        camellia_do_cipher,
     726        NULL,
     727        sizeof(CAMELLIA_KEY),
     728        NULL,
     729        NULL,
     730        NULL,
     731        NULL
     732    };
     733    return &cipher;
     734}
     735
     736/**
     737 * The Camellia-198 cipher type - hcrypto
     738 *
     739 * @return the Camellia-198 EVP_CIPHER pointer.
     740 *
     741 * @ingroup hcrypto_evp
     742 */
     743
     744const EVP_CIPHER *
     745EVP_hcrypto_camellia_192_cbc(void)
     746{
     747    static const EVP_CIPHER cipher = {
     748        0,
     749        16,
     750        24,
     751        16,
     752        EVP_CIPH_CBC_MODE,
     753        camellia_init,
     754        camellia_do_cipher,
     755        NULL,
     756        sizeof(CAMELLIA_KEY),
     757        NULL,
     758        NULL,
     759        NULL,
     760        NULL
     761    };
     762    return &cipher;
     763}
     764
     765/**
     766 * The Camellia-256 cipher type - hcrypto
     767 *
     768 * @return the Camellia-256 EVP_CIPHER pointer.
     769 *
     770 * @ingroup hcrypto_evp
     771 */
     772
     773const EVP_CIPHER *
     774EVP_hcrypto_camellia_256_cbc(void)
     775{
     776    static const EVP_CIPHER cipher = {
     777        0,
     778        16,
     779        32,
     780        16,
     781        EVP_CIPH_CBC_MODE,
     782        camellia_init,
     783        camellia_do_cipher,
     784        NULL,
     785        sizeof(CAMELLIA_KEY),
     786        NULL,
     787        NULL,
     788        NULL,
     789        NULL
     790    };
     791    return &cipher;
     792}
     793
     794static int
     795rc4_init(EVP_CIPHER_CTX *ctx,
     796         const unsigned char *key,
     797         const unsigned char *iv,
     798         int enc)
     799{
     800    RC4_KEY *k = ctx->cipher_data;
     801    RC4_set_key(k, ctx->key_len, key);
     802    return 1;
     803}
     804
     805static int
     806rc4_do_cipher(EVP_CIPHER_CTX *ctx,
     807              unsigned char *out,
     808              const unsigned char *in,
     809              unsigned int size)
     810{
     811    RC4_KEY *k = ctx->cipher_data;
     812    RC4(k, size, in, out);
     813    return 1;
     814}
     815
     816const EVP_CIPHER *
     817EVP_hcrypto_rc4(void)
     818{
     819    static const EVP_CIPHER rc4 = {
     820        0,
     821        1,
     822        16,
     823        0,
     824        EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
     825        rc4_init,
     826        rc4_do_cipher,
     827        NULL,
     828        sizeof(RC4_KEY),
     829        NULL,
     830        NULL,
     831        NULL,
     832        NULL
     833    };
     834    return &rc4;
     835}
     836
     837
     838const EVP_CIPHER *
     839EVP_hcrypto_rc4_40(void)
     840{
     841    static const EVP_CIPHER rc4_40 = {
     842        0,
     843        1,
     844        5,
     845        0,
     846        EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
     847        rc4_init,
     848        rc4_do_cipher,
     849        NULL,
     850        sizeof(RC4_KEY),
     851        NULL,
     852        NULL,
     853        NULL,
     854        NULL
     855    };
     856    return &rc4_40;
     857}
  • trunk/server/source4/heimdal/lib/hcrypto/evp.c

    r414 r745  
    4646
    4747#include <evp.h>
     48#include <evp-hcrypto.h>
     49#include <evp-cc.h>
    4850
    4951#include <krb5-types.h>
    50 
    51 #include "camellia.h"
    52 #include <des.h>
    53 #include <sha.h>
    54 #include <rc2.h>
    55 #include <rc4.h>
    56 #include <md2.h>
    57 #include <md4.h>
    58 #include <md5.h>
     52#include <roken.h>
     53
     54#ifndef HCRYPTO_DEF_PROVIDER
     55#define HCRYPTO_DEF_PROVIDER hcrypto
     56#endif
     57
     58#define HC_CONCAT4(x,y,z,aa)    x ## y ## z ## aa
     59
     60
     61#define EVP_DEF_OP(_prov,_op) HC_CONCAT4(EVP_,_prov,_,_op)()
    5962
    6063/**
     
    139142 */
    140143
    141 void HC_DEPRECATED
    142 EVP_MD_CTX_init(EVP_MD_CTX *ctx)
     144void
     145EVP_MD_CTX_init(EVP_MD_CTX *ctx) HC_DEPRECATED
    143146{
    144147    memset(ctx, 0, sizeof(*ctx));
     
    170173 */
    171174
    172 int HC_DEPRECATED
    173 EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
     175int
     176EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) HC_DEPRECATED
    174177{
    175178    if (ctx->md && ctx->md->cleanup)
    176179        (ctx->md->cleanup)(ctx);
     180    else if (ctx->md)
     181        memset(ctx->ptr, 0, ctx->md->ctx_size);
    177182    ctx->md = NULL;
    178183    ctx->engine = NULL;
     
    352357EVP_sha256(void)
    353358{
    354     static const struct hc_evp_md sha256 = {
    355         32,
    356         64,
    357         sizeof(SHA256_CTX),
    358         (hc_evp_md_init)SHA256_Init,
    359         (hc_evp_md_update)SHA256_Update,
    360         (hc_evp_md_final)SHA256_Final,
    361         NULL
    362     };
    363     return &sha256;
    364 }
    365 
    366 static const struct hc_evp_md sha1 = {
    367     20,
    368     64,
    369     sizeof(SHA_CTX),
    370     (hc_evp_md_init)SHA1_Init,
    371     (hc_evp_md_update)SHA1_Update,
    372     (hc_evp_md_final)SHA1_Final,
    373     NULL
    374 };
     359    hcrypto_validate();
     360    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha256);
     361}
     362
     363/**
     364 * The message digest SHA384
     365 *
     366 * @return the message digest type.
     367 *
     368 * @ingroup hcrypto_evp
     369 */
     370
     371const EVP_MD *
     372EVP_sha384(void)
     373{
     374    hcrypto_validate();
     375    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha384);
     376}
     377
     378/**
     379 * The message digest SHA512
     380 *
     381 * @return the message digest type.
     382 *
     383 * @ingroup hcrypto_evp
     384 */
     385
     386const EVP_MD *
     387EVP_sha512(void)
     388{
     389    hcrypto_validate();
     390    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha512);
     391}
    375392
    376393/**
     
    385402EVP_sha1(void)
    386403{
    387     return &sha1;
     404    hcrypto_validate();
     405    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha1);
    388406}
    389407
     
    397415
    398416const EVP_MD *
    399 EVP_sha(void)
    400 {
    401     return &sha1;
     417EVP_sha(void) HC_DEPRECATED
     418   
     419{
     420    hcrypto_validate();
     421    return EVP_sha1();
    402422}
    403423
     
    411431
    412432const EVP_MD *
    413 EVP_md5(void)
    414 {
    415     static const struct hc_evp_md md5 = {
    416         16,
    417         64,
    418         sizeof(MD5_CTX),
    419         (hc_evp_md_init)MD5_Init,
    420         (hc_evp_md_update)MD5_Update,
    421         (hc_evp_md_final)MD5_Final,
    422         NULL
    423     };
    424     return &md5;
     433EVP_md5(void) HC_DEPRECATED_CRYPTO
     434{
     435    hcrypto_validate();
     436    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, md5);
    425437}
    426438
     
    434446
    435447const EVP_MD *
    436 EVP_md4(void)
    437 {
    438     static const struct hc_evp_md md4 = {
    439         16,
    440         64,
    441         sizeof(MD4_CTX),
    442         (hc_evp_md_init)MD4_Init,
    443         (hc_evp_md_update)MD4_Update,
    444         (hc_evp_md_final)MD4_Final,
    445         NULL
    446     };
    447     return &md4;
     448EVP_md4(void) HC_DEPRECATED_CRYPTO
     449{
     450    hcrypto_validate();
     451    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, md4);
    448452}
    449453
     
    457461
    458462const EVP_MD *
    459 EVP_md2(void)
    460 {
    461     static const struct hc_evp_md md2 = {
    462         16,
    463         16,
    464         sizeof(MD2_CTX),
    465         (hc_evp_md_init)MD2_Init,
    466         (hc_evp_md_update)MD2_Update,
    467         (hc_evp_md_final)MD2_Final,
    468         NULL
    469     };
    470     return &md2;
     463EVP_md2(void) HC_DEPRECATED_CRYPTO
     464{
     465    hcrypto_validate();
     466    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, md2);
    471467}
    472468
     
    590586        c->cipher->cleanup(c);
    591587    if (c->cipher_data) {
     588        memset(c->cipher_data, 0, c->cipher->ctx_size);
    592589        free(c->cipher_data);
    593590        c->cipher_data = NULL;
     
    596593}
    597594
     595/**
     596 * If the cipher type supports it, change the key length
     597 *
     598 * @param c the cipher context to change the key length for
     599 * @param length new key length
     600 *
     601 * @return 1 on success.
     602 *
     603 * @ingroup hcrypto_evp
     604 */
     605
     606int
     607EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int length)
     608{
     609    if ((c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH) && length > 0) {
     610        c->key_len = length;
     611        return 1;
     612    }
     613    return 0;
     614}
     615
    598616#if 0
    599 int
    600 EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int length)
    601 {
    602     return 0;
    603 }
    604 
    605617int
    606618EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad)
     
    769781        ctx->key_len = c->key_len;
    770782
    771         ctx->cipher_data = malloc(c->ctx_size);
     783        ctx->cipher_data = calloc(1, c->ctx_size);
    772784        if (ctx->cipher_data == NULL && c->ctx_size != 0)
    773785            return 0;
     
    781793    }
    782794
    783     switch (EVP_CIPHER_CTX_flags(ctx)) {
     795    switch (EVP_CIPHER_CTX_mode(ctx)) {
    784796    case EVP_CIPH_CBC_MODE:
    785797
     
    790802        memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
    791803        break;
     804
     805    case EVP_CIPH_STREAM_CIPHER:
     806        break;
     807    case EVP_CIPH_CFB8_MODE:
     808        if (iv)
     809            memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx));
     810        break;
     811
    792812    default:
    793813        return 0;
     
    10061026}
    10071027
    1008 /*
    1009  *
    1010  */
    1011 
    1012 struct rc2_cbc {
    1013     unsigned int maximum_effective_key;
    1014     RC2_KEY key;
    1015 };
    1016 
    1017 static int
    1018 rc2_init(EVP_CIPHER_CTX *ctx,
    1019          const unsigned char * key,
    1020          const unsigned char * iv,
    1021          int encp)
    1022 {
    1023     struct rc2_cbc *k = ctx->cipher_data;
    1024     k->maximum_effective_key = EVP_CIPHER_CTX_key_length(ctx) * 8;
    1025     RC2_set_key(&k->key,
    1026                 EVP_CIPHER_CTX_key_length(ctx),
    1027                 key,
    1028                 k->maximum_effective_key);
    1029     return 1;
    1030 }
    1031 
    1032 static int
    1033 rc2_do_cipher(EVP_CIPHER_CTX *ctx,
    1034               unsigned char *out,
    1035               const unsigned char *in,
    1036               unsigned int size)
    1037 {
    1038     struct rc2_cbc *k = ctx->cipher_data;
    1039     RC2_cbc_encrypt(in, out, size, &k->key, ctx->iv, ctx->encrypt);
    1040     return 1;
    1041 }
    1042 
    1043 static int
    1044 rc2_cleanup(EVP_CIPHER_CTX *ctx)
    1045 {
    1046     memset(ctx->cipher_data, 0, sizeof(struct rc2_cbc));
    1047     return 1;
    1048 }
    1049 
    10501028/**
    10511029 * The RC2 cipher type
     
    10591037EVP_rc2_cbc(void)
    10601038{
    1061     static const EVP_CIPHER rc2_cbc = {
    1062         0,
    1063         RC2_BLOCK_SIZE,
    1064         RC2_KEY_LENGTH,
    1065         RC2_BLOCK_SIZE,
    1066         EVP_CIPH_CBC_MODE,
    1067         rc2_init,
    1068         rc2_do_cipher,
    1069         rc2_cleanup,
    1070         sizeof(struct rc2_cbc),
    1071         NULL,
    1072         NULL,
    1073         NULL,
    1074         NULL
    1075     };
    1076     return &rc2_cbc;
    1077 }
    1078 
    1079 /**
    1080  * The RC2-40 cipher type
    1081  *
    1082  * @return the RC2-40 EVP_CIPHER pointer.
     1039    hcrypto_validate();
     1040    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc2_cbc);
     1041}
     1042
     1043/**
     1044 * The RC2 cipher type
     1045 *
     1046 * @return the RC2 EVP_CIPHER pointer.
    10831047 *
    10841048 * @ingroup hcrypto_evp
     
    10881052EVP_rc2_40_cbc(void)
    10891053{
    1090     static const EVP_CIPHER rc2_40_cbc = {
    1091         0,
    1092         RC2_BLOCK_SIZE,
    1093         5,
    1094         RC2_BLOCK_SIZE,
    1095         EVP_CIPH_CBC_MODE,
    1096         rc2_init,
    1097         rc2_do_cipher,
    1098         rc2_cleanup,
    1099         sizeof(struct rc2_cbc),
    1100         NULL,
    1101         NULL,
    1102         NULL,
    1103         NULL
    1104     };
    1105     return &rc2_40_cbc;
    1106 }
    1107 
    1108 /**
    1109  * The RC2-64 cipher type
    1110  *
    1111  * @return the RC2-64 EVP_CIPHER pointer.
     1054    hcrypto_validate();
     1055    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc2_40_cbc);
     1056}
     1057
     1058/**
     1059 * The RC2 cipher type
     1060 *
     1061 * @return the RC2 EVP_CIPHER pointer.
    11121062 *
    11131063 * @ingroup hcrypto_evp
     
    11171067EVP_rc2_64_cbc(void)
    11181068{
    1119     static const EVP_CIPHER rc2_64_cbc = {
    1120         0,
    1121         RC2_BLOCK_SIZE,
    1122         8,
    1123         RC2_BLOCK_SIZE,
    1124         EVP_CIPH_CBC_MODE,
    1125         rc2_init,
    1126         rc2_do_cipher,
    1127         rc2_cleanup,
    1128         sizeof(struct rc2_cbc),
    1129         NULL,
    1130         NULL,
    1131         NULL,
    1132         NULL
    1133     };
    1134     return &rc2_64_cbc;
     1069    hcrypto_validate();
     1070    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc2_64_cbc);
    11351071}
    11361072
     
    11461082EVP_rc4(void)
    11471083{
    1148     printf("evp rc4\n");
    1149     abort();
    1150     return NULL;
     1084    hcrypto_validate();
     1085    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc4);
    11511086}
    11521087
     
    11621097EVP_rc4_40(void)
    11631098{
    1164     printf("evp rc4_40\n");
    1165     abort();
    1166     return NULL;
    1167 }
    1168 
    1169 /*
    1170  *
    1171  */
    1172 
    1173 static int
    1174 des_cbc_init(EVP_CIPHER_CTX *ctx,
    1175              const unsigned char * key,
    1176              const unsigned char * iv,
    1177              int encp)
    1178 {
    1179     DES_key_schedule *k = ctx->cipher_data;
    1180     DES_cblock deskey;
    1181     memcpy(&deskey, key, sizeof(deskey));
    1182     DES_set_key_unchecked(&deskey, k);
    1183     return 1;
    1184 }
    1185 
    1186 static int
    1187 des_cbc_do_cipher(EVP_CIPHER_CTX *ctx,
    1188                   unsigned char *out,
    1189                   const unsigned char *in,
    1190                   unsigned int size)
    1191 {
    1192     DES_key_schedule *k = ctx->cipher_data;
    1193     DES_cbc_encrypt(in, out, size,
    1194                     k, (DES_cblock *)ctx->iv, ctx->encrypt);
    1195     return 1;
    1196 }
    1197 
    1198 static int
    1199 des_cbc_cleanup(EVP_CIPHER_CTX *ctx)
    1200 {
    1201     memset(ctx->cipher_data, 0, sizeof(struct DES_key_schedule));
    1202     return 1;
     1099    hcrypto_validate();
     1100    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc4_40);
    12031101}
    12041102
     
    12141112EVP_des_cbc(void)
    12151113{
    1216     static const EVP_CIPHER des_ede3_cbc = {
    1217         0,
    1218         8,
    1219         8,
    1220         8,
    1221         EVP_CIPH_CBC_MODE,
    1222         des_cbc_init,
    1223         des_cbc_do_cipher,
    1224         des_cbc_cleanup,
    1225         sizeof(DES_key_schedule),
    1226         NULL,
    1227         NULL,
    1228         NULL,
    1229         NULL
    1230     };
    1231     return &des_ede3_cbc;
    1232 }
    1233 
    1234 /*
    1235  *
    1236  */
    1237 
    1238 struct des_ede3_cbc {
    1239     DES_key_schedule ks[3];
    1240 };
    1241 
    1242 static int
    1243 des_ede3_cbc_init(EVP_CIPHER_CTX *ctx,
    1244                   const unsigned char * key,
    1245                   const unsigned char * iv,
    1246                   int encp)
    1247 {
    1248     struct des_ede3_cbc *k = ctx->cipher_data;
    1249     DES_cblock deskey;
    1250 
    1251     memcpy(&deskey, key, sizeof(deskey));
    1252     DES_set_odd_parity(&deskey);
    1253     DES_set_key_unchecked(&deskey, &k->ks[0]);
    1254 
    1255     memcpy(&deskey, key + 8, sizeof(deskey));
    1256     DES_set_odd_parity(&deskey);
    1257     DES_set_key_unchecked(&deskey, &k->ks[1]);
    1258 
    1259     memcpy(&deskey, key + 16, sizeof(deskey));
    1260     DES_set_odd_parity(&deskey);
    1261     DES_set_key_unchecked(&deskey, &k->ks[2]);
    1262 
    1263     return 1;
    1264 }
    1265 
    1266 static int
    1267 des_ede3_cbc_do_cipher(EVP_CIPHER_CTX *ctx,
    1268                        unsigned char *out,
    1269                        const unsigned char *in,
    1270                        unsigned int size)
    1271 {
    1272     struct des_ede3_cbc *k = ctx->cipher_data;
    1273     DES_ede3_cbc_encrypt(in, out, size,
    1274                          &k->ks[0], &k->ks[1], &k->ks[2],
    1275                          (DES_cblock *)ctx->iv, ctx->encrypt);
    1276     return 1;
    1277 }
    1278 
    1279 static int
    1280 des_ede3_cbc_cleanup(EVP_CIPHER_CTX *ctx)
    1281 {
    1282     memset(ctx->cipher_data, 0, sizeof(struct des_ede3_cbc));
    1283     return 1;
     1114    hcrypto_validate();
     1115    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, des_cbc);
    12841116}
    12851117
     
    12951127EVP_des_ede3_cbc(void)
    12961128{
    1297     static const EVP_CIPHER des_ede3_cbc = {
    1298         0,
    1299         8,
    1300         24,
    1301         8,
    1302         EVP_CIPH_CBC_MODE,
    1303         des_ede3_cbc_init,
    1304         des_ede3_cbc_do_cipher,
    1305         des_ede3_cbc_cleanup,
    1306         sizeof(struct des_ede3_cbc),
    1307         NULL,
    1308         NULL,
    1309         NULL,
    1310         NULL
    1311     };
    1312     return &des_ede3_cbc;
     1129    hcrypto_validate();
     1130    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, des_ede3_cbc);
    13131131}
    13141132
     
    13241142EVP_aes_128_cbc(void)
    13251143{
    1326     return EVP_hcrypto_aes_128_cbc();
     1144    hcrypto_validate();
     1145    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_128_cbc);
    13271146}
    13281147
     
    13381157EVP_aes_192_cbc(void)
    13391158{
    1340     return EVP_hcrypto_aes_192_cbc();
     1159    hcrypto_validate();
     1160    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_192_cbc);
    13411161}
    13421162
     
    13521172EVP_aes_256_cbc(void)
    13531173{
    1354     return EVP_hcrypto_aes_256_cbc();
    1355 }
    1356 
    1357 static int
    1358 camellia_init(EVP_CIPHER_CTX *ctx,
    1359          const unsigned char * key,
    1360          const unsigned char * iv,
    1361          int encp)
    1362 {
    1363     CAMELLIA_KEY *k = ctx->cipher_data;
    1364     k->bits = ctx->cipher->key_len * 8;
    1365     CAMELLIA_set_key(key, ctx->cipher->key_len * 8, k);
    1366     return 1;
    1367 }
    1368 
    1369 static int
    1370 camellia_do_cipher(EVP_CIPHER_CTX *ctx,
    1371               unsigned char *out,
    1372               const unsigned char *in,
    1373               unsigned int size)
    1374 {
    1375     CAMELLIA_KEY *k = ctx->cipher_data;
    1376     CAMELLIA_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
    1377     return 1;
    1378 }
    1379 
    1380 static int
    1381 camellia_cleanup(EVP_CIPHER_CTX *ctx)
    1382 {
    1383     memset(ctx->cipher_data, 0, sizeof(CAMELLIA_KEY));
    1384     return 1;
     1174    hcrypto_validate();
     1175    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_256_cbc);
     1176}
     1177
     1178/**
     1179 * The AES-128 cipher type
     1180 *
     1181 * @return the AES-128 EVP_CIPHER pointer.
     1182 *
     1183 * @ingroup hcrypto_evp
     1184 */
     1185
     1186const EVP_CIPHER *
     1187EVP_aes_128_cfb8(void)
     1188{
     1189    hcrypto_validate();
     1190    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_128_cfb8);
     1191}
     1192
     1193/**
     1194 * The AES-192 cipher type
     1195 *
     1196 * @return the AES-192 EVP_CIPHER pointer.
     1197 *
     1198 * @ingroup hcrypto_evp
     1199 */
     1200
     1201const EVP_CIPHER *
     1202EVP_aes_192_cfb8(void)
     1203{
     1204    hcrypto_validate();
     1205    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_192_cfb8);
     1206}
     1207
     1208/**
     1209 * The AES-256 cipher type
     1210 *
     1211 * @return the AES-256 EVP_CIPHER pointer.
     1212 *
     1213 * @ingroup hcrypto_evp
     1214 */
     1215
     1216const EVP_CIPHER *
     1217EVP_aes_256_cfb8(void)
     1218{
     1219    hcrypto_validate();
     1220    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_256_cfb8);
    13851221}
    13861222
     
    13961232EVP_camellia_128_cbc(void)
    13971233{
    1398     static const EVP_CIPHER cipher = {
    1399         0,
    1400         16,
    1401         16,
    1402         16,
    1403         EVP_CIPH_CBC_MODE,
    1404         camellia_init,
    1405         camellia_do_cipher,
    1406         camellia_cleanup,
    1407         sizeof(CAMELLIA_KEY),
    1408         NULL,
    1409         NULL,
    1410         NULL,
    1411         NULL
    1412     };
    1413     return &cipher;
     1234    hcrypto_validate();
     1235    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, camellia_128_cbc);
    14141236}
    14151237
     
    14251247EVP_camellia_192_cbc(void)
    14261248{
    1427     static const EVP_CIPHER cipher = {
    1428         0,
    1429         16,
    1430         24,
    1431         16,
    1432         EVP_CIPH_CBC_MODE,
    1433         camellia_init,
    1434         camellia_do_cipher,
    1435         camellia_cleanup,
    1436         sizeof(CAMELLIA_KEY),
    1437         NULL,
    1438         NULL,
    1439         NULL,
    1440         NULL
    1441     };
    1442     return &cipher;
     1249    hcrypto_validate();
     1250    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, camellia_192_cbc);
    14431251}
    14441252
     
    14541262EVP_camellia_256_cbc(void)
    14551263{
    1456     static const EVP_CIPHER cipher = {
    1457         0,
    1458         16,
    1459         32,
    1460         16,
    1461         EVP_CIPH_CBC_MODE,
    1462         camellia_init,
    1463         camellia_do_cipher,
    1464         camellia_cleanup,
    1465         sizeof(CAMELLIA_KEY),
    1466         NULL,
    1467         NULL,
    1468         NULL,
    1469         NULL
    1470     };
    1471     return &cipher;
     1264    hcrypto_validate();
     1265    return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, camellia_256_cbc);
    14721266}
    14731267
     
    14841278    { "aes-192-cbc", EVP_aes_192_cbc },
    14851279    { "aes-256-cbc", EVP_aes_256_cbc },
     1280    { "aes-128-cfb8", EVP_aes_128_cfb8 },
     1281    { "aes-192-cfb8", EVP_aes_192_cfb8 },
     1282    { "aes-256-cfb8", EVP_aes_256_cfb8 },
    14861283    { "camellia-128-cbc", EVP_camellia_128_cbc },
    14871284    { "camellia-192-cbc", EVP_camellia_192_cbc },
     
    15481345               void *ivdata)
    15491346{
    1550     int ivlen, keylen, first = 0;
     1347    unsigned int ivlen, keylen;
     1348    int first = 0;
    15511349    unsigned int mds = 0, i;
    15521350    unsigned char *key = keydata;
  • trunk/server/source4/heimdal/lib/hcrypto/evp.h

    r414 r745  
    7575#define EVP_aes_192_cbc hc_EVP_aes_192_cbc
    7676#define EVP_aes_256_cbc hc_EVP_aes_256_cbc
    77 #define EVP_hcrypto_aes_128_cbc hc_EVP_hcrypto_aes_128_cbc
    78 #define EVP_hcrypto_aes_192_cbc hc_EVP_hcrypto_aes_192_cbc
    79 #define EVP_hcrypto_aes_256_cbc hc_EVP_hcrypto_aes_256_cbc
    80 #define EVP_hcrypto_aes_128_cts hc_EVP_hcrypto_aes_128_cts
    81 #define EVP_hcrypto_aes_192_cts hc_EVP_hcrypto_aes_192_cts
    82 #define EVP_hcrypto_aes_256_cts hc_EVP_hcrypto_aes_256_cts
     77#define EVP_aes_128_cfb8 hc_EVP_aes_128_cfb8
     78#define EVP_aes_192_cfb8 hc_EVP_aes_192_cfb8
     79#define EVP_aes_256_cfb8 hc_EVP_aes_256_cfb8
     80
    8381#define EVP_des_cbc hc_EVP_des_cbc
    8482#define EVP_des_ede3_cbc hc_EVP_des_ede3_cbc
     
    9997#define EVP_sha1 hc_EVP_sha1
    10098#define EVP_sha256 hc_EVP_sha256
     99#define EVP_sha384 hc_EVP_sha384
     100#define EVP_sha512 hc_EVP_sha512
    101101#define PKCS5_PBKDF2_HMAC_SHA1 hc_PKCS5_PBKDF2_HMAC_SHA1
    102102#define EVP_BytesToKey hc_EVP_BytesToKey
     
    107107#define EVP_CIPHER_CTX_ctrl hc_EVP_CIPHER_CTX_ctrl
    108108#define EVP_CIPHER_CTX_rand_key hc_EVP_CIPHER_CTX_rand_key
     109#define hcrypto_validate hc_hcrypto_validate
    109110
    110111/*
     
    135136#define EVP_CIPH_STREAM_CIPHER          0
    136137#define EVP_CIPH_CBC_MODE               2
     138#define EVP_CIPH_CFB8_MODE              4
    137139#define EVP_CIPH_MODE                   0x7
    138140
     141#define EVP_CIPH_VARIABLE_LENGTH        0x008 /* variable key length */
    139142#define EVP_CIPH_ALWAYS_CALL_INIT       0x020
    140143#define EVP_CIPH_RAND_KEY               0x200
     
    204207#endif
    205208
    206 
    207 #ifdef  __cplusplus
    208 extern "C" {
    209 #endif
     209#ifdef __cplusplus
     210#define HC_CPP_BEGIN extern "C" {
     211#define HC_CPP_END }
     212#else
     213#define HC_CPP_BEGIN
     214#define HC_CPP_END
     215#endif
     216
     217HC_CPP_BEGIN
    210218
    211219/*
     
    214222
    215223const EVP_MD *EVP_md_null(void);
    216 const EVP_MD *EVP_md2(void) HC_DEPRECATED_CRYPTO;
    217 const EVP_MD *EVP_md4(void) HC_DEPRECATED_CRYPTO;
    218 const EVP_MD *EVP_md5(void) HC_DEPRECATED_CRYPTO;
     224HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md2(void);
     225HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md4(void);
     226HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md5(void);
    219227const EVP_MD *EVP_sha(void);
    220228const EVP_MD *EVP_sha1(void);
    221229const EVP_MD *EVP_sha256(void);
     230const EVP_MD *EVP_sha384(void);
     231const EVP_MD *EVP_sha512(void);
    222232
    223233const EVP_CIPHER * EVP_aes_128_cbc(void);
    224234const EVP_CIPHER * EVP_aes_192_cbc(void);
    225235const EVP_CIPHER * EVP_aes_256_cbc(void);
    226 const EVP_CIPHER * EVP_hcrypto_aes_128_cbc(void);
    227 const EVP_CIPHER * EVP_hcrypto_aes_192_cbc(void);
    228 const EVP_CIPHER * EVP_hcrypto_aes_256_cbc(void);
    229 const EVP_CIPHER * EVP_hcrypto_aes_128_cts(void);
    230 const EVP_CIPHER * EVP_hcrypto_aes_192_cts(void);
    231 const EVP_CIPHER * EVP_hcrypto_aes_256_cts(void);
    232 const EVP_CIPHER * EVP_des_cbc(void) HC_DEPRECATED_CRYPTO;
     236const EVP_CIPHER * EVP_aes_128_cfb8(void);
     237const EVP_CIPHER * EVP_aes_192_cfb8(void);
     238const EVP_CIPHER * EVP_aes_256_cfb8(void);
     239HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_des_cbc(void);
    233240const EVP_CIPHER * EVP_des_ede3_cbc(void);
    234241const EVP_CIPHER * EVP_enc_null(void);
    235 const EVP_CIPHER * EVP_rc2_40_cbc(void) HC_DEPRECATED_CRYPTO;
    236 const EVP_CIPHER * EVP_rc2_64_cbc(void) HC_DEPRECATED_CRYPTO;
    237 const EVP_CIPHER * EVP_rc2_cbc(void) HC_DEPRECATED_CRYPTO;
     242HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_40_cbc(void);
     243HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_64_cbc(void);
     244HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_cbc(void);
    238245const EVP_CIPHER * EVP_rc4(void);
    239 const EVP_CIPHER * EVP_rc4_40(void) HC_DEPRECATED_CRYPTO;
     246HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc4_40(void);
    240247const EVP_CIPHER * EVP_camellia_128_cbc(void);
    241248const EVP_CIPHER * EVP_camellia_192_cbc(void);
    242249const EVP_CIPHER * EVP_camellia_256_cbc(void);
    243 
    244 /*
    245  *
    246  */
    247250
    248251size_t  EVP_MD_size(const EVP_MD *);
     
    319322void    OpenSSL_add_all_algorithms_noconf(void);
    320323
    321 #ifdef  __cplusplus
    322 }
    323 #endif
     324void
     325hcrypto_validate(void);
     326
     327HC_CPP_END
    324328
    325329#endif /* HEIM_EVP_H */
  • trunk/server/source4/heimdal/lib/hcrypto/hash.h

    r414 r745  
    3838#define __hash_h__
    3939
    40 #include <stdlib.h>
    41 #include <string.h>
    42 #include <stddef.h>
    4340#ifdef KRB5
    4441#include <krb5-types.h>
    4542#endif
     43#include <roken.h>
    4644
    4745#ifndef min
     
    6967}
    7068
     69static inline uint64_t
     70cshift64 (uint64_t x, unsigned int n)
     71{
     72  return ((uint64_t)x << (uint64_t)n) | ((uint64_t)x >> ((uint64_t)64 - (uint64_t)n));
     73}
     74
    7175#endif /* __hash_h__ */
  • trunk/server/source4/heimdal/lib/hcrypto/hmac.c

    r414 r745  
    5353    }
    5454    if (ctx->opad) {
    55         memset(ctx->ipad, 0, ctx->key_length);
     55        memset(ctx->opad, 0, EVP_MD_block_size(ctx->md));
    5656        free(ctx->opad);
    5757        ctx->opad = NULL;
    5858    }
    5959    if (ctx->ipad) {
    60         memset(ctx->ipad, 0, ctx->key_length);
     60        memset(ctx->ipad, 0, EVP_MD_block_size(ctx->md));
    6161        free(ctx->ipad);
    6262        ctx->ipad = NULL;
     
    122122        p[i] ^= ((const unsigned char *)key)[i];
    123123
    124     ctx->ctx = EVP_MD_CTX_create();
     124    if (ctx->ctx == NULL)
     125        ctx->ctx = EVP_MD_CTX_create();
    125126
    126127    EVP_DigestInit_ex(ctx->ctx, ctx->md, ctx->engine);
  • trunk/server/source4/heimdal/lib/hcrypto/md4.c

    r414 r745  
    192192            int i;
    193193            uint32_t current[16];
    194             struct x32 *u = (struct x32*)m->save;
     194            struct x32 *us = (struct x32*)m->save;
    195195            for(i = 0; i < 8; i++){
    196                 current[2*i+0] = swap_uint32_t(u[i].a);
    197                 current[2*i+1] = swap_uint32_t(u[i].b);
     196                current[2*i+0] = swap_uint32_t(us[i].a);
     197                current[2*i+1] = swap_uint32_t(us[i].b);
    198198            }
    199199            calc(m, current);
  • trunk/server/source4/heimdal/lib/hcrypto/md5.c

    r414 r745  
    216216      int i;
    217217      uint32_t current[16];
    218       struct x32 *u = (struct x32*)m->save;
     218      struct x32 *us = (struct x32*)m->save;
    219219      for(i = 0; i < 8; i++){
    220         current[2*i+0] = swap_uint32_t(u[i].a);
    221         current[2*i+1] = swap_uint32_t(u[i].b);
     220        current[2*i+0] = swap_uint32_t(us[i].a);
     221        current[2*i+1] = swap_uint32_t(us[i].b);
    222222      }
    223223      calc(m, current);
  • trunk/server/source4/heimdal/lib/hcrypto/rand-fortuna.c

    r414 r745  
    3535#include <stdlib.h>
    3636#include <rand.h>
    37 
     37#include <heim_threads.h>
     38
     39#ifdef KRB5
     40#include <krb5-types.h>
     41#endif
    3842#include <roken.h>
    3943
     
    440444
    441445/*
     446 * This mutex protects all of the above static elements from concurrent
     447 * access by multiple threads
     448 */
     449static HEIMDAL_MUTEX fortuna_mutex = HEIMDAL_MUTEX_INITIALIZER;
     450
     451/*
    442452 * Try our best to do an inital seed
    443453 */
    444454#define INIT_BYTES      128
     455
     456/*
     457 * fortuna_mutex must be held across calls to this function
     458 */
    445459
    446460static int
     
    452466        abort();
    453467
     468#ifndef NO_RAND_UNIX_METHOD
    454469    {
    455470        unsigned char buf[INIT_BYTES];
     
    460475        }
    461476    }
     477#endif
    462478#ifdef HAVE_ARC4RANDOM
    463479    {
     
    471487    }
    472488#endif
     489#ifndef NO_RAND_EGD_METHOD
    473490    /*
    474491     * Only to get egd entropy if /dev/random or arc4rand failed since
     
    483500        }
    484501    }
     502#endif
    485503    /*
    486504     * Fall back to gattering data from timer and secret files, this
     
    522540        add_entropy(&main_state, (void *)&tv, sizeof(tv));
    523541    }
     542#ifdef HAVE_GETUID
    524543    {
    525544        uid_t u = getuid();
    526545        add_entropy(&main_state, (void *)&u, sizeof(u));
    527546    }
     547#endif
    528548    return entropy_p;
    529549}
    530550
     551/*
     552 * fortuna_mutex must be held by callers of this function
     553 */
    531554static int
    532555fortuna_init(void)
     
    547570fortuna_seed(const void *indata, int size)
    548571{
     572    HEIMDAL_MUTEX_lock(&fortuna_mutex);
     573
    549574    fortuna_init();
    550575    add_entropy(&main_state, indata, size);
    551576    if (size >= INIT_BYTES)
    552577        have_entropy = 1;
     578
     579    HEIMDAL_MUTEX_unlock(&fortuna_mutex);
    553580}
    554581
     
    556583fortuna_bytes(unsigned char *outdata, int size)
    557584{
     585    int ret = 0;
     586
     587    HEIMDAL_MUTEX_lock(&fortuna_mutex);
     588
    558589    if (!fortuna_init())
    559         return 0;
     590        goto out;
     591
    560592    resend_bytes += size;
    561593    if (resend_bytes > FORTUNA_RESEED_BYTE || resend_bytes < size) {
     
    564596    }
    565597    extract_data(&main_state, size, outdata);
    566     return 1;
     598    ret = 1;
     599
     600out:
     601    HEIMDAL_MUTEX_unlock(&fortuna_mutex);
     602
     603    return ret;
    567604}
    568605
     
    570607fortuna_cleanup(void)
    571608{
     609    HEIMDAL_MUTEX_lock(&fortuna_mutex);
     610
    572611    init_done = 0;
    573612    have_entropy = 0;
    574613    memset(&main_state, 0, sizeof(main_state));
     614
     615    HEIMDAL_MUTEX_unlock(&fortuna_mutex);
    575616}
    576617
     
    590631fortuna_status(void)
    591632{
    592     return fortuna_init() ? 1 : 0;
     633    int result;
     634
     635    HEIMDAL_MUTEX_lock(&fortuna_mutex);
     636    result = fortuna_init();
     637    HEIMDAL_MUTEX_unlock(&fortuna_mutex);
     638
     639    return result ? 1 : 0;
    593640}
    594641
  • trunk/server/source4/heimdal/lib/hcrypto/rand-unix.c

    r414 r745  
    4343#include "randi.h"
    4444
    45 static int random_fd = -1;
    46 static HEIMDAL_MUTEX random_mutex = HEIMDAL_MUTEX_INITIALIZER;
    47 
    4845/*
    4946 * Unix /dev/random
    5047 */
    5148
    52 static int
    53 get_device_fd(int flags)
     49int
     50_hc_unix_device_fd(int flags, const char **fn)
    5451{
    5552    static const char *rnd_devices[] = {
     
    6562        int fd = open(*p, flags | O_NDELAY);
    6663        if(fd >= 0) {
     64            if (fn)
     65                *fn = *p;
    6766            rk_cloexec(fd);
    6867            return fd;
     
    8079        return;
    8180
    82     fd = get_device_fd(O_WRONLY);
     81    fd = _hc_unix_device_fd(O_WRONLY, NULL);
    8382    if (fd < 0)
    8483        return;
     
    9493{
    9594    ssize_t count;
    96     int once = 0;
     95    int fd;
    9796
    98     if (size <= 0)
     97    if (size < 0)
     98        return 0;
     99    else if (size == 0)
     100        return 1;
     101
     102    fd = _hc_unix_device_fd(O_RDONLY, NULL);
     103    if (fd < 0)
    99104        return 0;
    100105
    101     HEIMDAL_MUTEX_lock(&random_mutex);
    102     if (random_fd == -1) {
    103     retry:
    104         random_fd = get_device_fd(O_RDONLY);
    105         if (random_fd < 0) {
    106             HEIMDAL_MUTEX_unlock(&random_mutex);
    107             return 0;
    108         }
    109     }
    110 
    111106    while (size > 0) {
    112         HEIMDAL_MUTEX_unlock(&random_mutex);
    113         count = read (random_fd, outdata, size);
    114         HEIMDAL_MUTEX_lock(&random_mutex);
    115         if (random_fd < 0) {
    116             if (errno == EINTR)
    117                 continue;
    118             else if (errno == EBADF && once++ == 0) {
    119                 close(random_fd);
    120                 random_fd = -1;
    121                 goto retry;
    122             }
    123             return 0;
    124         } else if (count <= 0) {
    125             HEIMDAL_MUTEX_unlock(&random_mutex);
     107        count = read(fd, outdata, size);
     108        if (count < 0 && errno == EINTR)
     109            continue;
     110        else if (count <= 0) {
     111            close(fd);
    126112            return 0;
    127113        }
     
    129115        size -= count;
    130116    }
    131     HEIMDAL_MUTEX_unlock(&random_mutex);
     117    close(fd);
    132118
    133119    return 1;
     
    156142    int fd;
    157143
    158     fd = get_device_fd(O_RDONLY);
     144    fd = _hc_unix_device_fd(O_RDONLY, NULL);
    159145    if (fd < 0)
    160146        return 0;
  • trunk/server/source4/heimdal/lib/hcrypto/rand.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    4547#endif
    4648
     49#ifdef _WIN32
     50#include<shlobj.h>
     51#endif
     52
    4753/**
    4854 * @page page_rand RAND - random number
     
    5965    if (selected_meth != NULL)
    6066        return;
    61 #ifdef __APPLE__
     67#if defined(_WIN32)
     68    selected_meth = &hc_rand_w32crypto_method;
     69#elif defined(__APPLE__)
    6270    selected_meth = &hc_rand_unix_method;
    6371#else
     
    96104RAND_bytes(void *outdata, size_t size)
    97105{
     106    if (size == 0)
     107        return 1;
    98108    init_method();
    99109    return (*selected_meth->bytes)(outdata, size);
     
    342352    if (!issuid()) {
    343353        e = getenv("RANDFILE");
    344         if (e == NULL) {
     354        if (e == NULL)
    345355            e = getenv("HOME");
    346             if (e)
    347                 pathp = 1;
    348         }
    349     }
     356        if (e)
     357            pathp = 1;
     358    }
     359
     360#ifndef _WIN32
    350361    /*
    351362     * Here we really want to call getpwuid(getuid()) but this will
    352363     * cause recursive lookups if the nss library uses
    353364     * gssapi/krb5/hcrypto to authenticate to the ldap servers.
     365     *
     366     * So at least return the unix /dev/random if we have one
    354367     */
     368    if (e == NULL) {
     369        int fd;
     370
     371        fd = _hc_unix_device_fd(O_RDONLY, &e);
     372        if (fd >= 0)
     373            close(fd);
     374    }
     375#else  /* Win32 */
     376
     377    if (e == NULL) {
     378        char profile[MAX_PATH];
     379
     380        if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL,
     381                            SHGFP_TYPE_CURRENT, profile) == S_OK) {
     382            ret = snprintf(filename, size, "%s\\.rnd", profile);
     383
     384            if (ret > 0 && ret < size)
     385                return filename;
     386        }
     387    }
     388
     389#endif
    355390
    356391    if (e == NULL)
  • trunk/server/source4/heimdal/lib/hcrypto/rand.h

    r414 r745  
    4242typedef struct RAND_METHOD RAND_METHOD;
    4343
    44 #include <hcrypto/bn.h>
    4544#include <hcrypto/engine.h>
    4645
     
    6362#define RAND_egd_method hc_RAND_egd_method
    6463#define RAND_unix_method hc_RAND_unix_method
     64#define RAND_w32crypto_method hc_RAND_w32crypto_method
    6565
    6666/*
     
    105105const RAND_METHOD *     RAND_unix_method(void);
    106106const RAND_METHOD *     RAND_egd_method(void);
     107const RAND_METHOD *     RAND_w32crypto_method(void);
    107108
    108109#endif /* _HEIM_RAND_H */
  • trunk/server/source4/heimdal/lib/hcrypto/randi.h

    r414 r745  
    4343extern const RAND_METHOD hc_rand_egd_method;
    4444extern const RAND_METHOD hc_rand_timer_method;
     45extern const RAND_METHOD hc_rand_w32crypto_method;
    4546
    4647const RAND_METHOD * RAND_timer_method(void);
     48int _hc_unix_device_fd(int, const char **);
    4749
    4850#endif /* _HEIM_RANDI_H */
  • trunk/server/source4/heimdal/lib/hcrypto/rc4.c

    r414 r745  
    4646
    4747void
    48 RC4_set_key(RC4_KEY *key, const int len, unsigned char *data)
     48RC4_set_key(RC4_KEY *key, const int len, const unsigned char *data)
    4949{
    5050    int i, j;
  • trunk/server/source4/heimdal/lib/hcrypto/rc4.h

    r414 r745  
    4343} RC4_KEY;
    4444
    45 void RC4_set_key(RC4_KEY *, const int, unsigned char *);
     45void RC4_set_key(RC4_KEY *, const int, const unsigned char *);
    4646void RC4(RC4_KEY *, const int, const unsigned char *, unsigned char *);
  • trunk/server/source4/heimdal/lib/hcrypto/rijndael-alg-fst.c

    r414 r745  
    3232
    3333
     34#include <stdlib.h>
    3435#ifdef KRB5
    3536#include <krb5-types.h>
    3637#endif
    3738
    38 #include <rijndael-alg-fst.h>
    39 
    40 /* the file should not be used from outside */
    41 typedef uint8_t                 u8;
    42 typedef uint16_t                u16;   
    43 typedef uint32_t                u32;
     39#include "rijndael-alg-fst.h"
    4440
    4541/*
     
    5753*/
    5854
    59 static const u32 Te0[256] = {
     55static const uint32_t Te0[256] = {
    6056    0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
    6157    0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
     
    123119    0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
    124120};
    125 static const u32 Te1[256] = {
     121static const uint32_t Te1[256] = {
    126122    0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
    127123    0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
     
    189185    0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
    190186};
    191 static const u32 Te2[256] = {
     187static const uint32_t Te2[256] = {
    192188    0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
    193189    0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
     
    255251    0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
    256252};
    257 static const u32 Te3[256] = {
     253static const uint32_t Te3[256] = {
    258254
    259255    0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
     
    322318    0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
    323319};
    324 static const u32 Te4[256] = {
     320static const uint32_t Te4[256] = {
    325321    0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
    326322    0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
     
    388384    0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
    389385};
    390 static const u32 Td0[256] = {
     386static const uint32_t Td0[256] = {
    391387    0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
    392388    0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
     
    454450    0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
    455451};
    456 static const u32 Td1[256] = {
     452static const uint32_t Td1[256] = {
    457453    0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
    458454    0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
     
    520516    0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
    521517};
    522 static const u32 Td2[256] = {
     518static const uint32_t Td2[256] = {
    523519    0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
    524520    0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
     
    587583    0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
    588584};
    589 static const u32 Td3[256] = {
     585static const uint32_t Td3[256] = {
    590586    0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
    591587    0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
     
    653649    0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
    654650};
    655 static const u32 Td4[256] = {
     651static const uint32_t Td4[256] = {
    656652    0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
    657653    0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
     
    719715    0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
    720716};
    721 static const u32 rcon[] = {
     717static const uint32_t rcon[] = {
    722718        0x01000000, 0x02000000, 0x04000000, 0x08000000,
    723719        0x10000000, 0x20000000, 0x40000000, 0x80000000,
     
    728724
    729725#ifdef _MSC_VER
    730 #define GETU32(p) SWAP(*((u32 *)(p)))
    731 #define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
     726#define GETU32(p) SWAP(*((uint32_t *)(p)))
     727#define PUTU32(ct, st) { *((uint32_t *)(ct)) = SWAP((st)); }
    732728#else
    733 #define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] <<  8) ^ ((u32)(pt)[3]))
    734 #define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >>  8); (ct)[3] = (u8)(st); }
     729#define GETU32(pt) (((uint32_t)(pt)[0] << 24) ^ ((uint32_t)(pt)[1] << 16) ^ ((uint32_t)(pt)[2] <<  8) ^ ((uint32_t)(pt)[3]))
     730#define PUTU32(ct, st) { (ct)[0] = (uint8_t)((st) >> 24); (ct)[1] = (uint8_t)((st) >> 16); (ct)[2] = (uint8_t)((st) >>  8); (ct)[3] = (uint8_t)(st); }
    735731#endif
    736732
     
    740736 * @return      the number of rounds for the given cipher key size.
    741737 */
    742 int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits) {
     738int rijndaelKeySetupEnc(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits) {
    743739        int i = 0;
    744         u32 temp;
     740        uint32_t temp;
    745741
    746742        rk[0] = GETU32(cipherKey     );
     
    826822 * @return      the number of rounds for the given cipher key size.
    827823 */
    828 int rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits) {
     824int rijndaelKeySetupDec(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits) {
    829825        int Nr, i, j;
    830         u32 temp;
     826        uint32_t temp;
    831827
    832828        /* expand the cipher key: */
     
    866862}
    867863
    868 void rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16]) {
    869         u32 s0, s1, s2, s3, t0, t1, t2, t3;
     864void rijndaelEncrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t pt[16], uint8_t ct[16]) {
     865        uint32_t s0, s1, s2, s3, t0, t1, t2, t3;
    870866#ifndef FULL_UNROLL
    871867    int r;
     
    10471043}
    10481044
    1049 void rijndaelDecrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], u8 pt[16]) {
    1050         u32 s0, s1, s2, s3, t0, t1, t2, t3;
     1045void rijndaelDecrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t ct[16], uint8_t pt[16]) {
     1046        uint32_t s0, s1, s2, s3, t0, t1, t2, t3;
    10511047#ifndef FULL_UNROLL
    10521048    int r;
  • trunk/server/source4/heimdal/lib/hcrypto/rnd_keys.c

    r414 r745  
    4040#include <krb5-types.h>
    4141#endif
     42#include <stdlib.h>
     43
    4244#include <des.h>
    4345#include <rand.h>
    44 
    45 #include <stdlib.h>
    4646
    4747#undef __attribute__
  • trunk/server/source4/heimdal/lib/hcrypto/rsa.c

    r414 r745  
    3939#include <rfc2459_asn1.h>
    4040
     41#include <der.h>
     42
    4143#include <rsa.h>
     44
     45#include "common.h"
    4246
    4347#include <roken.h>
     
    4852 * RSA is named by its inventors (Ron Rivest, Adi Shamir, and Leonard
    4953 * Adleman) (published in 1977), patented expired in 21 September 2000.
     54 *
     55 *
     56 * Speed for RSA in seconds
     57 *   no key blinding
     58 *   1000 iteration,
     59 *   same rsa keys (1024 and 2048)
     60 *   operation performed each eteration sign, verify, encrypt, decrypt on a random bit pattern
     61 *
     62 * name         1024    2048    4098
     63 * =================================   
     64 * gmp:          0.73     6.60   44.80
     65 * tfm:          2.45       --      --
     66 * ltm:          3.79    20.74  105.41  (default in hcrypto)
     67 * openssl:      4.04    11.90   82.59
     68 * cdsa:        15.89   102.89  721.40
     69 * imath:       40.62       --      --
    5070 *
    5171 * See the library functions here: @ref hcrypto_rsa
     
    238258
    239259void *
    240 RSA_get_app_data(RSA *rsa)
     260RSA_get_app_data(const RSA *rsa)
    241261{
    242262    return rsa->ex_data.sk;
     
    279299    }
    280300
    281     if (ret == sizeof(inbuf) && memcmp(buffer, inbuf, sizeof(inbuf)) == 0) {
     301    if (ret == sizeof(inbuf) && ct_memcmp(buffer, inbuf, sizeof(inbuf)) == 0) {
    282302        free(buffer);
    283303        return 1;
     
    304324RSAFUNC(RSA_private_decrypt, (r)->meth->rsa_priv_dec(flen, f, t, r, p))
    305325
    306 /* XXX */
     326static const heim_octet_string null_entry_oid = { 2, rk_UNCONST("\x05\x00") };
     327
     328static const unsigned sha1_oid_tree[] = { 1, 3, 14, 3, 2, 26 };
     329static const AlgorithmIdentifier _signature_sha1_data = {
     330    { 6, rk_UNCONST(sha1_oid_tree) }, rk_UNCONST(&null_entry_oid)
     331};
     332static const unsigned sha256_oid_tree[] = { 2, 16, 840, 1, 101, 3, 4, 2, 1 };
     333static const AlgorithmIdentifier _signature_sha256_data = {
     334    { 9, rk_UNCONST(sha256_oid_tree) }, rk_UNCONST(&null_entry_oid)
     335};
     336static const unsigned md5_oid_tree[] = { 1, 2, 840, 113549, 2, 5 };
     337static const AlgorithmIdentifier _signature_md5_data = {
     338    { 6, rk_UNCONST(md5_oid_tree) }, rk_UNCONST(&null_entry_oid)
     339};
     340
     341
    307342int
    308343RSA_sign(int type, const unsigned char *from, unsigned int flen,
    309344         unsigned char *to, unsigned int *tlen, RSA *rsa)
    310345{
    311     return -1;
     346    if (rsa->meth->rsa_sign)
     347        return rsa->meth->rsa_sign(type, from, flen, to, tlen, rsa);
     348
     349    if (rsa->meth->rsa_priv_enc) {
     350        heim_octet_string indata;
     351        DigestInfo di;
     352        size_t size;
     353        int ret;
     354
     355        memset(&di, 0, sizeof(di));
     356
     357        if (type == NID_sha1) {
     358            di.digestAlgorithm = _signature_sha1_data;
     359        } else if (type == NID_md5) {
     360            di.digestAlgorithm = _signature_md5_data;
     361        } else if (type == NID_sha256) {
     362            di.digestAlgorithm = _signature_sha256_data;
     363        } else
     364            return -1;
     365
     366        di.digest.data = rk_UNCONST(from);
     367        di.digest.length = flen;
     368
     369        ASN1_MALLOC_ENCODE(DigestInfo,
     370                           indata.data,
     371                           indata.length,
     372                           &di,
     373                           &size,
     374                           ret);
     375        if (ret)
     376            return ret;
     377        if (indata.length != size)
     378            abort();
     379
     380        ret = rsa->meth->rsa_priv_enc(indata.length, indata.data, to,
     381                                      rsa, RSA_PKCS1_PADDING);
     382        free(indata.data);
     383        if (ret > 0) {
     384            *tlen = ret;
     385            ret = 1;
     386        } else
     387            ret = 0;
     388
     389        return ret;
     390    }
     391
     392    return 0;
    312393}
    313394
    314395int
    315396RSA_verify(int type, const unsigned char *from, unsigned int flen,
    316            unsigned char *to, unsigned int tlen, RSA *rsa)
    317 {
    318     return -1;
     397           unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
     398{
     399    if (rsa->meth->rsa_verify)
     400        return rsa->meth->rsa_verify(type, from, flen, sigbuf, siglen, rsa);
     401
     402    if (rsa->meth->rsa_pub_dec) {
     403        const AlgorithmIdentifier *digest_alg;
     404        void *data;
     405        DigestInfo di;
     406        size_t size;
     407        int ret, ret2;
     408
     409        data = malloc(RSA_size(rsa));
     410        if (data == NULL)
     411            return -1;
     412
     413        memset(&di, 0, sizeof(di));
     414
     415        ret = rsa->meth->rsa_pub_dec(siglen, sigbuf, data, rsa, RSA_PKCS1_PADDING);
     416        if (ret <= 0) {
     417            free(data);
     418            return -2;
     419        }
     420
     421        ret2 = decode_DigestInfo(data, ret, &di, &size);
     422        free(data);
     423        if (ret2 != 0)
     424            return -3;
     425        if (ret != size) {
     426            free_DigestInfo(&di);
     427            return -4;
     428        }
     429
     430        if (flen != di.digest.length || memcmp(di.digest.data, from, flen) != 0) {
     431            free_DigestInfo(&di);
     432            return -5;
     433        }
     434
     435        if (type == NID_sha1) {
     436            digest_alg = &_signature_sha1_data;
     437        } else if (type == NID_md5) {
     438            digest_alg = &_signature_md5_data;
     439        } else if (type == NID_sha256) {
     440            digest_alg = &_signature_sha256_data;
     441        } else {
     442            free_DigestInfo(&di);
     443            return -1;
     444        }
     445       
     446        ret = der_heim_oid_cmp(&digest_alg->algorithm,
     447                               &di.digestAlgorithm.algorithm);
     448        free_DigestInfo(&di);
     449       
     450        if (ret != 0)
     451            return 0;
     452        return 1;
     453    }
     454
     455    return 0;
    319456}
    320457
     
    381518}
    382519
    383 extern const RSA_METHOD hc_rsa_imath_method;
    384 #ifdef HAVE_GMP
    385 static const RSA_METHOD *default_rsa_method = &hc_rsa_gmp_method;
    386 #else
    387 static const RSA_METHOD *default_rsa_method = &hc_rsa_imath_method;
    388 #endif
     520extern const RSA_METHOD hc_rsa_gmp_method;
     521extern const RSA_METHOD hc_rsa_tfm_method;
     522extern const RSA_METHOD hc_rsa_ltm_method;
     523static const RSA_METHOD *default_rsa_method = &hc_rsa_ltm_method;
     524
    389525
    390526const RSA_METHOD *
     
    403539 *
    404540 */
    405 
    406 static BIGNUM *
    407 heim_int2BN(const heim_integer *i)
    408 {
    409     BIGNUM *bn;
    410 
    411     bn = BN_bin2bn(i->data, i->length, NULL);
    412     if (bn)
    413         BN_set_negative(bn, i->negative);
    414     return bn;
    415 }
    416 
    417 static int
    418 bn2heim_int(BIGNUM *bn, heim_integer *integer)
    419 {
    420     integer->length = BN_num_bytes(bn);
    421     integer->data = malloc(integer->length);
    422     if (integer->data == NULL) {
    423         integer->length = 0;
    424         return ENOMEM;
    425     }
    426     BN_bn2bin(bn, integer->data);
    427     integer->negative = BN_is_negative(bn);
    428     return 0;
    429 }
    430 
    431541
    432542RSA *
     
    452562    }
    453563
    454     k->n = heim_int2BN(&data.modulus);
    455     k->e = heim_int2BN(&data.publicExponent);
    456     k->d = heim_int2BN(&data.privateExponent);
    457     k->p = heim_int2BN(&data.prime1);
    458     k->q = heim_int2BN(&data.prime2);
    459     k->dmp1 = heim_int2BN(&data.exponent1);
    460     k->dmq1 = heim_int2BN(&data.exponent2);
    461     k->iqmp = heim_int2BN(&data.coefficient);
     564    k->n = _hc_integer_to_BN(&data.modulus, NULL);
     565    k->e = _hc_integer_to_BN(&data.publicExponent, NULL);
     566    k->d = _hc_integer_to_BN(&data.privateExponent, NULL);
     567    k->p = _hc_integer_to_BN(&data.prime1, NULL);
     568    k->q = _hc_integer_to_BN(&data.prime2, NULL);
     569    k->dmp1 = _hc_integer_to_BN(&data.exponent1, NULL);
     570    k->dmq1 = _hc_integer_to_BN(&data.exponent2, NULL);
     571    k->iqmp = _hc_integer_to_BN(&data.coefficient, NULL);
    462572    free_RSAPrivateKey(&data);
    463573
     
    486596    memset(&data, 0, sizeof(data));
    487597
    488     ret  = bn2heim_int(rsa->n, &data.modulus);
    489     ret |= bn2heim_int(rsa->e, &data.publicExponent);
    490     ret |= bn2heim_int(rsa->d, &data.privateExponent);
    491     ret |= bn2heim_int(rsa->p, &data.prime1);
    492     ret |= bn2heim_int(rsa->q, &data.prime2);
    493     ret |= bn2heim_int(rsa->dmp1, &data.exponent1);
    494     ret |= bn2heim_int(rsa->dmq1, &data.exponent2);
    495     ret |= bn2heim_int(rsa->iqmp, &data.coefficient);
     598    ret  = _hc_BN_to_integer(rsa->n, &data.modulus);
     599    ret |= _hc_BN_to_integer(rsa->e, &data.publicExponent);
     600    ret |= _hc_BN_to_integer(rsa->d, &data.privateExponent);
     601    ret |= _hc_BN_to_integer(rsa->p, &data.prime1);
     602    ret |= _hc_BN_to_integer(rsa->q, &data.prime2);
     603    ret |= _hc_BN_to_integer(rsa->dmp1, &data.exponent1);
     604    ret |= _hc_BN_to_integer(rsa->dmq1, &data.exponent2);
     605    ret |= _hc_BN_to_integer(rsa->iqmp, &data.coefficient);
    496606    if (ret) {
    497607        free_RSAPrivateKey(&data);
     
    531641    memset(&data, 0, sizeof(data));
    532642
    533     if (bn2heim_int(rsa->n, &data.modulus) ||
    534         bn2heim_int(rsa->e, &data.publicExponent))
     643    if (_hc_BN_to_integer(rsa->n, &data.modulus) ||
     644        _hc_BN_to_integer(rsa->e, &data.publicExponent))
    535645    {
    536646        free_RSAPublicKey(&data);
     
    560670    return size;
    561671}
     672
     673RSA *
     674d2i_RSAPublicKey(RSA *rsa, const unsigned char **pp, size_t len)
     675{
     676    RSAPublicKey data;
     677    RSA *k = rsa;
     678    size_t size;
     679    int ret;
     680
     681    ret = decode_RSAPublicKey(*pp, len, &data, &size);
     682    if (ret)
     683        return NULL;
     684
     685    *pp += size;
     686
     687    if (k == NULL) {
     688        k = RSA_new();
     689        if (k == NULL) {
     690            free_RSAPublicKey(&data);
     691            return NULL;
     692        }
     693    }
     694
     695    k->n = _hc_integer_to_BN(&data.modulus, NULL);
     696    k->e = _hc_integer_to_BN(&data.publicExponent, NULL);
     697
     698    free_RSAPublicKey(&data);
     699
     700    if (k->n == NULL || k->e == NULL) {
     701        RSA_free(k);
     702        return NULL;
     703    }
     704       
     705    return k;
     706}
  • trunk/server/source4/heimdal/lib/hcrypto/rsa.h

    r414 r745  
    4141/* symbol renaming */
    4242#define RSA_null_method hc_RSA_null_method
    43 #define RSA_imath_method hc_RSA_imath_method
     43#define RSA_ltm_method hc_RSA_ltm_method
    4444#define RSA_gmp_method hc_RSA_gmp_method
     45#define RSA_tfm_method hc_RSA_tfm_method
    4546#define RSA_new hc_RSA_new
    4647#define RSA_new_method hc_RSA_new_method
     
    6566#define i2d_RSAPrivateKey hc_i2d_RSAPrivateKey
    6667#define i2d_RSAPublicKey hc_i2d_RSAPublicKey
     68#define d2i_RSAPublicKey hc_d2i_RSAPublicKey
    6769
    6870/*
     
    134136
    135137const RSA_METHOD *RSA_null_method(void);
    136 const RSA_METHOD *RSA_imath_method(void);
    137138const RSA_METHOD *RSA_gmp_method(void);
     139const RSA_METHOD *RSA_tfm_method(void);
     140const RSA_METHOD *RSA_ltm_method(void);
    138141
    139142/*
     
    153156
    154157int     RSA_set_app_data(RSA *, void *arg);
    155 void *  RSA_get_app_data(RSA *);
     158void *  RSA_get_app_data(const RSA *);
    156159
    157160int     RSA_check_key(const RSA *);
     
    174177
    175178int     i2d_RSAPublicKey(RSA *, unsigned char **);
     179RSA *   d2i_RSAPublicKey(RSA *, const unsigned char **, size_t);
    176180
    177181#endif /* _HEIM_RSA_H */
  • trunk/server/source4/heimdal/lib/hcrypto/sha.c

    r414 r745  
    241241#if !defined(WORDS_BIGENDIAN) || defined(_CRAY)
    242242      int i;
    243       uint32_t current[16];
    244       struct x32 *u = (struct x32*)m->save;
     243      uint32_t SHA1current[16];
     244      struct x32 *us = (struct x32*)m->save;
    245245      for(i = 0; i < 8; i++){
    246         current[2*i+0] = swap_uint32_t(u[i].a);
    247         current[2*i+1] = swap_uint32_t(u[i].b);
     246        SHA1current[2*i+0] = swap_uint32_t(us[i].a);
     247        SHA1current[2*i+1] = swap_uint32_t(us[i].b);
    248248      }
    249       calc(m, current);
     249      calc(m, SHA1current);
    250250#else
    251251      calc(m, (uint32_t*)m->save);
  • trunk/server/source4/heimdal/lib/hcrypto/sha.h

    r414 r745  
    4444#define SHA256_Update hc_SHA256_Update
    4545#define SHA256_Final hc_SHA256_Final
     46#define SHA384_Init hc_SHA384_Init
     47#define SHA384_Update hc_SHA384_Update
     48#define SHA384_Final hc_SHA384_Final
     49#define SHA512_Init hc_SHA512_Init
     50#define SHA512_Update hc_SHA512_Update
     51#define SHA512_Final hc_SHA512_Final
    4652
    4753/*
     
    8187void SHA256_Final (void *, SHA256_CTX *);
    8288
     89/*
     90 * SHA-2 512
     91 */
     92
     93#define SHA512_DIGEST_LENGTH 64
     94
     95struct hc_sha512state {
     96  uint64_t sz[2];
     97  uint64_t counter[8];
     98  unsigned char save[128];
     99};
     100
     101typedef struct hc_sha512state SHA512_CTX;
     102
     103void SHA512_Init (SHA512_CTX *);
     104void SHA512_Update (SHA512_CTX *, const void *, size_t);
     105void SHA512_Final (void *, SHA512_CTX *);
     106
     107#define SHA384_DIGEST_LENGTH 48
     108
     109typedef struct hc_sha512state SHA384_CTX;
     110
     111void SHA384_Init (SHA384_CTX *);
     112void SHA384_Update (SHA384_CTX *, const void *, size_t);
     113void SHA384_Final (void *, SHA384_CTX *);
     114
    83115#endif /* HEIM_SHA_H */
  • trunk/server/source4/heimdal/lib/hcrypto/sha256.c

    r414 r745  
    184184            int i;
    185185            uint32_t current[16];
    186             struct x32 *u = (struct x32*)m->save;
     186            struct x32 *us = (struct x32*)m->save;
    187187            for(i = 0; i < 8; i++){
    188                 current[2*i+0] = swap_uint32_t(u[i].a);
    189                 current[2*i+1] = swap_uint32_t(u[i].b);
     188                current[2*i+0] = swap_uint32_t(us[i].a);
     189                current[2*i+1] = swap_uint32_t(us[i].b);
    190190            }
    191191            calc(m, current);
  • trunk/server/source4/heimdal/lib/hcrypto/ui.c

    r414 r745  
    3838#include <string.h>
    3939#include <signal.h>
     40#ifdef HAVE_TERMIOS_H
    4041#include <termios.h>
     42#endif
    4143#include <roken.h>
    4244
    4345#include <ui.h>
     46#ifdef HAVE_CONIO_H
     47#include <conio.h>
     48#endif
    4449
    4550static sig_atomic_t intr_flag;
     
    5055    intr_flag++;
    5156}
     57
     58#ifdef HAVE_CONIO_H
     59
     60/*
     61 * Windows does console slightly different then then unix case.
     62 */
     63
     64static int
     65read_string(const char *preprompt, const char *prompt,
     66            char *buf, size_t len, int echo)
     67{
     68    int of = 0;
     69    int c;
     70    char *p;
     71    void (*oldsigintr)(int);
     72
     73    _cprintf("%s%s", preprompt, prompt);
     74
     75    oldsigintr = signal(SIGINT, intr);
     76
     77    p = buf;
     78    while(intr_flag == 0){
     79        c = ((echo)? _getche(): _getch());
     80        if(c == '\n' || c == '\r')
     81            break;
     82        if(of == 0)
     83            *p++ = c;
     84        of = (p == buf + len);
     85    }
     86    if(of)
     87        p--;
     88    *p = 0;
     89   
     90    if(echo == 0){
     91        printf("\n");
     92    }
     93
     94    signal(SIGINT, oldsigintr);
     95   
     96    if(intr_flag)
     97        return -2;
     98    if(of)
     99        return -1;
     100    return 0;
     101}
     102
     103#else /* !HAVE_CONIO_H */
    52104
    53105#ifndef NSIG
     
    136188}
    137189
     190#endif /* HAVE_CONIO_H */
     191
    138192int
    139193UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify)
Note: See TracChangeset for help on using the changeset viewer.