From 7ebed02734e23ed678d84d17bc7ffb0823935c7b Mon Sep 17 00:00:00 2001 From: Heimdal Developers Date: Mon, 4 Oct 2010 14:25:11 +0100 Subject: [PATCH] Import of code from heimdal This commit updates the code imported from the external heimdal git repository to their revision 48ad3e1e6597f03cce5439831ef94b5ec11894e9 which is described as switch-from-svn-to-git-1593-g48ad3e1 Change-Id: I90eb6752000d6794e830a704adcf367928b05a98 Reviewed-on: http://gerrit.openafs.org/2898 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/external/heimdal/hcrypto/evp-cc.c | 57 ++++ src/external/heimdal/hcrypto/evp-hcrypto.c | 46 +++ src/external/heimdal/hcrypto/evp-hcrypto.h | 4 + src/external/heimdal/hcrypto/evp.c | 55 +++- src/external/heimdal/hcrypto/evp.h | 8 + src/external/heimdal/hcrypto/hash.h | 6 + .../heimdal/hcrypto/rijndael-alg-fst.c | 51 ++- src/external/heimdal/hcrypto/sha.c | 8 +- src/external/heimdal/hcrypto/sha.h | 26 ++ src/external/heimdal/hcrypto/sha512.c | 273 ++++++++++++++++ src/external/heimdal/hcrypto/validate.c | 308 ++++++++++++++++++ src/external/heimdal/krb5/config_file.c | 14 +- src/external/heimdal/krb5/n-fold.c | 141 ++++++++ src/external/heimdal/roken/base64.c | 142 ++++++++ src/external/heimdal/roken/base64.h | 55 ++++ src/external/heimdal/roken/net_read.c | 3 +- src/external/heimdal/roken/net_write.c | 3 +- src/external/heimdal/roken/strlcpy.c | 3 +- 18 files changed, 1164 insertions(+), 39 deletions(-) create mode 100644 src/external/heimdal/hcrypto/sha512.c create mode 100644 src/external/heimdal/hcrypto/validate.c create mode 100644 src/external/heimdal/krb5/n-fold.c create mode 100644 src/external/heimdal/roken/base64.c create mode 100644 src/external/heimdal/roken/base64.h diff --git a/src/external/heimdal/hcrypto/evp-cc.c b/src/external/heimdal/hcrypto/evp-cc.c index 983d5210a..11b2933ad 100644 --- a/src/external/heimdal/hcrypto/evp-cc.c +++ b/src/external/heimdal/hcrypto/evp-cc.c @@ -48,7 +48,9 @@ #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H #include #endif +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H #include +#endif #include #include @@ -57,6 +59,8 @@ * */ +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H + struct cc_key { CCCryptorRef href; }; @@ -160,6 +164,8 @@ cc_des_ede3_cbc_init(EVP_CIPHER_CTX *ctx, return init_cc_key(encp, kCCAlgorithm3DES, 0, key, kCCKeySize3DES, iv, &cc->href); } +#endif /* HAVE_COMMONCRYPTO_COMMONCRYPTOR_H */ + /** * The tripple DES cipher type (Apple CommonCrypto provider) * @@ -171,6 +177,7 @@ cc_des_ede3_cbc_init(EVP_CIPHER_CTX *ctx, const EVP_CIPHER * EVP_cc_des_ede3_cbc(void) { +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H static const EVP_CIPHER des_ede3_cbc = { 0, 8, @@ -187,8 +194,12 @@ EVP_cc_des_ede3_cbc(void) NULL }; return &des_ede3_cbc; +#else + return NULL; +#endif } +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H /* * */ @@ -202,6 +213,7 @@ cc_des_cbc_init(EVP_CIPHER_CTX *ctx, struct cc_key *cc = ctx->cipher_data; return init_cc_key(encp, kCCAlgorithmDES, 0, key, kCCBlockSizeDES, iv, &cc->href); } +#endif /** * The DES cipher type (Apple CommonCrypto provider) @@ -214,6 +226,7 @@ cc_des_cbc_init(EVP_CIPHER_CTX *ctx, const EVP_CIPHER * EVP_cc_des_cbc(void) { +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H static const EVP_CIPHER des_ede3_cbc = { 0, kCCBlockSizeDES, @@ -230,8 +243,12 @@ EVP_cc_des_cbc(void) NULL }; return &des_ede3_cbc; +#else + return NULL; +#endif } +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H /* * */ @@ -245,6 +262,7 @@ cc_aes_cbc_init(EVP_CIPHER_CTX *ctx, struct cc_key *cc = ctx->cipher_data; return init_cc_key(encp, kCCAlgorithmAES128, 0, key, ctx->cipher->key_len, iv, &cc->href); } +#endif /** * The AES-128 cipher type (Apple CommonCrypto provider) @@ -257,6 +275,7 @@ cc_aes_cbc_init(EVP_CIPHER_CTX *ctx, const EVP_CIPHER * EVP_cc_aes_128_cbc(void) { +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H static const EVP_CIPHER c = { 0, kCCBlockSizeAES128, @@ -273,6 +292,9 @@ EVP_cc_aes_128_cbc(void) NULL }; return &c; +#else + return NULL; +#endif } /** @@ -286,6 +308,7 @@ EVP_cc_aes_128_cbc(void) const EVP_CIPHER * EVP_cc_aes_192_cbc(void) { +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H static const EVP_CIPHER c = { 0, kCCBlockSizeAES128, @@ -302,6 +325,9 @@ EVP_cc_aes_192_cbc(void) NULL }; return &c; +#else + return NULL; +#endif } /** @@ -315,6 +341,7 @@ EVP_cc_aes_192_cbc(void) const EVP_CIPHER * EVP_cc_aes_256_cbc(void) { +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H static const EVP_CIPHER c = { 0, kCCBlockSizeAES128, @@ -331,8 +358,12 @@ EVP_cc_aes_256_cbc(void) NULL }; return &c; +#else + return NULL; +#endif } +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H /* * */ @@ -348,6 +379,7 @@ cc_aes_cfb8_init(EVP_CIPHER_CTX *ctx, return init_cc_key(1, kCCAlgorithmAES128, kCCOptionECBMode, key, ctx->cipher->key_len, NULL, &cc->href); } +#endif /** * The AES-128 CFB8 cipher type (Apple CommonCrypto provider) @@ -360,6 +392,7 @@ cc_aes_cfb8_init(EVP_CIPHER_CTX *ctx, const EVP_CIPHER * EVP_cc_aes_128_cfb8(void) { +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H static const EVP_CIPHER c = { 0, 1, @@ -376,6 +409,9 @@ EVP_cc_aes_128_cfb8(void) NULL }; return &c; +#else + return NULL; +#endif } /** @@ -389,6 +425,7 @@ EVP_cc_aes_128_cfb8(void) const EVP_CIPHER * EVP_cc_aes_192_cfb8(void) { +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H static const EVP_CIPHER c = { 0, 1, @@ -405,6 +442,9 @@ EVP_cc_aes_192_cfb8(void) NULL }; return &c; +#else + return NULL; +#endif } /** @@ -418,6 +458,7 @@ EVP_cc_aes_192_cfb8(void) const EVP_CIPHER * EVP_cc_aes_256_cfb8(void) { +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H static const EVP_CIPHER c = { 0, kCCBlockSizeAES128, @@ -434,6 +475,9 @@ EVP_cc_aes_256_cfb8(void) NULL }; return &c; +#else + return NULL; +#endif } /* @@ -722,6 +766,8 @@ EVP_cc_camellia_256_cbc(void) return NULL; } +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H + /* * */ @@ -736,7 +782,10 @@ cc_rc4_init(EVP_CIPHER_CTX *ctx, return init_cc_key(encp, kCCAlgorithmRC4, 0, key, ctx->key_len, iv, &cc->href); } +#endif + /** + * The RC4 cipher type (Apple CommonCrypto provider) * * @return the RC4 EVP_CIPHER pointer. @@ -747,6 +796,7 @@ cc_rc4_init(EVP_CIPHER_CTX *ctx, const EVP_CIPHER * EVP_cc_rc4(void) { +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H static const EVP_CIPHER rc4 = { 0, 1, @@ -763,6 +813,9 @@ EVP_cc_rc4(void) NULL }; return &rc4; +#else + return NULL; +#endif } @@ -777,6 +830,7 @@ EVP_cc_rc4(void) const EVP_CIPHER * EVP_cc_rc4_40(void) { +#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H static const EVP_CIPHER rc4_40 = { 0, 1, @@ -793,6 +847,9 @@ EVP_cc_rc4_40(void) NULL }; return &rc4_40; +#else + return NULL; +#endif } #endif /* __APPLE__ */ diff --git a/src/external/heimdal/hcrypto/evp-hcrypto.c b/src/external/heimdal/hcrypto/evp-hcrypto.c index 9e063545e..bf37b42ed 100644 --- a/src/external/heimdal/hcrypto/evp-hcrypto.c +++ b/src/external/heimdal/hcrypto/evp-hcrypto.c @@ -289,6 +289,52 @@ EVP_hcrypto_sha256(void) return &sha256; } +/** + * The message digest SHA384 - hcrypto + * + * @return the message digest type. + * + * @ingroup hcrypto_evp + */ + +const EVP_MD * +EVP_hcrypto_sha384(void) +{ + static const struct hc_evp_md sha384 = { + 48, + 128, + sizeof(SHA384_CTX), + (hc_evp_md_init)SHA384_Init, + (hc_evp_md_update)SHA384_Update, + (hc_evp_md_final)SHA384_Final, + NULL + }; + return &sha384; +} + +/** + * The message digest SHA512 - hcrypto + * + * @return the message digest type. + * + * @ingroup hcrypto_evp + */ + +const EVP_MD * +EVP_hcrypto_sha512(void) +{ + static const struct hc_evp_md sha512 = { + 64, + 128, + sizeof(SHA512_CTX), + (hc_evp_md_init)SHA512_Init, + (hc_evp_md_update)SHA512_Update, + (hc_evp_md_final)SHA512_Final, + NULL + }; + return &sha512; +} + /** * The message digest SHA1 - hcrypto * diff --git a/src/external/heimdal/hcrypto/evp-hcrypto.h b/src/external/heimdal/hcrypto/evp-hcrypto.h index 7915046bd..b7876c67c 100644 --- a/src/external/heimdal/hcrypto/evp-hcrypto.h +++ b/src/external/heimdal/hcrypto/evp-hcrypto.h @@ -42,6 +42,8 @@ #define EVP_hcrypto_md5 hc_EVP_hcrypto_md5 #define EVP_hcrypto_sha1 hc_EVP_hcrypto_sha1 #define EVP_hcrypto_sha256 hc_EVP_hcrypto_sha256 +#define EVP_hcrypto_sha384 hc_EVP_hcrypto_sha384 +#define EVP_hcrypto_sha512 hc_EVP_hcrypto_sha512 #define EVP_hcrypto_des_cbc hc_EVP_hcrypto_des_cbc #define EVP_hcrypto_des_ede3_cbc hc_EVP_hcrypto_des_ede3_cbc #define EVP_hcrypto_aes_128_cbc hc_EVP_hcrypto_aes_128_cbc @@ -70,6 +72,8 @@ const EVP_MD * EVP_hcrypto_md4(void); const EVP_MD * EVP_hcrypto_md5(void); const EVP_MD * EVP_hcrypto_sha1(void); const EVP_MD * EVP_hcrypto_sha256(void); +const EVP_MD * EVP_hcrypto_sha384(void); +const EVP_MD * EVP_hcrypto_sha512(void); const EVP_CIPHER * EVP_hcrypto_rc4(void); const EVP_CIPHER * EVP_hcrypto_rc4_40(void); diff --git a/src/external/heimdal/hcrypto/evp.c b/src/external/heimdal/hcrypto/evp.c index 6eaba33ea..75eefc493 100644 --- a/src/external/heimdal/hcrypto/evp.c +++ b/src/external/heimdal/hcrypto/evp.c @@ -356,9 +356,40 @@ EVP_Digest(const void *data, size_t dsize, void *hash, unsigned int *hsize, const EVP_MD * EVP_sha256(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha256); } +/** + * The message digest SHA384 + * + * @return the message digest type. + * + * @ingroup hcrypto_evp + */ + +const EVP_MD * +EVP_sha384(void) +{ + hcrypto_validate(); + return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha384); +} + +/** + * The message digest SHA512 + * + * @return the message digest type. + * + * @ingroup hcrypto_evp + */ + +const EVP_MD * +EVP_sha512(void) +{ + hcrypto_validate(); + return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha512); +} + /** * The message digest SHA1 * @@ -370,6 +401,7 @@ EVP_sha256(void) const EVP_MD * EVP_sha1(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha1); } @@ -385,6 +417,7 @@ const EVP_MD * EVP_sha(void) HC_DEPRECATED { + hcrypto_validate(); return EVP_sha1(); } @@ -399,6 +432,7 @@ EVP_sha(void) HC_DEPRECATED const EVP_MD * EVP_md5(void) HC_DEPRECATED_CRYPTO { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, md5); } @@ -413,6 +447,7 @@ EVP_md5(void) HC_DEPRECATED_CRYPTO const EVP_MD * EVP_md4(void) HC_DEPRECATED_CRYPTO { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, md4); } @@ -427,6 +462,7 @@ EVP_md4(void) HC_DEPRECATED_CRYPTO const EVP_MD * EVP_md2(void) HC_DEPRECATED_CRYPTO { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, md2); } @@ -1000,6 +1036,7 @@ EVP_enc_null(void) const EVP_CIPHER * EVP_rc2_cbc(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc2_cbc); } @@ -1014,6 +1051,7 @@ EVP_rc2_cbc(void) const EVP_CIPHER * EVP_rc2_40_cbc(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc2_40_cbc); } @@ -1028,6 +1066,7 @@ EVP_rc2_40_cbc(void) const EVP_CIPHER * EVP_rc2_64_cbc(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc2_64_cbc); } @@ -1042,6 +1081,7 @@ EVP_rc2_64_cbc(void) const EVP_CIPHER * EVP_rc4(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc4); } @@ -1056,6 +1096,7 @@ EVP_rc4(void) const EVP_CIPHER * EVP_rc4_40(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc4_40); } @@ -1070,6 +1111,7 @@ EVP_rc4_40(void) const EVP_CIPHER * EVP_des_cbc(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, des_cbc); } @@ -1084,6 +1126,7 @@ EVP_des_cbc(void) const EVP_CIPHER * EVP_des_ede3_cbc(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, des_ede3_cbc); } @@ -1098,6 +1141,7 @@ EVP_des_ede3_cbc(void) const EVP_CIPHER * EVP_aes_128_cbc(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_128_cbc); } @@ -1112,6 +1156,7 @@ EVP_aes_128_cbc(void) const EVP_CIPHER * EVP_aes_192_cbc(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_192_cbc); } @@ -1126,6 +1171,7 @@ EVP_aes_192_cbc(void) const EVP_CIPHER * EVP_aes_256_cbc(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_256_cbc); } @@ -1140,6 +1186,7 @@ EVP_aes_256_cbc(void) const EVP_CIPHER * EVP_aes_128_cfb8(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_128_cfb8); } @@ -1154,6 +1201,7 @@ EVP_aes_128_cfb8(void) const EVP_CIPHER * EVP_aes_192_cfb8(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_192_cfb8); } @@ -1168,6 +1216,7 @@ EVP_aes_192_cfb8(void) const EVP_CIPHER * EVP_aes_256_cfb8(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_256_cfb8); } @@ -1182,6 +1231,7 @@ EVP_aes_256_cfb8(void) const EVP_CIPHER * EVP_camellia_128_cbc(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, camellia_128_cbc); } @@ -1196,6 +1246,7 @@ EVP_camellia_128_cbc(void) const EVP_CIPHER * EVP_camellia_192_cbc(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, camellia_192_cbc); } @@ -1210,6 +1261,7 @@ EVP_camellia_192_cbc(void) const EVP_CIPHER * EVP_camellia_256_cbc(void) { + hcrypto_validate(); return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, camellia_256_cbc); } @@ -1292,7 +1344,8 @@ EVP_BytesToKey(const EVP_CIPHER *type, void *keydata, void *ivdata) { - int ivlen, keylen, first = 0; + unsigned int ivlen, keylen; + int first = 0; unsigned int mds = 0, i; unsigned char *key = keydata; unsigned char *iv = ivdata; diff --git a/src/external/heimdal/hcrypto/evp.h b/src/external/heimdal/hcrypto/evp.h index 75ca7442b..626c46329 100644 --- a/src/external/heimdal/hcrypto/evp.h +++ b/src/external/heimdal/hcrypto/evp.h @@ -96,6 +96,8 @@ #define EVP_sha hc_EVP_sha #define EVP_sha1 hc_EVP_sha1 #define EVP_sha256 hc_EVP_sha256 +#define EVP_sha384 hc_EVP_sha384 +#define EVP_sha512 hc_EVP_sha512 #define PKCS5_PBKDF2_HMAC_SHA1 hc_PKCS5_PBKDF2_HMAC_SHA1 #define EVP_BytesToKey hc_EVP_BytesToKey #define EVP_get_cipherbyname hc_EVP_get_cipherbyname @@ -104,6 +106,7 @@ #define OpenSSL_add_all_algorithms_noconf hc_OpenSSL_add_all_algorithms_noconf #define EVP_CIPHER_CTX_ctrl hc_EVP_CIPHER_CTX_ctrl #define EVP_CIPHER_CTX_rand_key hc_EVP_CIPHER_CTX_rand_key +#define hcrypto_validate hc_hcrypto_validate /* * @@ -224,6 +227,8 @@ HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md5(void); const EVP_MD *EVP_sha(void); const EVP_MD *EVP_sha1(void); const EVP_MD *EVP_sha256(void); +const EVP_MD *EVP_sha384(void); +const EVP_MD *EVP_sha512(void); const EVP_CIPHER * EVP_aes_128_cbc(void); const EVP_CIPHER * EVP_aes_192_cbc(void); @@ -316,6 +321,9 @@ void OpenSSL_add_all_algorithms(void); void OpenSSL_add_all_algorithms_conf(void); void OpenSSL_add_all_algorithms_noconf(void); +void +hcrypto_validate(void); + HC_CPP_END #endif /* HEIM_EVP_H */ diff --git a/src/external/heimdal/hcrypto/hash.h b/src/external/heimdal/hcrypto/hash.h index cfec9cf3f..498e5b1af 100644 --- a/src/external/heimdal/hcrypto/hash.h +++ b/src/external/heimdal/hcrypto/hash.h @@ -66,4 +66,10 @@ cshift (uint32_t x, unsigned int n) return CRAYFIX((x << n) | (x >> (32 - n))); } +static inline uint64_t +cshift64 (uint64_t x, unsigned int n) +{ + return ((uint64_t)x << (uint64_t)n) | ((uint64_t)x >> ((uint64_t)64 - (uint64_t)n)); +} + #endif /* __hash_h__ */ diff --git a/src/external/heimdal/hcrypto/rijndael-alg-fst.c b/src/external/heimdal/hcrypto/rijndael-alg-fst.c index a44b525de..d02bac7db 100644 --- a/src/external/heimdal/hcrypto/rijndael-alg-fst.c +++ b/src/external/heimdal/hcrypto/rijndael-alg-fst.c @@ -38,11 +38,6 @@ #include "rijndael-alg-fst.h" -/* the file should not be used from outside */ -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; - /* Te0[x] = S [x].[02, 01, 01, 03]; Te1[x] = S [x].[03, 02, 01, 01]; @@ -57,7 +52,7 @@ Td3[x] = Si[x].[09, 0d, 0b, 0e]; Td4[x] = Si[x].[01, 01, 01, 01]; */ -static const u32 Te0[256] = { +static const uint32_t Te0[256] = { 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU, @@ -123,7 +118,7 @@ static const u32 Te0[256] = { 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U, 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, }; -static const u32 Te1[256] = { +static const uint32_t Te1[256] = { 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU, @@ -189,7 +184,7 @@ static const u32 Te1[256] = { 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU, 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, }; -static const u32 Te2[256] = { +static const uint32_t Te2[256] = { 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU, @@ -255,7 +250,7 @@ static const u32 Te2[256] = { 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU, 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, }; -static const u32 Te3[256] = { +static const uint32_t Te3[256] = { 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, @@ -322,7 +317,7 @@ static const u32 Te3[256] = { 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, }; -static const u32 Te4[256] = { +static const uint32_t Te4[256] = { 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU, 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U, 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU, @@ -388,7 +383,7 @@ static const u32 Te4[256] = { 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU, 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U, }; -static const u32 Td0[256] = { +static const uint32_t Td0[256] = { 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U, @@ -454,7 +449,7 @@ static const u32 Td0[256] = { 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U, 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, }; -static const u32 Td1[256] = { +static const uint32_t Td1[256] = { 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU, @@ -520,7 +515,7 @@ static const u32 Td1[256] = { 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U, 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, }; -static const u32 Td2[256] = { +static const uint32_t Td2[256] = { 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U, @@ -587,7 +582,7 @@ static const u32 Td2[256] = { 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U, 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, }; -static const u32 Td3[256] = { +static const uint32_t Td3[256] = { 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U, @@ -653,7 +648,7 @@ static const u32 Td3[256] = { 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U, 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, }; -static const u32 Td4[256] = { +static const uint32_t Td4[256] = { 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U, 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U, 0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU, @@ -719,7 +714,7 @@ static const u32 Td4[256] = { 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U, 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU, }; -static const u32 rcon[] = { +static const uint32_t rcon[] = { 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ @@ -728,11 +723,11 @@ static const u32 rcon[] = { #define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) #ifdef _MSC_VER -#define GETU32(p) SWAP(*((u32 *)(p))) -#define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); } +#define GETU32(p) SWAP(*((uint32_t *)(p))) +#define PUTU32(ct, st) { *((uint32_t *)(ct)) = SWAP((st)); } #else -#define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3])) -#define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); } +#define GETU32(pt) (((uint32_t)(pt)[0] << 24) ^ ((uint32_t)(pt)[1] << 16) ^ ((uint32_t)(pt)[2] << 8) ^ ((uint32_t)(pt)[3])) +#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); } #endif /** @@ -740,9 +735,9 @@ static const u32 rcon[] = { * * @return the number of rounds for the given cipher key size. */ -int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits) { +int rijndaelKeySetupEnc(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits) { int i = 0; - u32 temp; + uint32_t temp; rk[0] = GETU32(cipherKey ); rk[1] = GETU32(cipherKey + 4); @@ -826,9 +821,9 @@ int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBit * * @return the number of rounds for the given cipher key size. */ -int rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits) { +int rijndaelKeySetupDec(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits) { int Nr, i, j; - u32 temp; + uint32_t temp; /* expand the cipher key: */ Nr = rijndaelKeySetupEnc(rk, cipherKey, keyBits); @@ -866,8 +861,8 @@ int rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBit return Nr; } -void rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16]) { - u32 s0, s1, s2, s3, t0, t1, t2, t3; +void rijndaelEncrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t pt[16], uint8_t ct[16]) { + uint32_t s0, s1, s2, s3, t0, t1, t2, t3; #ifndef FULL_UNROLL int r; #endif /* ?FULL_UNROLL */ @@ -1047,8 +1042,8 @@ void rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 c PUTU32(ct + 12, s3); } -void rijndaelDecrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], u8 pt[16]) { - u32 s0, s1, s2, s3, t0, t1, t2, t3; +void rijndaelDecrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t ct[16], uint8_t pt[16]) { + uint32_t s0, s1, s2, s3, t0, t1, t2, t3; #ifndef FULL_UNROLL int r; #endif /* ?FULL_UNROLL */ diff --git a/src/external/heimdal/hcrypto/sha.c b/src/external/heimdal/hcrypto/sha.c index 39c53b0a5..9c8b39e24 100644 --- a/src/external/heimdal/hcrypto/sha.c +++ b/src/external/heimdal/hcrypto/sha.c @@ -240,13 +240,13 @@ SHA1_Update (struct sha *m, const void *v, size_t len) if(offset == 64){ #if !defined(WORDS_BIGENDIAN) || defined(_CRAY) int i; - uint32_t current[16]; + uint32_t SHA1current[16]; struct x32 *us = (struct x32*)m->save; for(i = 0; i < 8; i++){ - current[2*i+0] = swap_uint32_t(us[i].a); - current[2*i+1] = swap_uint32_t(us[i].b); + SHA1current[2*i+0] = swap_uint32_t(us[i].a); + SHA1current[2*i+1] = swap_uint32_t(us[i].b); } - calc(m, current); + calc(m, SHA1current); #else calc(m, (uint32_t*)m->save); #endif diff --git a/src/external/heimdal/hcrypto/sha.h b/src/external/heimdal/hcrypto/sha.h index 39e33cf8d..a1f5a9931 100644 --- a/src/external/heimdal/hcrypto/sha.h +++ b/src/external/heimdal/hcrypto/sha.h @@ -80,4 +80,30 @@ void SHA256_Init (SHA256_CTX *); void SHA256_Update (SHA256_CTX *, const void *, size_t); void SHA256_Final (void *, SHA256_CTX *); +/* + * SHA-2 512 + */ + +#define SHA512_DIGEST_LENGTH 64 + +struct hc_sha512state { + uint64_t sz[2]; + uint64_t counter[8]; + unsigned char save[128]; +}; + +typedef struct hc_sha512state SHA512_CTX; + +void SHA512_Init (SHA512_CTX *); +void SHA512_Update (SHA512_CTX *, const void *, size_t); +void SHA512_Final (void *, SHA512_CTX *); + +#define SHA384_DIGEST_LENGTH 48 + +typedef struct hc_sha512state SHA384_CTX; + +void SHA384_Init (SHA384_CTX *); +void SHA384_Update (SHA384_CTX *, const void *, size_t); +void SHA384_Final (void *, SHA384_CTX *); + #endif /* HEIM_SHA_H */ diff --git a/src/external/heimdal/hcrypto/sha512.c b/src/external/heimdal/hcrypto/sha512.c new file mode 100644 index 000000000..fbdc3f51a --- /dev/null +++ b/src/external/heimdal/hcrypto/sha512.c @@ -0,0 +1,273 @@ +/* + * Copyright (c) 2006 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "config.h" + +#include "hash.h" +#include "sha.h" + +#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) +#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) + +#define ROTR(x,n) (((x)>>(n)) | ((x) << (64 - (n)))) + +#define Sigma0(x) (ROTR(x,28) ^ ROTR(x,34) ^ ROTR(x,39)) +#define Sigma1(x) (ROTR(x,14) ^ ROTR(x,18) ^ ROTR(x,41)) +#define sigma0(x) (ROTR(x,1) ^ ROTR(x,8) ^ ((x)>>7)) +#define sigma1(x) (ROTR(x,19) ^ ROTR(x,61) ^ ((x)>>6)) + +#define A m->counter[0] +#define B m->counter[1] +#define C m->counter[2] +#define D m->counter[3] +#define E m->counter[4] +#define F m->counter[5] +#define G m->counter[6] +#define H m->counter[7] + +static const uint64_t constant_512[80] = { + 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc, + 0x3956c25bf348b538, 0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, + 0xd807aa98a3030242, 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2, + 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235, 0xc19bf174cf692694, + 0xe49b69c19ef14ad2, 0xefbe4786384f25e3, 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65, + 0x2de92c6f592b0275, 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5, + 0x983e5152ee66dfab, 0xa831c66d2db43210, 0xb00327c898fb213f, 0xbf597fc7beef0ee4, + 0xc6e00bf33da88fc2, 0xd5a79147930aa725, 0x06ca6351e003826f, 0x142929670a0e6e70, + 0x27b70a8546d22ffc, 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed, 0x53380d139d95b3df, + 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, 0x92722c851482353b, + 0xa2bfe8a14cf10364, 0xa81a664bbc423001, 0xc24b8b70d0f89791, 0xc76c51a30654be30, + 0xd192e819d6ef5218, 0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8, + 0x19a4c116b8d2d0c8, 0x1e376c085141ab53, 0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8, + 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb, 0x5b9cca4f7763e373, 0x682e6ff3d6b2b8a3, + 0x748f82ee5defb2fc, 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec, + 0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, 0xc67178f2e372532b, + 0xca273eceea26619c, 0xd186b8c721c0c207, 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178, + 0x06f067aa72176fba, 0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b, + 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c, + 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 +}; + +void +SHA512_Init (SHA512_CTX *m) +{ + m->sz[0] = 0; + m->sz[1] = 0; + A = 0x6a09e667f3bcc908; + B = 0xbb67ae8584caa73b; + C = 0x3c6ef372fe94f82b; + D = 0xa54ff53a5f1d36f1; + E = 0x510e527fade682d1; + F = 0x9b05688c2b3e6c1f; + G = 0x1f83d9abfb41bd6b; + H = 0x5be0cd19137e2179; +} + +static void +calc (SHA512_CTX *m, uint64_t *in) +{ + uint64_t AA, BB, CC, DD, EE, FF, GG, HH; + uint64_t data[80]; + int i; + + AA = A; + BB = B; + CC = C; + DD = D; + EE = E; + FF = F; + GG = G; + HH = H; + + for (i = 0; i < 16; ++i) + data[i] = in[i]; + for (i = 16; i < 80; ++i) + data[i] = sigma1(data[i-2]) + data[i-7] + + sigma0(data[i-15]) + data[i - 16]; + + for (i = 0; i < 80; i++) { + uint64_t T1, T2; + + T1 = HH + Sigma1(EE) + Ch(EE, FF, GG) + constant_512[i] + data[i]; + T2 = Sigma0(AA) + Maj(AA,BB,CC); + + HH = GG; + GG = FF; + FF = EE; + EE = DD + T1; + DD = CC; + CC = BB; + BB = AA; + AA = T1 + T2; + } + + A += AA; + B += BB; + C += CC; + D += DD; + E += EE; + F += FF; + G += GG; + H += HH; +} + +/* + * From `Performance analysis of MD5' by Joseph D. Touch + */ + +#if !defined(WORDS_BIGENDIAN) || defined(_CRAY) +static inline uint64_t +swap_uint64_t (uint64_t t) +{ + uint64_t temp; + + temp = cshift64(t, 32); + temp = ((temp & 0xff00ff00ff00ff00) >> 8) | + ((temp & 0x00ff00ff00ff00ff) << 8); + return ((temp & 0xffff0000ffff0000) >> 16) | + ((temp & 0x0000ffff0000ffff) << 16); +} +#endif + +struct x64{ + uint64_t a:64; + uint64_t b:64; +}; + +void +SHA512_Update (SHA512_CTX *m, const void *v, size_t len) +{ + const unsigned char *p = v; + size_t old_sz = m->sz[0]; + size_t offset; + + m->sz[0] += len * 8; + if (m->sz[0] < old_sz) + ++m->sz[1]; + offset = (old_sz / 8) % 128; + while(len > 0){ + size_t l = min(len, 128 - offset); + memcpy(m->save + offset, p, l); + offset += l; + p += l; + len -= l; + if(offset == 128){ +#if !defined(WORDS_BIGENDIAN) || defined(_CRAY) + int i; + uint64_t current[16]; + struct x64 *us = (struct x64*)m->save; + for(i = 0; i < 8; i++){ + current[2*i+0] = swap_uint64_t(us[i].a); + current[2*i+1] = swap_uint64_t(us[i].b); + } + calc(m, current); +#else + calc(m, (uint64_t*)m->save); +#endif + offset = 0; + } + } +} + +void +SHA512_Final (void *res, SHA512_CTX *m) +{ + unsigned char zeros[128 + 16]; + unsigned offset = (m->sz[0] / 8) % 128; + unsigned int dstart = (240 - offset - 1) % 128 + 1; + + *zeros = 0x80; + memset (zeros + 1, 0, sizeof(zeros) - 1); + zeros[dstart+15] = (m->sz[0] >> 0) & 0xff; + zeros[dstart+14] = (m->sz[0] >> 8) & 0xff; + zeros[dstart+13] = (m->sz[0] >> 16) & 0xff; + zeros[dstart+12] = (m->sz[0] >> 24) & 0xff; + zeros[dstart+11] = (m->sz[0] >> 32) & 0xff; + zeros[dstart+10] = (m->sz[0] >> 40) & 0xff; + zeros[dstart+9] = (m->sz[0] >> 48) & 0xff; + zeros[dstart+8] = (m->sz[0] >> 56) & 0xff; + + zeros[dstart+7] = (m->sz[1] >> 0) & 0xff; + zeros[dstart+6] = (m->sz[1] >> 8) & 0xff; + zeros[dstart+5] = (m->sz[1] >> 16) & 0xff; + zeros[dstart+4] = (m->sz[1] >> 24) & 0xff; + zeros[dstart+3] = (m->sz[1] >> 32) & 0xff; + zeros[dstart+2] = (m->sz[1] >> 40) & 0xff; + zeros[dstart+1] = (m->sz[1] >> 48) & 0xff; + zeros[dstart+0] = (m->sz[1] >> 56) & 0xff; + SHA512_Update (m, zeros, dstart + 16); + { + int i; + unsigned char *r = (unsigned char*)res; + + for (i = 0; i < 8; ++i) { + r[8*i+7] = m->counter[i] & 0xFF; + r[8*i+6] = (m->counter[i] >> 8) & 0xFF; + r[8*i+5] = (m->counter[i] >> 16) & 0xFF; + r[8*i+4] = (m->counter[i] >> 24) & 0xFF; + r[8*i+3] = (m->counter[i] >> 32) & 0XFF; + r[8*i+2] = (m->counter[i] >> 40) & 0xFF; + r[8*i+1] = (m->counter[i] >> 48) & 0xFF; + r[8*i] = (m->counter[i] >> 56) & 0xFF; + } + } +} + +void +SHA384_Init(SHA384_CTX *m) +{ + m->sz[0] = 0; + m->sz[1] = 0; + A = 0xcbbb9d5dc1059ed8; + B = 0x629a292a367cd507; + C = 0x9159015a3070dd17; + D = 0x152fecd8f70e5939; + E = 0x67332667ffc00b31; + F = 0x8eb44a8768581511; + G = 0xdb0c2e0d64f98fa7; + H = 0x47b5481dbefa4fa4; +} + +void +SHA384_Update (SHA384_CTX *m, const void *v, size_t len) +{ + SHA512_Update(m, v, len); +} + +void +SHA384_Final (void *res, SHA384_CTX *m) +{ + unsigned char data[SHA512_DIGEST_LENGTH]; + SHA512_Final(data, m); + memcpy(res, data, SHA384_DIGEST_LENGTH); +} diff --git a/src/external/heimdal/hcrypto/validate.c b/src/external/heimdal/hcrypto/validate.c new file mode 100644 index 000000000..7f036aabf --- /dev/null +++ b/src/external/heimdal/hcrypto/validate.c @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2010 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +struct tests { + const EVP_CIPHER *(*cipher)(void); + const char *name; + void *key; + size_t keysize; + void *iv; + size_t datasize; + void *indata; + void *outdata; + void *outiv; +}; + +struct tests tests[] = { + { + EVP_aes_256_cbc, + "aes-256", + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + 32, + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + 16, + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + "\xdc\x95\xc0\x78\xa2\x40\x89\x89\xad\x48\xa2\x14\x92\x84\x20\x87" + }, +#if 0 + { + EVP_aes_128_cfb8, + "aes-cfb8-128", + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + 16, + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + 16, + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + "\x66\xe9\x4b\xd4\xef\x8a\x2c\x3b\x88\x4c\xfa\x59\xca\x34\x2b\x2e" + }, +#endif + { + EVP_des_ede3_cbc, + "des-ede3", + "\x19\x17\xff\xe6\xbb\x77\x2e\xfc" + "\x29\x76\x43\xbc\x63\x56\x7e\x9a" + "\x00\x2e\x4d\x43\x1d\x5f\xfd\x58", + 24, + "\xbf\x9a\x12\xb7\x26\x69\xfd\x05", + 16, + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + "\x55\x95\x97\x76\xa9\x6c\x66\x40\x64\xc7\xf4\x1c\x21\xb7\x14\x1b" + }, +#if 0 + { + EVP_camellia_128_cbc, + "camellia128", + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + 16, + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + 16, + "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + "\x07\x92\x3A\x39\xEB\x0A\x81\x7D\x1C\x4D\x87\xBD\xB8\x2D\x1F\x1C", + NULL + }, +#endif + { + EVP_rc4, + "rc4 8", + "\x01\x23\x45\x67\x89\xAB\xCD\xEF", + 8, + NULL, + 8, + "\x00\x00\x00\x00\x00\x00\x00\x00", + "\x74\x94\xC2\xE7\x10\x4B\x08\x79", + NULL + }, + { + EVP_rc4, + "rc4 5", + "\x61\x8a\x63\xd2\xfb", + 5, + NULL, + 5, + "\xdc\xee\x4c\xf9\x2c", + "\xf1\x38\x29\xc9\xde", + NULL + }, + { + EVP_rc4, + "rc4 309", + "\x29\x04\x19\x72\xfb\x42\xba\x5f\xc7\x12\x77\x12\xf1\x38\x29\xc9", + 16, + NULL, + 309, + "\x52\x75\x69\x73\x6c\x69\x6e\x6e" + "\x75\x6e\x20\x6c\x61\x75\x6c\x75" + "\x20\x6b\x6f\x72\x76\x69\x73\x73" + "\x73\x61\x6e\x69\x2c\x20\x74\xe4" + "\x68\x6b\xe4\x70\xe4\x69\x64\x65" + "\x6e\x20\x70\xe4\xe4\x6c\x6c\xe4" + "\x20\x74\xe4\x79\x73\x69\x6b\x75" + "\x75\x2e\x20\x4b\x65\x73\xe4\x79" + "\xf6\x6e\x20\x6f\x6e\x20\x6f\x6e" + "\x6e\x69\x20\x6f\x6d\x61\x6e\x61" + "\x6e\x69\x2c\x20\x6b\x61\x73\x6b" + "\x69\x73\x61\x76\x75\x75\x6e\x20" + "\x6c\x61\x61\x6b\x73\x6f\x74\x20" + "\x76\x65\x72\x68\x6f\x75\x75\x2e" + "\x20\x45\x6e\x20\x6d\x61\x20\x69" + "\x6c\x6f\x69\x74\x73\x65\x2c\x20" + "\x73\x75\x72\x65\x20\x68\x75\x6f" + "\x6b\x61\x61\x2c\x20\x6d\x75\x74" + "\x74\x61\x20\x6d\x65\x74\x73\xe4" + "\x6e\x20\x74\x75\x6d\x6d\x75\x75" + "\x73\x20\x6d\x75\x6c\x6c\x65\x20" + "\x74\x75\x6f\x6b\x61\x61\x2e\x20" + "\x50\x75\x75\x6e\x74\x6f\x20\x70" + "\x69\x6c\x76\x65\x6e\x2c\x20\x6d" + "\x69\x20\x68\x75\x6b\x6b\x75\x75" + "\x2c\x20\x73\x69\x69\x6e\x74\x6f" + "\x20\x76\x61\x72\x61\x6e\x20\x74" + "\x75\x75\x6c\x69\x73\x65\x6e\x2c" + "\x20\x6d\x69\x20\x6e\x75\x6b\x6b" + "\x75\x75\x2e\x20\x54\x75\x6f\x6b" + "\x73\x75\x74\x20\x76\x61\x6e\x61" + "\x6d\x6f\x6e\x20\x6a\x61\x20\x76" + "\x61\x72\x6a\x6f\x74\x20\x76\x65" + "\x65\x6e\x2c\x20\x6e\x69\x69\x73" + "\x74\xe4\x20\x73\x79\x64\xe4\x6d" + "\x65\x6e\x69\x20\x6c\x61\x75\x6c" + "\x75\x6e\x20\x74\x65\x65\x6e\x2e" + "\x20\x2d\x20\x45\x69\x6e\x6f\x20" + "\x4c\x65\x69\x6e\x6f", + "\x35\x81\x86\x99\x90\x01\xe6\xb5" + "\xda\xf0\x5e\xce\xeb\x7e\xee\x21" + "\xe0\x68\x9c\x1f\x00\xee\xa8\x1f" + "\x7d\xd2\xca\xae\xe1\xd2\x76\x3e" + "\x68\xaf\x0e\xad\x33\xd6\x6c\x26" + "\x8b\xc9\x46\xc4\x84\xfb\xe9\x4c" + "\x5f\x5e\x0b\x86\xa5\x92\x79\xe4" + "\xf8\x24\xe7\xa6\x40\xbd\x22\x32" + "\x10\xb0\xa6\x11\x60\xb7\xbc\xe9" + "\x86\xea\x65\x68\x80\x03\x59\x6b" + "\x63\x0a\x6b\x90\xf8\xe0\xca\xf6" + "\x91\x2a\x98\xeb\x87\x21\x76\xe8" + "\x3c\x20\x2c\xaa\x64\x16\x6d\x2c" + "\xce\x57\xff\x1b\xca\x57\xb2\x13" + "\xf0\xed\x1a\xa7\x2f\xb8\xea\x52" + "\xb0\xbe\x01\xcd\x1e\x41\x28\x67" + "\x72\x0b\x32\x6e\xb3\x89\xd0\x11" + "\xbd\x70\xd8\xaf\x03\x5f\xb0\xd8" + "\x58\x9d\xbc\xe3\xc6\x66\xf5\xea" + "\x8d\x4c\x79\x54\xc5\x0c\x3f\x34" + "\x0b\x04\x67\xf8\x1b\x42\x59\x61" + "\xc1\x18\x43\x07\x4d\xf6\x20\xf2" + "\x08\x40\x4b\x39\x4c\xf9\xd3\x7f" + "\xf5\x4b\x5f\x1a\xd8\xf6\xea\x7d" + "\xa3\xc5\x61\xdf\xa7\x28\x1f\x96" + "\x44\x63\xd2\xcc\x35\xa4\xd1\xb0" + "\x34\x90\xde\xc5\x1b\x07\x11\xfb" + "\xd6\xf5\x5f\x79\x23\x4d\x5b\x7c" + "\x76\x66\x22\xa6\x6d\xe9\x2b\xe9" + "\x96\x46\x1d\x5e\x4d\xc8\x78\xef" + "\x9b\xca\x03\x05\x21\xe8\x35\x1e" + "\x4b\xae\xd2\xfd\x04\xf9\x46\x73" + "\x68\xc4\xad\x6a\xc1\x86\xd0\x82" + "\x45\xb2\x63\xa2\x66\x6d\x1f\x6c" + "\x54\x20\xf1\x59\x9d\xfd\x9f\x43" + "\x89\x21\xc2\xf5\xa4\x63\x93\x8c" + "\xe0\x98\x22\x65\xee\xf7\x01\x79" + "\xbc\x55\x3f\x33\x9e\xb1\xa4\xc1" + "\xaf\x5f\x6a\x54\x7f" + } +}; + +static int +test_cipher(struct tests *t) +{ + const EVP_CIPHER *c = t->cipher(); + EVP_CIPHER_CTX ectx; + EVP_CIPHER_CTX dctx; + void *d; + + EVP_CIPHER_CTX_init(&ectx); + EVP_CIPHER_CTX_init(&dctx); + + if (EVP_CipherInit_ex(&ectx, c, NULL, NULL, NULL, 1) != 1) + errx(1, "%s: EVP_CipherInit_ex einit", t->name); + if (EVP_CipherInit_ex(&dctx, c, NULL, NULL, NULL, 0) != 1) + errx(1, "%s: EVP_CipherInit_ex dinit", t->name); + + EVP_CIPHER_CTX_set_key_length(&ectx, t->keysize); + EVP_CIPHER_CTX_set_key_length(&dctx, t->keysize); + + if (EVP_CipherInit_ex(&ectx, NULL, NULL, t->key, t->iv, 1) != 1) + errx(1, "%s: EVP_CipherInit_ex encrypt", t->name); + if (EVP_CipherInit_ex(&dctx, NULL, NULL, t->key, t->iv, 0) != 1) + errx(1, "%s: EVP_CipherInit_ex decrypt", t->name); + + d = emalloc(t->datasize); + + if (!EVP_Cipher(&ectx, d, t->indata, t->datasize)) + return 1; + + if (memcmp(d, t->outdata, t->datasize) != 0) + errx(1, "%s: encrypt not the same", t->name); + + if (!EVP_Cipher(&dctx, d, d, t->datasize)) + return 1; + + if (memcmp(d, t->indata, t->datasize) != 0) + errx(1, "%s: decrypt not the same", t->name); + + if (t->outiv) + /* XXXX check */; + + EVP_CIPHER_CTX_cleanup(&ectx); + EVP_CIPHER_CTX_cleanup(&dctx); + free(d); + + return 0; +} + +static void +check_hmac(void) +{ + unsigned char buf[4] = { 0, 0, 0, 0 }; + char hmackey[] = "hello-world"; + size_t hmackey_size = sizeof(hmackey); + unsigned int hmaclen; + unsigned char hmac[EVP_MAX_MD_SIZE]; + HMAC_CTX c; + + char answer[20] = "\x2c\xfa\x32\xb7\x2b\x8a\xf6\xdf\xcf\xda" + "\x6f\xd1\x52\x4d\x54\x58\x73\x0f\xf3\x24"; + + HMAC_CTX_init(&c); + HMAC_Init_ex(&c, hmackey, hmackey_size, EVP_sha1(), NULL); + HMAC_Update(&c, buf, sizeof(buf)); + HMAC_Final(&c, hmac, &hmaclen); + HMAC_CTX_cleanup(&c); + + if (hmaclen != 20) + errx(1, "hmaclen = %d\n", (int)hmaclen); + + if (ct_memcmp(hmac, answer, hmaclen) != 0) + errx(1, "wrong answer\n"); +} + +void +hcrypto_validate(void) +{ + static int validated = 0; + unsigned int i; + + /* its ok to run this twice, do don't check for races */ + if (validated) + return; + validated++; + + for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) + test_cipher(&tests[i]); + + check_hmac(); +} diff --git a/src/external/heimdal/krb5/config_file.c b/src/external/heimdal/krb5/config_file.c index 704c3bfdf..adad9c1e7 100644 --- a/src/external/heimdal/krb5/config_file.c +++ b/src/external/heimdal/krb5/config_file.c @@ -239,7 +239,12 @@ parse_binding(struct fileptr *f, unsigned *lineno, char *p, return ret; } -#ifdef __APPLE__ +#if defined(__APPLE__) + +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 +#define HAVE_CFPROPERTYLISTCREATEWITHSTREAM 1 +#endif + static char * cfstring2cstring(CFStringRef string) { @@ -293,7 +298,6 @@ parse_plist_config(krb5_context context, const char *path, krb5_config_section * { CFReadStreamRef s; CFDictionaryRef d; - CFErrorRef e; CFURLRef url; url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (UInt8 *)path, strlen(path), FALSE); @@ -315,7 +319,11 @@ parse_plist_config(krb5_context context, const char *path, krb5_config_section * return ENOENT; } - d = (CFDictionaryRef)CFPropertyListCreateWithStream (kCFAllocatorDefault, s, 0, kCFPropertyListImmutable, NULL, &e); +#ifdef HAVE_CFPROPERTYLISTCREATEWITHSTREAM + d = (CFDictionaryRef)CFPropertyListCreateWithStream(NULL, s, 0, kCFPropertyListImmutable, NULL, NULL); +#else + d = (CFDictionaryRef)CFPropertyListCreateFromStream(NULL, s, 0, kCFPropertyListImmutable, NULL, NULL); +#endif CFRelease(s); if (d == NULL) { krb5_clear_error_message(context); diff --git a/src/external/heimdal/krb5/n-fold.c b/src/external/heimdal/krb5/n-fold.c new file mode 100644 index 000000000..2e6092c5c --- /dev/null +++ b/src/external/heimdal/krb5/n-fold.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 1999 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of KTH nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "krb5_locl.h" + +static krb5_error_code +rr13(unsigned char *buf, size_t len) +{ + unsigned char *tmp; + int bytes = (len + 7) / 8; + int i; + if(len == 0) + return 0; + { + const int bits = 13 % len; + const int lbit = len % 8; + + tmp = malloc(bytes); + if (tmp == NULL) + return ENOMEM; + memcpy(tmp, buf, bytes); + if(lbit) { + /* pad final byte with inital bits */ + tmp[bytes - 1] &= 0xff << (8 - lbit); + for(i = lbit; i < 8; i += len) + tmp[bytes - 1] |= buf[0] >> i; + } + for(i = 0; i < bytes; i++) { + int bb; + int b1, s1, b2, s2; + /* calculate first bit position of this byte */ + bb = 8 * i - bits; + while(bb < 0) + bb += len; + /* byte offset and shift count */ + b1 = bb / 8; + s1 = bb % 8; + + if(bb + 8 > bytes * 8) + /* watch for wraparound */ + s2 = (len + 8 - s1) % 8; + else + s2 = 8 - s1; + b2 = (b1 + 1) % bytes; + buf[i] = (tmp[b1] << s1) | (tmp[b2] >> s2); + } + free(tmp); + } + return 0; +} + +/* Add `b' to `a', both being one's complement numbers. */ +static void +add1(unsigned char *a, unsigned char *b, size_t len) +{ + int i; + int carry = 0; + for(i = len - 1; i >= 0; i--){ + int x = a[i] + b[i] + carry; + carry = x > 0xff; + a[i] = x & 0xff; + } + for(i = len - 1; carry && i >= 0; i--){ + int x = a[i] + carry; + carry = x > 0xff; + a[i] = x & 0xff; + } +} + +KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL +_krb5_n_fold(const void *str, size_t len, void *key, size_t size) +{ + /* if len < size we need at most N * len bytes, ie < 2 * size; + if len > size we need at most 2 * len */ + krb5_error_code ret = 0; + size_t maxlen = 2 * max(size, len); + size_t l = 0; + unsigned char *tmp = malloc(maxlen); + unsigned char *buf = malloc(len); + + if (tmp == NULL || buf == NULL) { + ret = ENOMEM; + goto out; + } + + memcpy(buf, str, len); + memset(key, 0, size); + do { + memcpy(tmp + l, buf, len); + l += len; + ret = rr13(buf, len * 8); + if (ret) + goto out; + while(l >= size) { + add1(key, tmp, size); + l -= size; + if(l == 0) + break; + memmove(tmp, tmp + size, l); + } + } while(l != 0); +out: + if (buf) { + memset(buf, 0, len); + free(buf); + } + if (tmp) { + memset(tmp, 0, maxlen); + free(tmp); + } + return ret; +} diff --git a/src/external/heimdal/roken/base64.c b/src/external/heimdal/roken/base64.c new file mode 100644 index 000000000..394e9841c --- /dev/null +++ b/src/external/heimdal/roken/base64.c @@ -0,0 +1,142 @@ +/* + * Copyright (c) 1995-2001 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include +#include +#include "base64.h" + +static const char base64_chars[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +static int +pos(char c) +{ + const char *p; + for (p = base64_chars; *p; p++) + if (*p == c) + return p - base64_chars; + return -1; +} + +ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL +base64_encode(const void *data, int size, char **str) +{ + char *s, *p; + int i; + int c; + const unsigned char *q; + + if (size > INT_MAX/4 || size < 0) { + *str = NULL; + return -1; + } + + p = s = (char *) malloc(size * 4 / 3 + 4); + if (p == NULL) { + *str = NULL; + return -1; + } + q = (const unsigned char *) data; + + for (i = 0; i < size;) { + c = q[i++]; + c *= 256; + if (i < size) + c += q[i]; + i++; + c *= 256; + if (i < size) + c += q[i]; + i++; + p[0] = base64_chars[(c & 0x00fc0000) >> 18]; + p[1] = base64_chars[(c & 0x0003f000) >> 12]; + p[2] = base64_chars[(c & 0x00000fc0) >> 6]; + p[3] = base64_chars[(c & 0x0000003f) >> 0]; + if (i > size) + p[3] = '='; + if (i > size + 1) + p[2] = '='; + p += 4; + } + *p = 0; + *str = s; + return (int) strlen(s); +} + +#define DECODE_ERROR 0xffffffff + +static unsigned int +token_decode(const char *token) +{ + int i; + unsigned int val = 0; + int marker = 0; + if (strlen(token) < 4) + return DECODE_ERROR; + for (i = 0; i < 4; i++) { + val *= 64; + if (token[i] == '=') + marker++; + else if (marker > 0) + return DECODE_ERROR; + else + val += pos(token[i]); + } + if (marker > 2) + return DECODE_ERROR; + return (marker << 24) | val; +} + +ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL +base64_decode(const char *str, void *data) +{ + const char *p; + unsigned char *q; + + q = data; + for (p = str; *p && (*p == '=' || strchr(base64_chars, *p)); p += 4) { + unsigned int val = token_decode(p); + unsigned int marker = (val >> 24) & 0xff; + if (val == DECODE_ERROR) + return -1; + *q++ = (val >> 16) & 0xff; + if (marker < 2) + *q++ = (val >> 8) & 0xff; + if (marker < 1) + *q++ = val & 0xff; + } + return q - (unsigned char *) data; +} diff --git a/src/external/heimdal/roken/base64.h b/src/external/heimdal/roken/base64.h new file mode 100644 index 000000000..dfae4c13b --- /dev/null +++ b/src/external/heimdal/roken/base64.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* $Id$ */ + +#ifndef _BASE64_H_ +#define _BASE64_H_ + +#ifndef ROKEN_LIB_FUNCTION +#ifdef _WIN32 +#define ROKEN_LIB_FUNCTION +#define ROKEN_LIB_CALL __cdecl +#else +#define ROKEN_LIB_FUNCTION +#define ROKEN_LIB_CALL +#endif +#endif + +ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL +base64_encode(const void *, int, char **); + +ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL +base64_decode(const char *, void *); + +#endif diff --git a/src/external/heimdal/roken/net_read.c b/src/external/heimdal/roken/net_read.c index 1f959db95..df1ac53de 100644 --- a/src/external/heimdal/roken/net_read.c +++ b/src/external/heimdal/roken/net_read.c @@ -86,7 +86,8 @@ net_read(rk_socket_t sock, void *buf, size_t nbytes) if (use_read == 0 && rk_IS_SOCKET_ERROR(count) && - rk_SOCK_ERRNO == WSAENOTSOCK) { + (rk_SOCK_ERRNO == WSANOTINITIALISED || + rk_SOCK_ERRNO == WSAENOTSOCK)) { use_read = 1; count = _read (sock, cbuf, rem); diff --git a/src/external/heimdal/roken/net_write.c b/src/external/heimdal/roken/net_write.c index 402e20915..e1cfa9907 100644 --- a/src/external/heimdal/roken/net_write.c +++ b/src/external/heimdal/roken/net_write.c @@ -83,7 +83,8 @@ net_write(rk_socket_t sock, const void *buf, size_t nbytes) if (use_write == 0 && rk_IS_SOCKET_ERROR(count) && - rk_SOCK_ERRNO == WSAENOTSOCK) { + (rk_SOCK_ERRNO == WSANOTINITIALISED || + rk_SOCK_ERRNO == WSAENOTSOCK)) { use_write = 1; count = _write (sock, cbuf, rem); diff --git a/src/external/heimdal/roken/strlcpy.c b/src/external/heimdal/roken/strlcpy.c index 7c1789bd1..0fe2b97fc 100644 --- a/src/external/heimdal/roken/strlcpy.c +++ b/src/external/heimdal/roken/strlcpy.c @@ -43,7 +43,8 @@ strlcpy (char *dst, const char *src, size_t dst_cch) { errno_t e; - e = strcpy_s(dst, dst_cch, src); + if (dst_cch > 0) + e = strncpy_s(dst, dst_cch, src, _TRUNCATE); return strlen (src); } -- 2.39.5