mirror of
https://git.openafs.org/openafs.git
synced 2025-01-20 07:51:00 +00:00
Import of code from heimdal
This commit updates the code imported from the external heimdal git repository to their revision 40ef7759b917648938416e15521d383e2eade5cf which is described as switch-from-svn-to-git-1333-g40ef775 Change-Id: Ie03ff2d99293272f9ce4c900367eefa063ce8d98 Reviewed-on: http://gerrit.openafs.org/2574 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Derrick Brashear <shadow@dementia.org> Tested-by: Derrick Brashear <shadow@dementia.org>
This commit is contained in:
parent
776dbdebc1
commit
fa1c0cfe5f
144
src/external/heimdal/hcrypto/aes.c
vendored
Normal file
144
src/external/heimdal/hcrypto/aes.c
vendored
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (c) 2003 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"
|
||||
|
||||
|
||||
#ifdef KRB5
|
||||
#include <krb5-types.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "rijndael-alg-fst.h"
|
||||
#include "aes.h"
|
||||
|
||||
int
|
||||
AES_set_encrypt_key(const unsigned char *userkey, const int bits, AES_KEY *key)
|
||||
{
|
||||
key->rounds = rijndaelKeySetupEnc(key->key, userkey, bits);
|
||||
if (key->rounds == 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
AES_set_decrypt_key(const unsigned char *userkey, const int bits, AES_KEY *key)
|
||||
{
|
||||
key->rounds = rijndaelKeySetupDec(key->key, userkey, bits);
|
||||
if (key->rounds == 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key)
|
||||
{
|
||||
rijndaelEncrypt(key->key, key->rounds, in, out);
|
||||
}
|
||||
|
||||
void
|
||||
AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key)
|
||||
{
|
||||
rijndaelDecrypt(key->key, key->rounds, in, out);
|
||||
}
|
||||
|
||||
void
|
||||
AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
unsigned long size, const AES_KEY *key,
|
||||
unsigned char *iv, int forward_encrypt)
|
||||
{
|
||||
unsigned char tmp[AES_BLOCK_SIZE];
|
||||
int i;
|
||||
|
||||
if (forward_encrypt) {
|
||||
while (size >= AES_BLOCK_SIZE) {
|
||||
for (i = 0; i < AES_BLOCK_SIZE; i++)
|
||||
tmp[i] = in[i] ^ iv[i];
|
||||
AES_encrypt(tmp, out, key);
|
||||
memcpy(iv, out, AES_BLOCK_SIZE);
|
||||
size -= AES_BLOCK_SIZE;
|
||||
in += AES_BLOCK_SIZE;
|
||||
out += AES_BLOCK_SIZE;
|
||||
}
|
||||
if (size) {
|
||||
for (i = 0; i < size; i++)
|
||||
tmp[i] = in[i] ^ iv[i];
|
||||
for (i = size; i < AES_BLOCK_SIZE; i++)
|
||||
tmp[i] = iv[i];
|
||||
AES_encrypt(tmp, out, key);
|
||||
memcpy(iv, out, AES_BLOCK_SIZE);
|
||||
}
|
||||
} else {
|
||||
while (size >= AES_BLOCK_SIZE) {
|
||||
memcpy(tmp, in, AES_BLOCK_SIZE);
|
||||
AES_decrypt(tmp, out, key);
|
||||
for (i = 0; i < AES_BLOCK_SIZE; i++)
|
||||
out[i] ^= iv[i];
|
||||
memcpy(iv, tmp, AES_BLOCK_SIZE);
|
||||
size -= AES_BLOCK_SIZE;
|
||||
in += AES_BLOCK_SIZE;
|
||||
out += AES_BLOCK_SIZE;
|
||||
}
|
||||
if (size) {
|
||||
memcpy(tmp, in, AES_BLOCK_SIZE);
|
||||
AES_decrypt(tmp, out, key);
|
||||
for (i = 0; i < size; i++)
|
||||
out[i] ^= iv[i];
|
||||
memcpy(iv, tmp, AES_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
|
||||
unsigned long size, const AES_KEY *key,
|
||||
unsigned char *iv, int forward_encrypt)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
unsigned char tmp[AES_BLOCK_SIZE + 1];
|
||||
|
||||
memcpy(tmp, iv, AES_BLOCK_SIZE);
|
||||
AES_encrypt(iv, iv, key);
|
||||
if (!forward_encrypt) {
|
||||
tmp[AES_BLOCK_SIZE] = in[i];
|
||||
}
|
||||
out[i] = in[i] ^ iv[0];
|
||||
if (forward_encrypt) {
|
||||
tmp[AES_BLOCK_SIZE] = out[i];
|
||||
}
|
||||
memcpy(iv, &tmp[1], AES_BLOCK_SIZE);
|
||||
}
|
||||
}
|
84
src/external/heimdal/hcrypto/aes.h
vendored
Normal file
84
src/external/heimdal/hcrypto/aes.h
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2004 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 HEIM_AES_H
|
||||
#define HEIM_AES_H 1
|
||||
|
||||
/* symbol renaming */
|
||||
#define AES_set_encrypt_key hc_AES_set_encrypt_key
|
||||
#define AES_set_decrypt_key hc_AES_decrypt_key
|
||||
#define AES_encrypt hc_AES_encrypt
|
||||
#define AES_decrypt hc_AES_decrypt
|
||||
#define AES_cbc_encrypt hc_AES_cbc_encrypt
|
||||
#define AES_cfb8_encrypt hc_AES_cfb8_encrypt
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#define AES_BLOCK_SIZE 16
|
||||
#define AES_MAXNR 14
|
||||
|
||||
#define AES_ENCRYPT 1
|
||||
#define AES_DECRYPT 0
|
||||
|
||||
typedef struct aes_key {
|
||||
uint32_t key[(AES_MAXNR+1)*4];
|
||||
int rounds;
|
||||
} AES_KEY;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int AES_set_encrypt_key(const unsigned char *, const int, AES_KEY *);
|
||||
int AES_set_decrypt_key(const unsigned char *, const int, AES_KEY *);
|
||||
|
||||
void AES_encrypt(const unsigned char *, unsigned char *, const AES_KEY *);
|
||||
void AES_decrypt(const unsigned char *, unsigned char *, const AES_KEY *);
|
||||
|
||||
void AES_cbc_encrypt(const unsigned char *, unsigned char *,
|
||||
unsigned long, const AES_KEY *,
|
||||
unsigned char *, int);
|
||||
void AES_cfb8_encrypt(const unsigned char *, unsigned char *,
|
||||
unsigned long, const AES_KEY *,
|
||||
unsigned char *, int);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HEIM_AES_H */
|
1469
src/external/heimdal/hcrypto/camellia-ntt.c
vendored
Normal file
1469
src/external/heimdal/hcrypto/camellia-ntt.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
65
src/external/heimdal/hcrypto/camellia-ntt.h
vendored
Normal file
65
src/external/heimdal/hcrypto/camellia-ntt.h
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
/* camellia.h ver 1.2.0
|
||||
*
|
||||
* Copyright (c) 2006,2007
|
||||
* NTT (Nippon Telegraph and Telephone Corporation) . 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 as
|
||||
* the first lines of this file unmodified.
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NTT ``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 NTT 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.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CAMELLIA_H
|
||||
#define HEADER_CAMELLIA_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CAMELLIA_BLOCK_SIZE 16
|
||||
#define CAMELLIA_TABLE_BYTE_LEN 272
|
||||
#define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / 4)
|
||||
|
||||
/* u32 must be 32bit word */
|
||||
typedef uint32_t u32;
|
||||
typedef unsigned char u8;
|
||||
|
||||
typedef u32 KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN];
|
||||
|
||||
|
||||
void Camellia_Ekeygen(const int keyBitLength,
|
||||
const unsigned char *rawKey,
|
||||
KEY_TABLE_TYPE keyTable);
|
||||
|
||||
void Camellia_EncryptBlock(const int keyBitLength,
|
||||
const unsigned char *plaintext,
|
||||
const KEY_TABLE_TYPE keyTable,
|
||||
unsigned char *cipherText);
|
||||
|
||||
void Camellia_DecryptBlock(const int keyBitLength,
|
||||
const unsigned char *cipherText,
|
||||
const KEY_TABLE_TYPE keyTable,
|
||||
unsigned char *plaintext);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_CAMELLIA_H */
|
116
src/external/heimdal/hcrypto/camellia.c
vendored
Normal file
116
src/external/heimdal/hcrypto/camellia.c
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2007 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"
|
||||
|
||||
#ifdef KRB5
|
||||
#include <krb5-types.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "camellia-ntt.h"
|
||||
#include "camellia.h"
|
||||
|
||||
#include <roken.h>
|
||||
|
||||
int
|
||||
CAMELLIA_set_key(const unsigned char *userkey,
|
||||
const int bits, CAMELLIA_KEY *key)
|
||||
{
|
||||
key->bits = bits;
|
||||
Camellia_Ekeygen(bits, userkey, key->key);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
CAMELLIA_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const CAMELLIA_KEY *key)
|
||||
{
|
||||
Camellia_EncryptBlock(key->bits, in, key->key, out);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
CAMELLIA_decrypt(const unsigned char *in, unsigned char *out,
|
||||
const CAMELLIA_KEY *key)
|
||||
{
|
||||
Camellia_DecryptBlock(key->bits, in, key->key, out);
|
||||
}
|
||||
|
||||
void
|
||||
CAMELLIA_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
unsigned long size, const CAMELLIA_KEY *key,
|
||||
unsigned char *iv, int mode_encrypt)
|
||||
{
|
||||
unsigned char tmp[CAMELLIA_BLOCK_SIZE];
|
||||
int i;
|
||||
|
||||
if (mode_encrypt) {
|
||||
while (size >= CAMELLIA_BLOCK_SIZE) {
|
||||
for (i = 0; i < CAMELLIA_BLOCK_SIZE; i++)
|
||||
tmp[i] = in[i] ^ iv[i];
|
||||
CAMELLIA_encrypt(tmp, out, key);
|
||||
memcpy(iv, out, CAMELLIA_BLOCK_SIZE);
|
||||
size -= CAMELLIA_BLOCK_SIZE;
|
||||
in += CAMELLIA_BLOCK_SIZE;
|
||||
out += CAMELLIA_BLOCK_SIZE;
|
||||
}
|
||||
if (size) {
|
||||
for (i = 0; i < size; i++)
|
||||
tmp[i] = in[i] ^ iv[i];
|
||||
for (i = size; i < CAMELLIA_BLOCK_SIZE; i++)
|
||||
tmp[i] = iv[i];
|
||||
CAMELLIA_encrypt(tmp, out, key);
|
||||
memcpy(iv, out, CAMELLIA_BLOCK_SIZE);
|
||||
}
|
||||
} else {
|
||||
while (size >= CAMELLIA_BLOCK_SIZE) {
|
||||
memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
|
||||
CAMELLIA_decrypt(tmp, out, key);
|
||||
for (i = 0; i < CAMELLIA_BLOCK_SIZE; i++)
|
||||
out[i] ^= iv[i];
|
||||
memcpy(iv, tmp, CAMELLIA_BLOCK_SIZE);
|
||||
size -= CAMELLIA_BLOCK_SIZE;
|
||||
in += CAMELLIA_BLOCK_SIZE;
|
||||
out += CAMELLIA_BLOCK_SIZE;
|
||||
}
|
||||
if (size) {
|
||||
memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
|
||||
CAMELLIA_decrypt(tmp, out, key);
|
||||
for (i = 0; i < size; i++)
|
||||
out[i] ^= iv[i];
|
||||
memcpy(iv, tmp, CAMELLIA_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
72
src/external/heimdal/hcrypto/camellia.h
vendored
Normal file
72
src/external/heimdal/hcrypto/camellia.h
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2007 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 HEIM_CAMELLIA_H
|
||||
#define HEIM_CAMELLIA_H 1
|
||||
|
||||
/* symbol renaming */
|
||||
#define CAMELLIA_set_key hc_CAMELLIA_set_encrypt_key
|
||||
#define CAMELLIA_encrypt hc_CAMELLIA_encrypt
|
||||
#define CAMELLIA_decrypt hc_CAMELLIA_decrypt
|
||||
#define CAMELLIA_cbc_encrypt hc_CAMELLIA_cbc_encrypt
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#define CAMELLIA_BLOCK_SIZE 16
|
||||
#define CAMELLIA_TABLE_BYTE_LEN 272
|
||||
#define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / 4)
|
||||
|
||||
#define CAMELLIA_ENCRYPT 1
|
||||
#define CAMELLIA_DECRYPT 0
|
||||
|
||||
typedef struct camellia_key {
|
||||
unsigned int bits;
|
||||
uint32_t key[CAMELLIA_TABLE_WORD_LEN];
|
||||
} CAMELLIA_KEY;
|
||||
|
||||
int CAMELLIA_set_key(const unsigned char *, const int, CAMELLIA_KEY *);
|
||||
|
||||
void CAMELLIA_encrypt(const unsigned char *, unsigned char *,
|
||||
const CAMELLIA_KEY *);
|
||||
void CAMELLIA_decrypt(const unsigned char *, unsigned char *,
|
||||
const CAMELLIA_KEY *);
|
||||
|
||||
void CAMELLIA_cbc_encrypt(const unsigned char *, unsigned char *,
|
||||
const unsigned long, const CAMELLIA_KEY *,
|
||||
unsigned char *, int);
|
||||
|
||||
#endif /* HEIM_CAMELLIA_H */
|
196
src/external/heimdal/hcrypto/des-tables.h
vendored
Normal file
196
src/external/heimdal/hcrypto/des-tables.h
vendored
Normal file
@ -0,0 +1,196 @@
|
||||
/* GENERATE FILE from gen-des.pl, do not edit */
|
||||
|
||||
/* pc1_c_3 bit pattern 5 13 21 */
|
||||
static int pc1_c_3[8] = {
|
||||
0x00000000, 0x00000010, 0x00001000, 0x00001010,
|
||||
0x00100000, 0x00100010, 0x00101000, 0x00101010
|
||||
};
|
||||
/* pc1_c_4 bit pattern 1 9 17 25 */
|
||||
static int pc1_c_4[16] = {
|
||||
0x00000000, 0x00000001, 0x00000100, 0x00000101,
|
||||
0x00010000, 0x00010001, 0x00010100, 0x00010101,
|
||||
0x01000000, 0x01000001, 0x01000100, 0x01000101,
|
||||
0x01010000, 0x01010001, 0x01010100, 0x01010101
|
||||
};
|
||||
/* pc1_d_3 bit pattern 49 41 33 */
|
||||
static int pc1_d_3[8] = {
|
||||
0x00000000, 0x01000000, 0x00010000, 0x01010000,
|
||||
0x00000100, 0x01000100, 0x00010100, 0x01010100
|
||||
};
|
||||
/* pc1_d_4 bit pattern 57 53 45 37 */
|
||||
static int pc1_d_4[16] = {
|
||||
0x00000000, 0x00100000, 0x00001000, 0x00101000,
|
||||
0x00000010, 0x00100010, 0x00001010, 0x00101010,
|
||||
0x00000001, 0x00100001, 0x00001001, 0x00101001,
|
||||
0x00000011, 0x00100011, 0x00001011, 0x00101011
|
||||
};
|
||||
/* pc2_c_1 bit pattern 5 24 7 16 6 10 */
|
||||
static int pc2_c_1[64] = {
|
||||
0x00000000, 0x00004000, 0x00040000, 0x00044000,
|
||||
0x00000100, 0x00004100, 0x00040100, 0x00044100,
|
||||
0x00020000, 0x00024000, 0x00060000, 0x00064000,
|
||||
0x00020100, 0x00024100, 0x00060100, 0x00064100,
|
||||
0x00000001, 0x00004001, 0x00040001, 0x00044001,
|
||||
0x00000101, 0x00004101, 0x00040101, 0x00044101,
|
||||
0x00020001, 0x00024001, 0x00060001, 0x00064001,
|
||||
0x00020101, 0x00024101, 0x00060101, 0x00064101,
|
||||
0x00080000, 0x00084000, 0x000c0000, 0x000c4000,
|
||||
0x00080100, 0x00084100, 0x000c0100, 0x000c4100,
|
||||
0x000a0000, 0x000a4000, 0x000e0000, 0x000e4000,
|
||||
0x000a0100, 0x000a4100, 0x000e0100, 0x000e4100,
|
||||
0x00080001, 0x00084001, 0x000c0001, 0x000c4001,
|
||||
0x00080101, 0x00084101, 0x000c0101, 0x000c4101,
|
||||
0x000a0001, 0x000a4001, 0x000e0001, 0x000e4001,
|
||||
0x000a0101, 0x000a4101, 0x000e0101, 0x000e4101
|
||||
};
|
||||
/* pc2_c_2 bit pattern 20 18 12 3 15 23 */
|
||||
static int pc2_c_2[64] = {
|
||||
0x00000000, 0x00000002, 0x00000200, 0x00000202,
|
||||
0x00200000, 0x00200002, 0x00200200, 0x00200202,
|
||||
0x00001000, 0x00001002, 0x00001200, 0x00001202,
|
||||
0x00201000, 0x00201002, 0x00201200, 0x00201202,
|
||||
0x00000040, 0x00000042, 0x00000240, 0x00000242,
|
||||
0x00200040, 0x00200042, 0x00200240, 0x00200242,
|
||||
0x00001040, 0x00001042, 0x00001240, 0x00001242,
|
||||
0x00201040, 0x00201042, 0x00201240, 0x00201242,
|
||||
0x00000010, 0x00000012, 0x00000210, 0x00000212,
|
||||
0x00200010, 0x00200012, 0x00200210, 0x00200212,
|
||||
0x00001010, 0x00001012, 0x00001210, 0x00001212,
|
||||
0x00201010, 0x00201012, 0x00201210, 0x00201212,
|
||||
0x00000050, 0x00000052, 0x00000250, 0x00000252,
|
||||
0x00200050, 0x00200052, 0x00200250, 0x00200252,
|
||||
0x00001050, 0x00001052, 0x00001250, 0x00001252,
|
||||
0x00201050, 0x00201052, 0x00201250, 0x00201252
|
||||
};
|
||||
/* pc2_c_3 bit pattern 1 9 19 2 14 22 */
|
||||
static int pc2_c_3[64] = {
|
||||
0x00000000, 0x00000004, 0x00000400, 0x00000404,
|
||||
0x00400000, 0x00400004, 0x00400400, 0x00400404,
|
||||
0x00000020, 0x00000024, 0x00000420, 0x00000424,
|
||||
0x00400020, 0x00400024, 0x00400420, 0x00400424,
|
||||
0x00008000, 0x00008004, 0x00008400, 0x00008404,
|
||||
0x00408000, 0x00408004, 0x00408400, 0x00408404,
|
||||
0x00008020, 0x00008024, 0x00008420, 0x00008424,
|
||||
0x00408020, 0x00408024, 0x00408420, 0x00408424,
|
||||
0x00800000, 0x00800004, 0x00800400, 0x00800404,
|
||||
0x00c00000, 0x00c00004, 0x00c00400, 0x00c00404,
|
||||
0x00800020, 0x00800024, 0x00800420, 0x00800424,
|
||||
0x00c00020, 0x00c00024, 0x00c00420, 0x00c00424,
|
||||
0x00808000, 0x00808004, 0x00808400, 0x00808404,
|
||||
0x00c08000, 0x00c08004, 0x00c08400, 0x00c08404,
|
||||
0x00808020, 0x00808024, 0x00808420, 0x00808424,
|
||||
0x00c08020, 0x00c08024, 0x00c08420, 0x00c08424
|
||||
};
|
||||
/* pc2_c_4 bit pattern 11 13 4 17 21 8 */
|
||||
static int pc2_c_4[64] = {
|
||||
0x00000000, 0x00010000, 0x00000008, 0x00010008,
|
||||
0x00000080, 0x00010080, 0x00000088, 0x00010088,
|
||||
0x00100000, 0x00110000, 0x00100008, 0x00110008,
|
||||
0x00100080, 0x00110080, 0x00100088, 0x00110088,
|
||||
0x00000800, 0x00010800, 0x00000808, 0x00010808,
|
||||
0x00000880, 0x00010880, 0x00000888, 0x00010888,
|
||||
0x00100800, 0x00110800, 0x00100808, 0x00110808,
|
||||
0x00100880, 0x00110880, 0x00100888, 0x00110888,
|
||||
0x00002000, 0x00012000, 0x00002008, 0x00012008,
|
||||
0x00002080, 0x00012080, 0x00002088, 0x00012088,
|
||||
0x00102000, 0x00112000, 0x00102008, 0x00112008,
|
||||
0x00102080, 0x00112080, 0x00102088, 0x00112088,
|
||||
0x00002800, 0x00012800, 0x00002808, 0x00012808,
|
||||
0x00002880, 0x00012880, 0x00002888, 0x00012888,
|
||||
0x00102800, 0x00112800, 0x00102808, 0x00112808,
|
||||
0x00102880, 0x00112880, 0x00102888, 0x00112888
|
||||
};
|
||||
/* pc2_d_1 bit pattern 51 35 31 52 39 45 */
|
||||
static int pc2_d_1[64] = {
|
||||
0x00000000, 0x00000080, 0x00002000, 0x00002080,
|
||||
0x00000001, 0x00000081, 0x00002001, 0x00002081,
|
||||
0x00200000, 0x00200080, 0x00202000, 0x00202080,
|
||||
0x00200001, 0x00200081, 0x00202001, 0x00202081,
|
||||
0x00020000, 0x00020080, 0x00022000, 0x00022080,
|
||||
0x00020001, 0x00020081, 0x00022001, 0x00022081,
|
||||
0x00220000, 0x00220080, 0x00222000, 0x00222080,
|
||||
0x00220001, 0x00220081, 0x00222001, 0x00222081,
|
||||
0x00000002, 0x00000082, 0x00002002, 0x00002082,
|
||||
0x00000003, 0x00000083, 0x00002003, 0x00002083,
|
||||
0x00200002, 0x00200082, 0x00202002, 0x00202082,
|
||||
0x00200003, 0x00200083, 0x00202003, 0x00202083,
|
||||
0x00020002, 0x00020082, 0x00022002, 0x00022082,
|
||||
0x00020003, 0x00020083, 0x00022003, 0x00022083,
|
||||
0x00220002, 0x00220082, 0x00222002, 0x00222082,
|
||||
0x00220003, 0x00220083, 0x00222003, 0x00222083
|
||||
};
|
||||
/* pc2_d_2 bit pattern 50 32 43 36 29 48 */
|
||||
static int pc2_d_2[64] = {
|
||||
0x00000000, 0x00000010, 0x00800000, 0x00800010,
|
||||
0x00010000, 0x00010010, 0x00810000, 0x00810010,
|
||||
0x00000200, 0x00000210, 0x00800200, 0x00800210,
|
||||
0x00010200, 0x00010210, 0x00810200, 0x00810210,
|
||||
0x00100000, 0x00100010, 0x00900000, 0x00900010,
|
||||
0x00110000, 0x00110010, 0x00910000, 0x00910010,
|
||||
0x00100200, 0x00100210, 0x00900200, 0x00900210,
|
||||
0x00110200, 0x00110210, 0x00910200, 0x00910210,
|
||||
0x00000004, 0x00000014, 0x00800004, 0x00800014,
|
||||
0x00010004, 0x00010014, 0x00810004, 0x00810014,
|
||||
0x00000204, 0x00000214, 0x00800204, 0x00800214,
|
||||
0x00010204, 0x00010214, 0x00810204, 0x00810214,
|
||||
0x00100004, 0x00100014, 0x00900004, 0x00900014,
|
||||
0x00110004, 0x00110014, 0x00910004, 0x00910014,
|
||||
0x00100204, 0x00100214, 0x00900204, 0x00900214,
|
||||
0x00110204, 0x00110214, 0x00910204, 0x00910214
|
||||
};
|
||||
/* pc2_d_3 bit pattern 41 38 47 33 40 42 */
|
||||
static int pc2_d_3[64] = {
|
||||
0x00000000, 0x00000400, 0x00001000, 0x00001400,
|
||||
0x00080000, 0x00080400, 0x00081000, 0x00081400,
|
||||
0x00000020, 0x00000420, 0x00001020, 0x00001420,
|
||||
0x00080020, 0x00080420, 0x00081020, 0x00081420,
|
||||
0x00004000, 0x00004400, 0x00005000, 0x00005400,
|
||||
0x00084000, 0x00084400, 0x00085000, 0x00085400,
|
||||
0x00004020, 0x00004420, 0x00005020, 0x00005420,
|
||||
0x00084020, 0x00084420, 0x00085020, 0x00085420,
|
||||
0x00000800, 0x00000c00, 0x00001800, 0x00001c00,
|
||||
0x00080800, 0x00080c00, 0x00081800, 0x00081c00,
|
||||
0x00000820, 0x00000c20, 0x00001820, 0x00001c20,
|
||||
0x00080820, 0x00080c20, 0x00081820, 0x00081c20,
|
||||
0x00004800, 0x00004c00, 0x00005800, 0x00005c00,
|
||||
0x00084800, 0x00084c00, 0x00085800, 0x00085c00,
|
||||
0x00004820, 0x00004c20, 0x00005820, 0x00005c20,
|
||||
0x00084820, 0x00084c20, 0x00085820, 0x00085c20
|
||||
};
|
||||
/* pc2_d_4 bit pattern 49 37 30 46 34 44 */
|
||||
static int pc2_d_4[64] = {
|
||||
0x00000000, 0x00000100, 0x00040000, 0x00040100,
|
||||
0x00000040, 0x00000140, 0x00040040, 0x00040140,
|
||||
0x00400000, 0x00400100, 0x00440000, 0x00440100,
|
||||
0x00400040, 0x00400140, 0x00440040, 0x00440140,
|
||||
0x00008000, 0x00008100, 0x00048000, 0x00048100,
|
||||
0x00008040, 0x00008140, 0x00048040, 0x00048140,
|
||||
0x00408000, 0x00408100, 0x00448000, 0x00448100,
|
||||
0x00408040, 0x00408140, 0x00448040, 0x00448140,
|
||||
0x00000008, 0x00000108, 0x00040008, 0x00040108,
|
||||
0x00000048, 0x00000148, 0x00040048, 0x00040148,
|
||||
0x00400008, 0x00400108, 0x00440008, 0x00440108,
|
||||
0x00400048, 0x00400148, 0x00440048, 0x00440148,
|
||||
0x00008008, 0x00008108, 0x00048008, 0x00048108,
|
||||
0x00008048, 0x00008148, 0x00048048, 0x00048148,
|
||||
0x00408008, 0x00408108, 0x00448008, 0x00448108,
|
||||
0x00408048, 0x00408148, 0x00448048, 0x00448148
|
||||
};
|
||||
static unsigned char odd_parity[256] = {
|
||||
1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
|
||||
16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
|
||||
32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
|
||||
49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
|
||||
64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
|
||||
81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
|
||||
97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
|
||||
112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
|
||||
128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
|
||||
145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
|
||||
161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
|
||||
176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
|
||||
193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
|
||||
208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
|
||||
224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
|
||||
241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254,
|
||||
};
|
1184
src/external/heimdal/hcrypto/des.c
vendored
Normal file
1184
src/external/heimdal/hcrypto/des.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
146
src/external/heimdal/hcrypto/des.h
vendored
Normal file
146
src/external/heimdal/hcrypto/des.h
vendored
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (c) 2005 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 _DESperate_H
|
||||
#define _DESperate_H 1
|
||||
|
||||
/* symbol renaming */
|
||||
#define _DES_ipfp_test _hc_DES_ipfp_test
|
||||
#define DES_cbc_cksum hc_DES_cbc_cksum
|
||||
#define DES_cbc_encrypt hc_DES_cbc_encrypt
|
||||
#define DES_cfb64_encrypt hc_DES_cfb64_encrypt
|
||||
#define DES_check_key_parity hc_DES_check_key_parity
|
||||
#define DES_ecb3_encrypt hc_DES_ecb3_encrypt
|
||||
#define DES_ecb_encrypt hc_DES_ecb_encrypt
|
||||
#define DES_ede3_cbc_encrypt hc_DES_ede3_cbc_encrypt
|
||||
#define DES_encrypt hc_DES_encrypt
|
||||
#define DES_generate_random_block hc_DES_generate_random_block
|
||||
#define DES_init_random_number_generator hc_DES_init_random_number_generator
|
||||
#define DES_is_weak_key hc_DES_is_weak_key
|
||||
#define DES_key_sched hc_DES_key_sched
|
||||
#define DES_new_random_key hc_DES_new_random_key
|
||||
#define DES_pcbc_encrypt hc_DES_pcbc_encrypt
|
||||
#define DES_rand_data hc_DES_rand_data
|
||||
#define DES_random_key hc_DES_random_key
|
||||
#define DES_read_password hc_DES_read_password
|
||||
#define DES_set_key hc_DES_set_key
|
||||
#define DES_set_key_checked hc_DES_set_key_checked
|
||||
#define DES_set_key_unchecked hc_DES_set_key_unchecked
|
||||
#define DES_set_key_sched hc_DES_set_key_sched
|
||||
#define DES_set_odd_parity hc_DES_set_odd_parity
|
||||
#define DES_set_random_generator_seed hc_DES_set_random_generator_seed
|
||||
#define DES_set_sequence_number hc_DES_set_sequence_number
|
||||
#define DES_string_to_key hc_DES_string_to_key
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#define DES_CBLOCK_LEN 8
|
||||
#define DES_KEY_SZ 8
|
||||
|
||||
#define DES_ENCRYPT 1
|
||||
#define DES_DECRYPT 0
|
||||
|
||||
typedef unsigned char DES_cblock[DES_CBLOCK_LEN];
|
||||
typedef struct DES_key_schedule
|
||||
{
|
||||
uint32_t ks[32];
|
||||
} DES_key_schedule;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HC_DEPRECATED
|
||||
#if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1 )))
|
||||
#define HC_DEPRECATED __attribute__((deprecated))
|
||||
#elif defined(_MSC_VER) && (_MSC_VER>1200)
|
||||
#define HC_DEPRECATED __declspec(deprecated)
|
||||
#else
|
||||
#define HC_DEPRECATED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void DES_set_odd_parity(DES_cblock *);
|
||||
int DES_check_key_parity(DES_cblock *);
|
||||
int DES_is_weak_key(DES_cblock *);
|
||||
int HC_DEPRECATED DES_set_key(DES_cblock *, DES_key_schedule *);
|
||||
int DES_set_key_checked(DES_cblock *, DES_key_schedule *);
|
||||
int DES_set_key_unchecked(DES_cblock *, DES_key_schedule *);
|
||||
int DES_key_sched(DES_cblock *, DES_key_schedule *);
|
||||
void DES_string_to_key(const char *, DES_cblock *);
|
||||
int DES_read_password(DES_cblock *, char *, int);
|
||||
|
||||
void HC_DEPRECATED DES_rand_data(void *, int);
|
||||
void HC_DEPRECATED DES_set_random_generator_seed(DES_cblock *);
|
||||
void HC_DEPRECATED DES_generate_random_block(DES_cblock *);
|
||||
void HC_DEPRECATED DES_set_sequence_number(void *);
|
||||
void HC_DEPRECATED DES_init_random_number_generator(DES_cblock *);
|
||||
void HC_DEPRECATED DES_random_key(DES_cblock *);
|
||||
int HC_DEPRECATED DES_new_random_key(DES_cblock *);
|
||||
|
||||
|
||||
void DES_encrypt(uint32_t [2], DES_key_schedule *, int);
|
||||
void DES_ecb_encrypt(DES_cblock *, DES_cblock *, DES_key_schedule *, int);
|
||||
void DES_ecb3_encrypt(DES_cblock *,DES_cblock *, DES_key_schedule *,
|
||||
DES_key_schedule *, DES_key_schedule *, int);
|
||||
void DES_pcbc_encrypt(const void *, void *, long,
|
||||
DES_key_schedule *, DES_cblock *, int);
|
||||
void DES_cbc_encrypt(const void *, void *, long,
|
||||
DES_key_schedule *, DES_cblock *, int);
|
||||
void DES_ede3_cbc_encrypt(const void *, void *, long,
|
||||
DES_key_schedule *, DES_key_schedule *,
|
||||
DES_key_schedule *, DES_cblock *, int);
|
||||
void DES_cfb64_encrypt(const void *, void *, long,
|
||||
DES_key_schedule *, DES_cblock *, int *, int);
|
||||
|
||||
|
||||
uint32_t DES_cbc_cksum(const void *, DES_cblock *,
|
||||
long, DES_key_schedule *, DES_cblock *);
|
||||
|
||||
|
||||
void _DES_ipfp_test(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _DESperate_H */
|
794
src/external/heimdal/hcrypto/evp-cc.c
vendored
Normal file
794
src/external/heimdal/hcrypto/evp-cc.c
vendored
Normal file
@ -0,0 +1,794 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Portions Copyright (c) 2009 Apple Inc. 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.
|
||||
*/
|
||||
|
||||
/* CommonCrypto provider */
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#endif
|
||||
#include <CommonCrypto/CommonCryptor.h>
|
||||
|
||||
#include <evp.h>
|
||||
#include <evp-cc.h>
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
struct cc_key {
|
||||
CCCryptorRef href;
|
||||
};
|
||||
|
||||
static int
|
||||
cc_do_cipher(EVP_CIPHER_CTX *ctx,
|
||||
unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned int size)
|
||||
{
|
||||
struct cc_key *cc = ctx->cipher_data;
|
||||
CCCryptorStatus ret;
|
||||
size_t moved;
|
||||
|
||||
memcpy(out, in, size);
|
||||
|
||||
ret = CCCryptorUpdate(cc->href, in, size, out, size, &moved);
|
||||
if (ret)
|
||||
return 0;
|
||||
|
||||
if (moved != size)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
cc_do_cfb8_cipher(EVP_CIPHER_CTX *ctx,
|
||||
unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned int size)
|
||||
{
|
||||
struct cc_key *cc = ctx->cipher_data;
|
||||
CCCryptorStatus ret;
|
||||
size_t moved;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
unsigned char oiv[EVP_MAX_IV_LENGTH + 1];
|
||||
|
||||
assert(ctx->cipher->iv_len + 1 <= sizeof(oiv));
|
||||
memcpy(oiv, ctx->iv, ctx->cipher->iv_len);
|
||||
|
||||
ret = CCCryptorUpdate(cc->href, ctx->iv, ctx->cipher->iv_len,
|
||||
ctx->iv, ctx->cipher->iv_len, &moved);
|
||||
if (ret)
|
||||
return 0;
|
||||
|
||||
if (moved != ctx->cipher->iv_len)
|
||||
return 0;
|
||||
|
||||
if (!ctx->encrypt)
|
||||
oiv[ctx->cipher->iv_len] = in[i];
|
||||
out[i] = in[i] ^ ctx->iv[0];
|
||||
if (ctx->encrypt)
|
||||
oiv[ctx->cipher->iv_len] = out[i];
|
||||
|
||||
memcpy(ctx->iv, &oiv[1], ctx->cipher->iv_len);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
cc_cleanup(EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
struct cc_key *cc = ctx->cipher_data;
|
||||
if (cc->href)
|
||||
CCCryptorRelease(cc->href);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
init_cc_key(int encp, CCAlgorithm alg, CCOptions opts, const void *key,
|
||||
size_t keylen, const void *iv, CCCryptorRef *ref)
|
||||
{
|
||||
CCOperation op = encp ? kCCEncrypt : kCCDecrypt;
|
||||
CCCryptorStatus ret;
|
||||
|
||||
if (*ref) {
|
||||
if (key == NULL && iv) {
|
||||
CCCryptorReset(*ref, iv);
|
||||
return 1;
|
||||
}
|
||||
CCCryptorRelease(*ref);
|
||||
}
|
||||
|
||||
ret = CCCryptorCreate(op, alg, opts, key, keylen, iv, ref);
|
||||
if (ret)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
cc_des_ede3_cbc_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char * key,
|
||||
const unsigned char * iv,
|
||||
int encp)
|
||||
{
|
||||
struct cc_key *cc = ctx->cipher_data;
|
||||
return init_cc_key(encp, kCCAlgorithm3DES, 0, key, kCCKeySize3DES, iv, &cc->href);
|
||||
}
|
||||
|
||||
/**
|
||||
* The tripple DES cipher type (Apple CommonCrypto provider)
|
||||
*
|
||||
* @return the DES-EDE3-CBC EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_des_ede3_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER des_ede3_cbc = {
|
||||
0,
|
||||
8,
|
||||
24,
|
||||
8,
|
||||
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
|
||||
cc_des_ede3_cbc_init,
|
||||
cc_do_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &des_ede3_cbc;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static int
|
||||
cc_des_cbc_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char * key,
|
||||
const unsigned char * iv,
|
||||
int encp)
|
||||
{
|
||||
struct cc_key *cc = ctx->cipher_data;
|
||||
return init_cc_key(encp, kCCAlgorithmDES, 0, key, kCCBlockSizeDES, iv, &cc->href);
|
||||
}
|
||||
|
||||
/**
|
||||
* The DES cipher type (Apple CommonCrypto provider)
|
||||
*
|
||||
* @return the DES-CBC EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_des_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER des_ede3_cbc = {
|
||||
0,
|
||||
kCCBlockSizeDES,
|
||||
kCCBlockSizeDES,
|
||||
kCCBlockSizeDES,
|
||||
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
|
||||
cc_des_cbc_init,
|
||||
cc_do_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &des_ede3_cbc;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static int
|
||||
cc_aes_cbc_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char * key,
|
||||
const unsigned char * iv,
|
||||
int encp)
|
||||
{
|
||||
struct cc_key *cc = ctx->cipher_data;
|
||||
return init_cc_key(encp, kCCAlgorithmAES128, 0, key, ctx->cipher->key_len, iv, &cc->href);
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-128 cipher type (Apple CommonCrypto provider)
|
||||
*
|
||||
* @return the AES-128-CBC EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_aes_128_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER c = {
|
||||
0,
|
||||
kCCBlockSizeAES128,
|
||||
kCCKeySizeAES128,
|
||||
kCCBlockSizeAES128,
|
||||
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
|
||||
cc_aes_cbc_init,
|
||||
cc_do_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &c;
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-192 cipher type (Apple CommonCrypto provider)
|
||||
*
|
||||
* @return the AES-192-CBC EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_aes_192_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER c = {
|
||||
0,
|
||||
kCCBlockSizeAES128,
|
||||
kCCKeySizeAES192,
|
||||
kCCBlockSizeAES128,
|
||||
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
|
||||
cc_aes_cbc_init,
|
||||
cc_do_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &c;
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-256 cipher type (Apple CommonCrypto provider)
|
||||
*
|
||||
* @return the AES-256-CBC EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_aes_256_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER c = {
|
||||
0,
|
||||
kCCBlockSizeAES128,
|
||||
kCCKeySizeAES256,
|
||||
kCCBlockSizeAES128,
|
||||
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
|
||||
cc_aes_cbc_init,
|
||||
cc_do_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &c;
|
||||
}
|
||||
|
||||
static int
|
||||
cc_aes_cfb8_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char * key,
|
||||
const unsigned char * iv,
|
||||
int encp)
|
||||
{
|
||||
struct cc_key *cc = ctx->cipher_data;
|
||||
return init_cc_key(1, kCCAlgorithmAES128, kCCOptionECBMode,
|
||||
key, ctx->cipher->key_len, NULL, &cc->href);
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-128 CFB8 cipher type (Apple CommonCrypto provider)
|
||||
*
|
||||
* @return the AES-128-CFB8 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_aes_128_cfb8(void)
|
||||
{
|
||||
static const EVP_CIPHER c = {
|
||||
0,
|
||||
1,
|
||||
kCCKeySizeAES128,
|
||||
kCCBlockSizeAES128,
|
||||
EVP_CIPH_CFB8_MODE,
|
||||
cc_aes_cfb8_init,
|
||||
cc_do_cfb8_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &c;
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-192 CFB8 cipher type (Apple CommonCrypto provider)
|
||||
*
|
||||
* @return the AES-192-CFB8 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_aes_192_cfb8(void)
|
||||
{
|
||||
static const EVP_CIPHER c = {
|
||||
0,
|
||||
1,
|
||||
kCCKeySizeAES192,
|
||||
kCCBlockSizeAES128,
|
||||
EVP_CIPH_CFB8_MODE,
|
||||
cc_aes_cfb8_init,
|
||||
cc_do_cfb8_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &c;
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-256 CFB8 cipher type (Apple CommonCrypto provider)
|
||||
*
|
||||
* @return the AES-256-CFB8 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_aes_256_cfb8(void)
|
||||
{
|
||||
static const EVP_CIPHER c = {
|
||||
0,
|
||||
1,
|
||||
kCCKeySizeAES256,
|
||||
kCCBlockSizeAES128,
|
||||
EVP_CIPH_CFB8_MODE,
|
||||
cc_aes_cfb8_init,
|
||||
cc_do_cfb8_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &c;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef COMMONCRYPTO_SUPPORTS_RC2
|
||||
static int
|
||||
cc_rc2_cbc_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char * key,
|
||||
const unsigned char * iv,
|
||||
int encp)
|
||||
{
|
||||
struct cc_key *cc = ctx->cipher_data;
|
||||
return init_cc_key(encp, kCCAlgorithmRC2, 0, key, ctx->cipher->key_len, iv, &cc->href);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The RC2 cipher type - common crypto
|
||||
*
|
||||
* @return the RC2 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_rc2_cbc(void)
|
||||
{
|
||||
#ifdef COMMONCRYPTO_SUPPORTS_RC2
|
||||
static const EVP_CIPHER rc2_cbc = {
|
||||
0,
|
||||
kCCBlockSizeRC2,
|
||||
16,
|
||||
kCCBlockSizeRC2,
|
||||
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
|
||||
cc_rc2_cbc_init,
|
||||
cc_do_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &rc2_cbc;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* The RC2-40 cipher type - common crypto
|
||||
*
|
||||
* @return the RC2-40 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_rc2_40_cbc(void)
|
||||
{
|
||||
#ifdef COMMONCRYPTO_SUPPORTS_RC2
|
||||
static const EVP_CIPHER rc2_40_cbc = {
|
||||
0,
|
||||
kCCBlockSizeRC2,
|
||||
5,
|
||||
kCCBlockSizeRC2,
|
||||
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
|
||||
cc_rc2_cbc_init,
|
||||
cc_do_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &rc2_40_cbc;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The RC2-64 cipher type - common crypto
|
||||
*
|
||||
* @return the RC2-64 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_rc2_64_cbc(void)
|
||||
{
|
||||
#ifdef COMMONCRYPTO_SUPPORTS_RC2
|
||||
static const EVP_CIPHER rc2_64_cbc = {
|
||||
0,
|
||||
kCCBlockSizeRC2,
|
||||
8,
|
||||
kCCBlockSizeRC2,
|
||||
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
|
||||
cc_rc2_cbc_init,
|
||||
cc_do_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &rc2_64_cbc;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* The CommonCrypto md2 provider
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_MD *
|
||||
EVP_cc_md2(void)
|
||||
{
|
||||
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
|
||||
static const struct hc_evp_md md2 = {
|
||||
CC_MD2_DIGEST_LENGTH,
|
||||
CC_MD2_BLOCK_BYTES,
|
||||
sizeof(CC_MD2_CTX),
|
||||
(hc_evp_md_init)CC_MD2_Init,
|
||||
(hc_evp_md_update)CC_MD2_Update,
|
||||
(hc_evp_md_final)CC_MD2_Final,
|
||||
(hc_evp_md_cleanup)NULL
|
||||
};
|
||||
return &md2;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* The CommonCrypto md4 provider
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_MD *
|
||||
EVP_cc_md4(void)
|
||||
{
|
||||
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
|
||||
static const struct hc_evp_md md4 = {
|
||||
CC_MD4_DIGEST_LENGTH,
|
||||
CC_MD4_BLOCK_BYTES,
|
||||
sizeof(CC_MD4_CTX),
|
||||
(hc_evp_md_init)CC_MD4_Init,
|
||||
(hc_evp_md_update)CC_MD4_Update,
|
||||
(hc_evp_md_final)CC_MD4_Final,
|
||||
(hc_evp_md_cleanup)NULL
|
||||
};
|
||||
return &md4;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* The CommonCrypto md5 provider
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_MD *
|
||||
EVP_cc_md5(void)
|
||||
{
|
||||
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
|
||||
static const struct hc_evp_md md5 = {
|
||||
CC_MD5_DIGEST_LENGTH,
|
||||
CC_MD5_BLOCK_BYTES,
|
||||
sizeof(CC_MD5_CTX),
|
||||
(hc_evp_md_init)CC_MD5_Init,
|
||||
(hc_evp_md_update)CC_MD5_Update,
|
||||
(hc_evp_md_final)CC_MD5_Final,
|
||||
(hc_evp_md_cleanup)NULL
|
||||
};
|
||||
return &md5;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* The CommonCrypto sha1 provider
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_MD *
|
||||
EVP_cc_sha1(void)
|
||||
{
|
||||
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
|
||||
static const struct hc_evp_md sha1 = {
|
||||
CC_SHA1_DIGEST_LENGTH,
|
||||
CC_SHA1_BLOCK_BYTES,
|
||||
sizeof(CC_SHA1_CTX),
|
||||
(hc_evp_md_init)CC_SHA1_Init,
|
||||
(hc_evp_md_update)CC_SHA1_Update,
|
||||
(hc_evp_md_final)CC_SHA1_Final,
|
||||
(hc_evp_md_cleanup)NULL
|
||||
};
|
||||
return &sha1;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* The CommonCrypto sha256 provider
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_MD *
|
||||
EVP_cc_sha256(void)
|
||||
{
|
||||
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
|
||||
static const struct hc_evp_md sha256 = {
|
||||
CC_SHA256_DIGEST_LENGTH,
|
||||
CC_SHA256_BLOCK_BYTES,
|
||||
sizeof(CC_SHA256_CTX),
|
||||
(hc_evp_md_init)CC_SHA256_Init,
|
||||
(hc_evp_md_update)CC_SHA256_Update,
|
||||
(hc_evp_md_final)CC_SHA256_Final,
|
||||
(hc_evp_md_cleanup)NULL
|
||||
};
|
||||
return &sha256;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* The Camellia-128 cipher type - CommonCrypto
|
||||
*
|
||||
* @return the Camellia-128 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_camellia_128_cbc(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Camellia-198 cipher type - CommonCrypto
|
||||
*
|
||||
* @return the Camellia-198 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_camellia_192_cbc(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Camellia-256 cipher type - CommonCrypto
|
||||
*
|
||||
* @return the Camellia-256 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_camellia_256_cbc(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static int
|
||||
cc_rc4_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char * key,
|
||||
const unsigned char * iv,
|
||||
int encp)
|
||||
{
|
||||
struct cc_key *cc = ctx->cipher_data;
|
||||
return init_cc_key(encp, kCCAlgorithmRC4, 0, key, ctx->key_len, iv, &cc->href);
|
||||
}
|
||||
|
||||
/**
|
||||
* The RC4 cipher type (Apple CommonCrypto provider)
|
||||
*
|
||||
* @return the RC4 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_rc4(void)
|
||||
{
|
||||
static const EVP_CIPHER rc4 = {
|
||||
0,
|
||||
1,
|
||||
16,
|
||||
0,
|
||||
EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
|
||||
cc_rc4_init,
|
||||
cc_do_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &rc4;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The RC4-40 cipher type (Apple CommonCrypto provider)
|
||||
*
|
||||
* @return the RC4 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_cc_rc4_40(void)
|
||||
{
|
||||
static const EVP_CIPHER rc4_40 = {
|
||||
0,
|
||||
1,
|
||||
5,
|
||||
0,
|
||||
EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
|
||||
cc_rc4_init,
|
||||
cc_do_cipher,
|
||||
cc_cleanup,
|
||||
sizeof(struct cc_key),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &rc4_40;
|
||||
}
|
||||
|
||||
#endif /* __APPLE__ */
|
98
src/external/heimdal/hcrypto/evp-cc.h
vendored
Normal file
98
src/external/heimdal/hcrypto/evp-cc.h
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2009 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 HEIM_EVP_CC_H
|
||||
#define HEIM_EVP_CC_H 1
|
||||
|
||||
/* symbol renaming */
|
||||
#define EVP_cc_md2 hc_EVP_cc_md2
|
||||
#define EVP_cc_md4 hc_EVP_cc_md4
|
||||
#define EVP_cc_md5 hc_EVP_cc_md5
|
||||
#define EVP_cc_sha1 hc_EVP_cc_sha1
|
||||
#define EVP_cc_sha256 hc_EVP_cc_sha256
|
||||
#define EVP_cc_des_cbc hc_EVP_cc_des_cbc
|
||||
#define EVP_cc_des_ede3_cbc hc_EVP_cc_des_ede3_cbc
|
||||
#define EVP_cc_aes_128_cbc hc_EVP_cc_aes_128_cbc
|
||||
#define EVP_cc_aes_192_cbc hc_EVP_cc_aes_192_cbc
|
||||
#define EVP_cc_aes_256_cbc hc_EVP_cc_aes_256_cbc
|
||||
#define EVP_cc_aes_cfb_128_cbc hc_EVP_cc_aes_128_cfb8
|
||||
#define EVP_cc_aes_cfb_192_cbc hc_EVP_cc_aes_192_cfb8
|
||||
#define EVP_cc_aes_cfb_256_cbc hc_EVP_cc_aes_256_cfb8
|
||||
#define EVP_cc_rc4 hc_EVP_cc_rc4
|
||||
#define EVP_cc_rc4_40 hc_EVP_cc_rc4_40
|
||||
#define EVP_cc_rc2_40_cbc hc_EVP_cc_rc2_40_cbc
|
||||
#define EVP_cc_rc2_64_cbc hc_EVP_cc_rc2_64_cbc
|
||||
#define EVP_cc_rc2_cbc hc_EVP_cc_rc2_cbc
|
||||
#define EVP_cc_camellia_128_cbc hc_EVP_cc_camellia_128_cbc
|
||||
#define EVP_cc_camellia_192_cbc hc_EVP_cc_camellia_192_cbc
|
||||
#define EVP_cc_camellia_256_cbc hc_EVP_cc_camellia_256_cbc
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
HC_CPP_BEGIN
|
||||
|
||||
const EVP_MD * EVP_cc_md2(void);
|
||||
const EVP_MD * EVP_cc_md4(void);
|
||||
const EVP_MD * EVP_cc_md5(void);
|
||||
const EVP_MD * EVP_cc_sha1(void);
|
||||
const EVP_MD * EVP_cc_sha256(void);
|
||||
|
||||
const EVP_CIPHER * EVP_cc_rc2_cbc(void);
|
||||
const EVP_CIPHER * EVP_cc_rc2_40_cbc(void);
|
||||
const EVP_CIPHER * EVP_cc_rc2_64_cbc(void);
|
||||
|
||||
const EVP_CIPHER * EVP_cc_rc4(void);
|
||||
const EVP_CIPHER * EVP_cc_rc4_40(void);
|
||||
|
||||
const EVP_CIPHER * EVP_cc_des_cbc(void);
|
||||
const EVP_CIPHER * EVP_cc_des_ede3_cbc(void);
|
||||
|
||||
const EVP_CIPHER * EVP_cc_aes_128_cbc(void);
|
||||
const EVP_CIPHER * EVP_cc_aes_192_cbc(void);
|
||||
const EVP_CIPHER * EVP_cc_aes_256_cbc(void);
|
||||
|
||||
const EVP_CIPHER * EVP_cc_aes_128_cfb8(void);
|
||||
const EVP_CIPHER * EVP_cc_aes_192_cfb8(void);
|
||||
const EVP_CIPHER * EVP_cc_aes_256_cfb8(void);
|
||||
|
||||
const EVP_CIPHER * EVP_cc_camellia_128_cbc(void);
|
||||
const EVP_CIPHER * EVP_cc_camellia_192_cbc(void);
|
||||
const EVP_CIPHER * EVP_cc_camellia_256_cbc(void);
|
||||
|
||||
HC_CPP_END
|
||||
|
||||
#endif /* HEIM_EVP_CC_H */
|
811
src/external/heimdal/hcrypto/evp-hcrypto.c
vendored
Normal file
811
src/external/heimdal/hcrypto/evp-hcrypto.c
vendored
Normal file
@ -0,0 +1,811 @@
|
||||
/*
|
||||
* Copyright (c) 2006 - 2008 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>
|
||||
|
||||
#define HC_DEPRECATED
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <evp.h>
|
||||
#include <evp-hcrypto.h>
|
||||
|
||||
#include <krb5-types.h>
|
||||
|
||||
#include <des.h>
|
||||
#include "camellia.h"
|
||||
#include <aes.h>
|
||||
|
||||
#include <rc2.h>
|
||||
#include <rc4.h>
|
||||
|
||||
#include <sha.h>
|
||||
#include <md2.h>
|
||||
#include <md4.h>
|
||||
#include <md5.h>
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static int
|
||||
aes_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char * key,
|
||||
const unsigned char * iv,
|
||||
int encp)
|
||||
{
|
||||
AES_KEY *k = ctx->cipher_data;
|
||||
if (ctx->encrypt)
|
||||
AES_set_encrypt_key(key, ctx->cipher->key_len * 8, k);
|
||||
else
|
||||
AES_set_decrypt_key(key, ctx->cipher->key_len * 8, k);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
aes_do_cipher(EVP_CIPHER_CTX *ctx,
|
||||
unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned int size)
|
||||
{
|
||||
AES_KEY *k = ctx->cipher_data;
|
||||
if (ctx->flags & EVP_CIPH_CFB8_MODE)
|
||||
AES_cfb8_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
|
||||
else
|
||||
AES_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-128 cipher type (hcrypto)
|
||||
*
|
||||
* @return the AES-128 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_aes_128_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER aes_128_cbc = {
|
||||
0,
|
||||
16,
|
||||
16,
|
||||
16,
|
||||
EVP_CIPH_CBC_MODE,
|
||||
aes_init,
|
||||
aes_do_cipher,
|
||||
NULL,
|
||||
sizeof(AES_KEY),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
return &aes_128_cbc;
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-192 cipher type (hcrypto)
|
||||
*
|
||||
* @return the AES-192 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_aes_192_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER aes_192_cbc = {
|
||||
0,
|
||||
16,
|
||||
24,
|
||||
16,
|
||||
EVP_CIPH_CBC_MODE,
|
||||
aes_init,
|
||||
aes_do_cipher,
|
||||
NULL,
|
||||
sizeof(AES_KEY),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &aes_192_cbc;
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-256 cipher type (hcrypto)
|
||||
*
|
||||
* @return the AES-256 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_aes_256_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER aes_256_cbc = {
|
||||
0,
|
||||
16,
|
||||
32,
|
||||
16,
|
||||
EVP_CIPH_CBC_MODE,
|
||||
aes_init,
|
||||
aes_do_cipher,
|
||||
NULL,
|
||||
sizeof(AES_KEY),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &aes_256_cbc;
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-128 CFB8 cipher type (hcrypto)
|
||||
*
|
||||
* @return the AES-128 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_aes_128_cfb8(void)
|
||||
{
|
||||
static const EVP_CIPHER aes_128_cfb8 = {
|
||||
0,
|
||||
1,
|
||||
16,
|
||||
16,
|
||||
EVP_CIPH_CFB8_MODE,
|
||||
aes_init,
|
||||
aes_do_cipher,
|
||||
NULL,
|
||||
sizeof(AES_KEY),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
return &aes_128_cfb8;
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-192 CFB8 cipher type (hcrypto)
|
||||
*
|
||||
* @return the AES-192 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_aes_192_cfb8(void)
|
||||
{
|
||||
static const EVP_CIPHER aes_192_cfb8 = {
|
||||
0,
|
||||
1,
|
||||
24,
|
||||
16,
|
||||
EVP_CIPH_CFB8_MODE,
|
||||
aes_init,
|
||||
aes_do_cipher,
|
||||
NULL,
|
||||
sizeof(AES_KEY),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &aes_192_cfb8;
|
||||
}
|
||||
|
||||
/**
|
||||
* The AES-256 CFB8 cipher type (hcrypto)
|
||||
*
|
||||
* @return the AES-256 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_aes_256_cfb8(void)
|
||||
{
|
||||
static const EVP_CIPHER aes_256_cfb8 = {
|
||||
0,
|
||||
1,
|
||||
32,
|
||||
16,
|
||||
EVP_CIPH_CFB8_MODE,
|
||||
aes_init,
|
||||
aes_do_cipher,
|
||||
NULL,
|
||||
sizeof(AES_KEY),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &aes_256_cfb8;
|
||||
}
|
||||
|
||||
/**
|
||||
* The message digest SHA256 - hcrypto
|
||||
*
|
||||
* @return the message digest type.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_MD *
|
||||
EVP_hcrypto_sha256(void)
|
||||
{
|
||||
static const struct hc_evp_md sha256 = {
|
||||
32,
|
||||
64,
|
||||
sizeof(SHA256_CTX),
|
||||
(hc_evp_md_init)SHA256_Init,
|
||||
(hc_evp_md_update)SHA256_Update,
|
||||
(hc_evp_md_final)SHA256_Final,
|
||||
NULL
|
||||
};
|
||||
return &sha256;
|
||||
}
|
||||
|
||||
/**
|
||||
* The message digest SHA1 - hcrypto
|
||||
*
|
||||
* @return the message digest type.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_MD *
|
||||
EVP_hcrypto_sha1(void)
|
||||
{
|
||||
static const struct hc_evp_md sha1 = {
|
||||
20,
|
||||
64,
|
||||
sizeof(SHA_CTX),
|
||||
(hc_evp_md_init)SHA1_Init,
|
||||
(hc_evp_md_update)SHA1_Update,
|
||||
(hc_evp_md_final)SHA1_Final,
|
||||
NULL
|
||||
};
|
||||
return &sha1;
|
||||
}
|
||||
|
||||
/**
|
||||
* The message digest MD5 - hcrypto
|
||||
*
|
||||
* @return the message digest type.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_MD *
|
||||
EVP_hcrypto_md5(void)
|
||||
{
|
||||
static const struct hc_evp_md md5 = {
|
||||
16,
|
||||
64,
|
||||
sizeof(MD5_CTX),
|
||||
(hc_evp_md_init)MD5_Init,
|
||||
(hc_evp_md_update)MD5_Update,
|
||||
(hc_evp_md_final)MD5_Final,
|
||||
NULL
|
||||
};
|
||||
return &md5;
|
||||
}
|
||||
|
||||
/**
|
||||
* The message digest MD4 - hcrypto
|
||||
*
|
||||
* @return the message digest type.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_MD *
|
||||
EVP_hcrypto_md4(void)
|
||||
{
|
||||
static const struct hc_evp_md md4 = {
|
||||
16,
|
||||
64,
|
||||
sizeof(MD4_CTX),
|
||||
(hc_evp_md_init)MD4_Init,
|
||||
(hc_evp_md_update)MD4_Update,
|
||||
(hc_evp_md_final)MD4_Final,
|
||||
NULL
|
||||
};
|
||||
return &md4;
|
||||
}
|
||||
|
||||
/**
|
||||
* The message digest MD2 - hcrypto
|
||||
*
|
||||
* @return the message digest type.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_MD *
|
||||
EVP_hcrypto_md2(void)
|
||||
{
|
||||
static const struct hc_evp_md md2 = {
|
||||
16,
|
||||
16,
|
||||
sizeof(MD2_CTX),
|
||||
(hc_evp_md_init)MD2_Init,
|
||||
(hc_evp_md_update)MD2_Update,
|
||||
(hc_evp_md_final)MD2_Final,
|
||||
NULL
|
||||
};
|
||||
return &md2;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static int
|
||||
des_cbc_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char * key,
|
||||
const unsigned char * iv,
|
||||
int encp)
|
||||
{
|
||||
DES_key_schedule *k = ctx->cipher_data;
|
||||
DES_cblock deskey;
|
||||
memcpy(&deskey, key, sizeof(deskey));
|
||||
DES_set_key_unchecked(&deskey, k);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
des_cbc_do_cipher(EVP_CIPHER_CTX *ctx,
|
||||
unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned int size)
|
||||
{
|
||||
DES_key_schedule *k = ctx->cipher_data;
|
||||
DES_cbc_encrypt(in, out, size,
|
||||
k, (DES_cblock *)ctx->iv, ctx->encrypt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* The DES cipher type
|
||||
*
|
||||
* @return the DES-CBC EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_des_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER des_cbc = {
|
||||
0,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
EVP_CIPH_CBC_MODE,
|
||||
des_cbc_init,
|
||||
des_cbc_do_cipher,
|
||||
NULL,
|
||||
sizeof(DES_key_schedule),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &des_cbc;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
struct des_ede3_cbc {
|
||||
DES_key_schedule ks[3];
|
||||
};
|
||||
|
||||
static int
|
||||
des_ede3_cbc_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char * key,
|
||||
const unsigned char * iv,
|
||||
int encp)
|
||||
{
|
||||
struct des_ede3_cbc *k = ctx->cipher_data;
|
||||
DES_cblock deskey;
|
||||
|
||||
memcpy(&deskey, key, sizeof(deskey));
|
||||
DES_set_odd_parity(&deskey);
|
||||
DES_set_key_unchecked(&deskey, &k->ks[0]);
|
||||
|
||||
memcpy(&deskey, key + 8, sizeof(deskey));
|
||||
DES_set_odd_parity(&deskey);
|
||||
DES_set_key_unchecked(&deskey, &k->ks[1]);
|
||||
|
||||
memcpy(&deskey, key + 16, sizeof(deskey));
|
||||
DES_set_odd_parity(&deskey);
|
||||
DES_set_key_unchecked(&deskey, &k->ks[2]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
des_ede3_cbc_do_cipher(EVP_CIPHER_CTX *ctx,
|
||||
unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned int size)
|
||||
{
|
||||
struct des_ede3_cbc *k = ctx->cipher_data;
|
||||
DES_ede3_cbc_encrypt(in, out, size,
|
||||
&k->ks[0], &k->ks[1], &k->ks[2],
|
||||
(DES_cblock *)ctx->iv, ctx->encrypt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* The tripple DES cipher type - hcrypto
|
||||
*
|
||||
* @return the DES-EDE3-CBC EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_des_ede3_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER des_ede3_cbc = {
|
||||
0,
|
||||
8,
|
||||
24,
|
||||
8,
|
||||
EVP_CIPH_CBC_MODE,
|
||||
des_ede3_cbc_init,
|
||||
des_ede3_cbc_do_cipher,
|
||||
NULL,
|
||||
sizeof(struct des_ede3_cbc),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &des_ede3_cbc;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
struct rc2_cbc {
|
||||
unsigned int maximum_effective_key;
|
||||
RC2_KEY key;
|
||||
};
|
||||
|
||||
static int
|
||||
rc2_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char * key,
|
||||
const unsigned char * iv,
|
||||
int encp)
|
||||
{
|
||||
struct rc2_cbc *k = ctx->cipher_data;
|
||||
k->maximum_effective_key = EVP_CIPHER_CTX_key_length(ctx) * 8;
|
||||
RC2_set_key(&k->key,
|
||||
EVP_CIPHER_CTX_key_length(ctx),
|
||||
key,
|
||||
k->maximum_effective_key);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
rc2_do_cipher(EVP_CIPHER_CTX *ctx,
|
||||
unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned int size)
|
||||
{
|
||||
struct rc2_cbc *k = ctx->cipher_data;
|
||||
RC2_cbc_encrypt(in, out, size, &k->key, ctx->iv, ctx->encrypt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* The RC2 cipher type - hcrypto
|
||||
*
|
||||
* @return the RC2 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_rc2_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER rc2_cbc = {
|
||||
0,
|
||||
RC2_BLOCK_SIZE,
|
||||
RC2_KEY_LENGTH,
|
||||
RC2_BLOCK_SIZE,
|
||||
EVP_CIPH_CBC_MODE|EVP_CIPH_VARIABLE_LENGTH,
|
||||
rc2_init,
|
||||
rc2_do_cipher,
|
||||
NULL,
|
||||
sizeof(struct rc2_cbc),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &rc2_cbc;
|
||||
}
|
||||
|
||||
/**
|
||||
* The RC2-40 cipher type
|
||||
*
|
||||
* @return the RC2-40 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_rc2_40_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER rc2_40_cbc = {
|
||||
0,
|
||||
RC2_BLOCK_SIZE,
|
||||
5,
|
||||
RC2_BLOCK_SIZE,
|
||||
EVP_CIPH_CBC_MODE,
|
||||
rc2_init,
|
||||
rc2_do_cipher,
|
||||
NULL,
|
||||
sizeof(struct rc2_cbc),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &rc2_40_cbc;
|
||||
}
|
||||
|
||||
/**
|
||||
* The RC2-64 cipher type
|
||||
*
|
||||
* @return the RC2-64 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_rc2_64_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER rc2_64_cbc = {
|
||||
0,
|
||||
RC2_BLOCK_SIZE,
|
||||
8,
|
||||
RC2_BLOCK_SIZE,
|
||||
EVP_CIPH_CBC_MODE,
|
||||
rc2_init,
|
||||
rc2_do_cipher,
|
||||
NULL,
|
||||
sizeof(struct rc2_cbc),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &rc2_64_cbc;
|
||||
}
|
||||
|
||||
static int
|
||||
camellia_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char * key,
|
||||
const unsigned char * iv,
|
||||
int encp)
|
||||
{
|
||||
CAMELLIA_KEY *k = ctx->cipher_data;
|
||||
k->bits = ctx->cipher->key_len * 8;
|
||||
CAMELLIA_set_key(key, ctx->cipher->key_len * 8, k);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
camellia_do_cipher(EVP_CIPHER_CTX *ctx,
|
||||
unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned int size)
|
||||
{
|
||||
CAMELLIA_KEY *k = ctx->cipher_data;
|
||||
CAMELLIA_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Camellia-128 cipher type - hcrypto
|
||||
*
|
||||
* @return the Camellia-128 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_camellia_128_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER cipher = {
|
||||
0,
|
||||
16,
|
||||
16,
|
||||
16,
|
||||
EVP_CIPH_CBC_MODE,
|
||||
camellia_init,
|
||||
camellia_do_cipher,
|
||||
NULL,
|
||||
sizeof(CAMELLIA_KEY),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &cipher;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Camellia-198 cipher type - hcrypto
|
||||
*
|
||||
* @return the Camellia-198 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_camellia_192_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER cipher = {
|
||||
0,
|
||||
16,
|
||||
24,
|
||||
16,
|
||||
EVP_CIPH_CBC_MODE,
|
||||
camellia_init,
|
||||
camellia_do_cipher,
|
||||
NULL,
|
||||
sizeof(CAMELLIA_KEY),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &cipher;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Camellia-256 cipher type - hcrypto
|
||||
*
|
||||
* @return the Camellia-256 EVP_CIPHER pointer.
|
||||
*
|
||||
* @ingroup hcrypto_evp
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_camellia_256_cbc(void)
|
||||
{
|
||||
static const EVP_CIPHER cipher = {
|
||||
0,
|
||||
16,
|
||||
32,
|
||||
16,
|
||||
EVP_CIPH_CBC_MODE,
|
||||
camellia_init,
|
||||
camellia_do_cipher,
|
||||
NULL,
|
||||
sizeof(CAMELLIA_KEY),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &cipher;
|
||||
}
|
||||
|
||||
static int
|
||||
rc4_init(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char *key,
|
||||
const unsigned char *iv,
|
||||
int enc)
|
||||
{
|
||||
RC4_KEY *k = ctx->cipher_data;
|
||||
RC4_set_key(k, ctx->key_len, key);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
rc4_do_cipher(EVP_CIPHER_CTX *ctx,
|
||||
unsigned char *out,
|
||||
const unsigned char *in,
|
||||
unsigned int size)
|
||||
{
|
||||
RC4_KEY *k = ctx->cipher_data;
|
||||
RC4(k, size, in, out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_rc4(void)
|
||||
{
|
||||
static const EVP_CIPHER rc4 = {
|
||||
0,
|
||||
1,
|
||||
16,
|
||||
0,
|
||||
EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
|
||||
rc4_init,
|
||||
rc4_do_cipher,
|
||||
NULL,
|
||||
sizeof(RC4_KEY),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &rc4;
|
||||
}
|
||||
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_hcrypto_rc4_40(void)
|
||||
{
|
||||
static const EVP_CIPHER rc4_40 = {
|
||||
0,
|
||||
1,
|
||||
5,
|
||||
0,
|
||||
EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
|
||||
rc4_init,
|
||||
rc4_do_cipher,
|
||||
NULL,
|
||||
sizeof(RC4_KEY),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
return &rc4_40;
|
||||
}
|
99
src/external/heimdal/hcrypto/evp-hcrypto.h
vendored
Normal file
99
src/external/heimdal/hcrypto/evp-hcrypto.h
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2009 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 HEIM_EVP_HCRYPTO_H
|
||||
#define HEIM_EVP_HCRYPTO_H 1
|
||||
|
||||
/* symbol renaming */
|
||||
#define EVP_hcrypto_md2 hc_EVP_hcrypto_md2
|
||||
#define EVP_hcrypto_md4 hc_EVP_hcrypto_md4
|
||||
#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_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
|
||||
#define EVP_hcrypto_aes_192_cbc hc_EVP_hcrypto_aes_192_cbc
|
||||
#define EVP_hcrypto_aes_256_cbc hc_EVP_hcrypto_aes_256_cbc
|
||||
#define EVP_hcrypto_aes_128_cfb8 hc_EVP_hcrypto_aes_128_cfb8
|
||||
#define EVP_hcrypto_aes_192_cfb8 hc_EVP_hcrypto_aes_192_cfb8
|
||||
#define EVP_hcrypto_aes_256_cfb8 hc_EVP_hcrypto_aes_256_cfb8
|
||||
#define EVP_hcrypto_rc4 hc_EVP_hcrypto_rc4
|
||||
#define EVP_hcrypto_rc4_40 hc_EVP_hcrypto_rc4_40
|
||||
#define EVP_hcrypto_rc2_40_cbc hc_EVP_hcrypto_rc2_40_cbc
|
||||
#define EVP_hcrypto_rc2_64_cbc hc_EVP_hcrypto_rc2_64_cbc
|
||||
#define EVP_hcrypto_rc2_cbc hc_EVP_hcrypto_rc2_cbc
|
||||
#define EVP_hcrypto_camellia_128_cbc hc_EVP_hcrypto_camellia_128_cbc
|
||||
#define EVP_hcrypto_camellia_192_cbc hc_EVP_hcrypto_camellia_192_cbc
|
||||
#define EVP_hcrypto_camellia_256_cbc hc_EVP_hcrypto_camellia_256_cbc
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
HC_CPP_BEGIN
|
||||
|
||||
const EVP_MD * EVP_hcrypto_md2(void);
|
||||
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_CIPHER * EVP_hcrypto_rc4(void);
|
||||
const EVP_CIPHER * EVP_hcrypto_rc4_40(void);
|
||||
|
||||
const EVP_CIPHER * EVP_hcrypto_rc2_cbc(void);
|
||||
const EVP_CIPHER * EVP_hcrypto_rc2_40_cbc(void);
|
||||
const EVP_CIPHER * EVP_hcrypto_rc2_64_cbc(void);
|
||||
|
||||
const EVP_CIPHER * EVP_hcrypto_des_cbc(void);
|
||||
const EVP_CIPHER * EVP_hcrypto_des_ede3_cbc(void);
|
||||
|
||||
const EVP_CIPHER * EVP_hcrypto_aes_128_cbc(void);
|
||||
const EVP_CIPHER * EVP_hcrypto_aes_192_cbc(void);
|
||||
const EVP_CIPHER * EVP_hcrypto_aes_256_cbc(void);
|
||||
|
||||
const EVP_CIPHER * EVP_hcrypto_aes_128_cfb8(void);
|
||||
const EVP_CIPHER * EVP_hcrypto_aes_192_cfb8(void);
|
||||
const EVP_CIPHER * EVP_hcrypto_aes_256_cfb8(void);
|
||||
|
||||
const EVP_CIPHER * EVP_hcrypto_camellia_128_cbc(void);
|
||||
const EVP_CIPHER * EVP_hcrypto_camellia_192_cbc(void);
|
||||
const EVP_CIPHER * EVP_hcrypto_camellia_256_cbc(void);
|
||||
|
||||
|
||||
HC_CPP_END
|
||||
|
||||
#endif /* HEIM_EVP_HCRYPTO_H */
|
1442
src/external/heimdal/hcrypto/evp.c
vendored
Normal file
1442
src/external/heimdal/hcrypto/evp.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
321
src/external/heimdal/hcrypto/evp.h
vendored
Normal file
321
src/external/heimdal/hcrypto/evp.h
vendored
Normal file
@ -0,0 +1,321 @@
|
||||
/*
|
||||
* Copyright (c) 2005 - 2008 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 HEIM_EVP_H
|
||||
#define HEIM_EVP_H 1
|
||||
|
||||
#include <hcrypto/engine.h>
|
||||
|
||||
/* symbol renaming */
|
||||
#define EVP_CIPHER_CTX_block_size hc_EVP_CIPHER_CTX_block_size
|
||||
#define EVP_CIPHER_CTX_cipher hc_EVP_CIPHER_CTX_cipher
|
||||
#define EVP_CIPHER_CTX_cleanup hc_EVP_CIPHER_CTX_cleanup
|
||||
#define EVP_CIPHER_CTX_flags hc_EVP_CIPHER_CTX_flags
|
||||
#define EVP_CIPHER_CTX_get_app_data hc_EVP_CIPHER_CTX_get_app_data
|
||||
#define EVP_CIPHER_CTX_init hc_EVP_CIPHER_CTX_init
|
||||
#define EVP_CIPHER_CTX_iv_length hc_EVP_CIPHER_CTX_iv_length
|
||||
#define EVP_CIPHER_CTX_key_length hc_EVP_CIPHER_CTX_key_length
|
||||
#define EVP_CIPHER_CTX_mode hc_EVP_CIPHER_CTX_mode
|
||||
#define EVP_CIPHER_CTX_set_app_data hc_EVP_CIPHER_CTX_set_app_data
|
||||
#define EVP_CIPHER_CTX_set_key_length hc_EVP_CIPHER_CTX_set_key_length
|
||||
#define EVP_CIPHER_CTX_set_padding hc_EVP_CIPHER_CTX_set_padding
|
||||
#define EVP_CIPHER_block_size hc_EVP_CIPHER_block_size
|
||||
#define EVP_CIPHER_iv_length hc_EVP_CIPHER_iv_length
|
||||
#define EVP_CIPHER_key_length hc_EVP_CIPHER_key_length
|
||||
#define EVP_Cipher hc_EVP_Cipher
|
||||
#define EVP_CipherInit_ex hc_EVP_CipherInit_ex
|
||||
#define EVP_CipherUpdate hc_EVP_CipherUpdate
|
||||
#define EVP_CipherFinal_ex hc_EVP_CipherFinal_ex
|
||||
#define EVP_Digest hc_EVP_Digest
|
||||
#define EVP_DigestFinal_ex hc_EVP_DigestFinal_ex
|
||||
#define EVP_DigestInit_ex hc_EVP_DigestInit_ex
|
||||
#define EVP_DigestUpdate hc_EVP_DigestUpdate
|
||||
#define EVP_MD_CTX_block_size hc_EVP_MD_CTX_block_size
|
||||
#define EVP_MD_CTX_cleanup hc_EVP_MD_CTX_cleanup
|
||||
#define EVP_MD_CTX_create hc_EVP_MD_CTX_create
|
||||
#define EVP_MD_CTX_init hc_EVP_MD_CTX_init
|
||||
#define EVP_MD_CTX_destroy hc_EVP_MD_CTX_destroy
|
||||
#define EVP_MD_CTX_md hc_EVP_MD_CTX_md
|
||||
#define EVP_MD_CTX_size hc_EVP_MD_CTX_size
|
||||
#define EVP_MD_block_size hc_EVP_MD_block_size
|
||||
#define EVP_MD_size hc_EVP_MD_size
|
||||
#define EVP_aes_128_cbc hc_EVP_aes_128_cbc
|
||||
#define EVP_aes_192_cbc hc_EVP_aes_192_cbc
|
||||
#define EVP_aes_256_cbc hc_EVP_aes_256_cbc
|
||||
#define EVP_aes_128_cfb8 hc_EVP_aes_128_cfb8
|
||||
#define EVP_aes_192_cfb8 hc_EVP_aes_192_cfb8
|
||||
#define EVP_aes_256_cfb8 hc_EVP_aes_256_cfb8
|
||||
|
||||
#define EVP_des_cbc hc_EVP_des_cbc
|
||||
#define EVP_des_ede3_cbc hc_EVP_des_ede3_cbc
|
||||
#define EVP_enc_null hc_EVP_enc_null
|
||||
#define EVP_md2 hc_EVP_md2
|
||||
#define EVP_md4 hc_EVP_md4
|
||||
#define EVP_md5 hc_EVP_md5
|
||||
#define EVP_md_null hc_EVP_md_null
|
||||
#define EVP_rc2_40_cbc hc_EVP_rc2_40_cbc
|
||||
#define EVP_rc2_64_cbc hc_EVP_rc2_64_cbc
|
||||
#define EVP_rc2_cbc hc_EVP_rc2_cbc
|
||||
#define EVP_rc4 hc_EVP_rc4
|
||||
#define EVP_rc4_40 hc_EVP_rc4_40
|
||||
#define EVP_camellia_128_cbc hc_EVP_camellia_128_cbc
|
||||
#define EVP_camellia_192_cbc hc_EVP_camellia_192_cbc
|
||||
#define EVP_camellia_256_cbc hc_EVP_camellia_256_cbc
|
||||
#define EVP_sha hc_EVP_sha
|
||||
#define EVP_sha1 hc_EVP_sha1
|
||||
#define EVP_sha256 hc_EVP_sha256
|
||||
#define PKCS5_PBKDF2_HMAC_SHA1 hc_PKCS5_PBKDF2_HMAC_SHA1
|
||||
#define EVP_BytesToKey hc_EVP_BytesToKey
|
||||
#define EVP_get_cipherbyname hc_EVP_get_cipherbyname
|
||||
#define OpenSSL_add_all_algorithms hc_OpenSSL_add_all_algorithms
|
||||
#define OpenSSL_add_all_algorithms_conf hc_OpenSSL_add_all_algorithms_conf
|
||||
#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
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct hc_EVP_MD_CTX EVP_MD_CTX;
|
||||
typedef struct hc_evp_pkey EVP_PKEY;
|
||||
typedef struct hc_evp_md EVP_MD;
|
||||
typedef struct hc_CIPHER EVP_CIPHER;
|
||||
typedef struct hc_CIPHER_CTX EVP_CIPHER_CTX;
|
||||
|
||||
#define EVP_MAX_IV_LENGTH 16
|
||||
#define EVP_MAX_BLOCK_LENGTH 32
|
||||
|
||||
#define EVP_MAX_MD_SIZE 64
|
||||
|
||||
struct hc_CIPHER {
|
||||
int nid;
|
||||
int block_size;
|
||||
int key_len;
|
||||
int iv_len;
|
||||
unsigned long flags;
|
||||
/* The lowest 3 bits is used as integer field for the mode the
|
||||
* cipher is used in (use EVP_CIPHER.._mode() to extract the
|
||||
* mode). The rest of the flag field is a bitfield.
|
||||
*/
|
||||
#define EVP_CIPH_STREAM_CIPHER 0
|
||||
#define EVP_CIPH_CBC_MODE 2
|
||||
#define EVP_CIPH_CFB8_MODE 4
|
||||
#define EVP_CIPH_MODE 0x7
|
||||
|
||||
#define EVP_CIPH_VARIABLE_LENGTH 0x008 /* variable key length */
|
||||
#define EVP_CIPH_ALWAYS_CALL_INIT 0x020
|
||||
#define EVP_CIPH_RAND_KEY 0x200
|
||||
|
||||
int (*init)(EVP_CIPHER_CTX*,const unsigned char*,const unsigned char*,int);
|
||||
int (*do_cipher)(EVP_CIPHER_CTX *, unsigned char *,
|
||||
const unsigned char *, unsigned int);
|
||||
int (*cleanup)(EVP_CIPHER_CTX *);
|
||||
int ctx_size;
|
||||
void *set_asn1_parameters;
|
||||
void *get_asn1_parameters;
|
||||
int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr);
|
||||
#define EVP_CTRL_RAND_KEY 0x6
|
||||
|
||||
void *app_data;
|
||||
};
|
||||
|
||||
struct hc_CIPHER_CTX {
|
||||
const EVP_CIPHER *cipher;
|
||||
ENGINE *engine;
|
||||
int encrypt;
|
||||
int buf_len; /* bytes stored in buf for EVP_CipherUpdate */
|
||||
unsigned char oiv[EVP_MAX_IV_LENGTH];
|
||||
unsigned char iv[EVP_MAX_IV_LENGTH];
|
||||
unsigned char buf[EVP_MAX_BLOCK_LENGTH];
|
||||
int num;
|
||||
void *app_data;
|
||||
int key_len;
|
||||
unsigned long flags;
|
||||
void *cipher_data;
|
||||
int final_used;
|
||||
int block_mask;
|
||||
unsigned char final[EVP_MAX_BLOCK_LENGTH];
|
||||
};
|
||||
|
||||
typedef int (*hc_evp_md_init)(EVP_MD_CTX *);
|
||||
typedef int (*hc_evp_md_update)(EVP_MD_CTX *,const void *, size_t);
|
||||
typedef int (*hc_evp_md_final)(void *, EVP_MD_CTX *);
|
||||
typedef int (*hc_evp_md_cleanup)(EVP_MD_CTX *);
|
||||
|
||||
struct hc_evp_md {
|
||||
int hash_size;
|
||||
int block_size;
|
||||
int ctx_size;
|
||||
hc_evp_md_init init;
|
||||
hc_evp_md_update update;
|
||||
hc_evp_md_final final;
|
||||
hc_evp_md_cleanup cleanup;
|
||||
};
|
||||
|
||||
#if !defined(__GNUC__) && !defined(__attribute__)
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
|
||||
#ifndef HC_DEPRECATED
|
||||
#if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1 )))
|
||||
#define HC_DEPRECATED __attribute__((deprecated))
|
||||
#elif defined(_MSC_VER) && (_MSC_VER>1200)
|
||||
#define HC_DEPRECATED __declspec(deprecated)
|
||||
#else
|
||||
#define HC_DEPRECATED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HC_DEPRECATED_CRYPTO
|
||||
#define HC_DEPRECATED_CRYPTO HC_DEPRECATED
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define HC_CPP_BEGIN extern "C" {
|
||||
#define HC_CPP_END }
|
||||
#else
|
||||
#define HC_CPP_BEGIN
|
||||
#define HC_CPP_END
|
||||
#endif
|
||||
|
||||
HC_CPP_BEGIN
|
||||
|
||||
/*
|
||||
* Avaible crypto algs
|
||||
*/
|
||||
|
||||
const EVP_MD *EVP_md_null(void);
|
||||
HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md2(void);
|
||||
HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md4(void);
|
||||
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_CIPHER * EVP_aes_128_cbc(void);
|
||||
const EVP_CIPHER * EVP_aes_192_cbc(void);
|
||||
const EVP_CIPHER * EVP_aes_256_cbc(void);
|
||||
const EVP_CIPHER * EVP_aes_128_cfb8(void);
|
||||
const EVP_CIPHER * EVP_aes_192_cfb8(void);
|
||||
const EVP_CIPHER * EVP_aes_256_cfb8(void);
|
||||
HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_des_cbc(void);
|
||||
const EVP_CIPHER * EVP_des_ede3_cbc(void);
|
||||
const EVP_CIPHER * EVP_enc_null(void);
|
||||
HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_40_cbc(void);
|
||||
HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_64_cbc(void);
|
||||
HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_cbc(void);
|
||||
const EVP_CIPHER * EVP_rc4(void);
|
||||
HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc4_40(void);
|
||||
const EVP_CIPHER * EVP_camellia_128_cbc(void);
|
||||
const EVP_CIPHER * EVP_camellia_192_cbc(void);
|
||||
const EVP_CIPHER * EVP_camellia_256_cbc(void);
|
||||
|
||||
size_t EVP_MD_size(const EVP_MD *);
|
||||
size_t EVP_MD_block_size(const EVP_MD *);
|
||||
|
||||
const EVP_MD *
|
||||
EVP_MD_CTX_md(EVP_MD_CTX *);
|
||||
size_t EVP_MD_CTX_size(EVP_MD_CTX *);
|
||||
size_t EVP_MD_CTX_block_size(EVP_MD_CTX *);
|
||||
|
||||
EVP_MD_CTX *
|
||||
EVP_MD_CTX_create(void);
|
||||
void HC_DEPRECATED EVP_MD_CTX_init(EVP_MD_CTX *);
|
||||
void EVP_MD_CTX_destroy(EVP_MD_CTX *);
|
||||
int HC_DEPRECATED EVP_MD_CTX_cleanup(EVP_MD_CTX *);
|
||||
|
||||
int EVP_DigestInit_ex(EVP_MD_CTX *, const EVP_MD *, ENGINE *);
|
||||
int EVP_DigestUpdate(EVP_MD_CTX *,const void *, size_t);
|
||||
int EVP_DigestFinal_ex(EVP_MD_CTX *, void *, unsigned int *);
|
||||
int EVP_Digest(const void *, size_t, void *, unsigned int *,
|
||||
const EVP_MD *, ENGINE *);
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_get_cipherbyname(const char *);
|
||||
|
||||
size_t EVP_CIPHER_block_size(const EVP_CIPHER *);
|
||||
size_t EVP_CIPHER_key_length(const EVP_CIPHER *);
|
||||
size_t EVP_CIPHER_iv_length(const EVP_CIPHER *);
|
||||
|
||||
void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *);
|
||||
int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *);
|
||||
int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *, int);
|
||||
int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *, int);
|
||||
unsigned long
|
||||
EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *);
|
||||
int EVP_CIPHER_CTX_mode(const EVP_CIPHER_CTX *);
|
||||
|
||||
const EVP_CIPHER *
|
||||
EVP_CIPHER_CTX_cipher(EVP_CIPHER_CTX *);
|
||||
size_t EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *);
|
||||
size_t EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *);
|
||||
size_t EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *);
|
||||
void * EVP_CIPHER_CTX_get_app_data(EVP_CIPHER_CTX *);
|
||||
void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *, void *);
|
||||
|
||||
int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *, int, int, void *);
|
||||
int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *, void *);
|
||||
|
||||
|
||||
int EVP_CipherInit_ex(EVP_CIPHER_CTX *,const EVP_CIPHER *, ENGINE *,
|
||||
const void *, const void *, int);
|
||||
int EVP_CipherUpdate(EVP_CIPHER_CTX *, void *, int *, void *, size_t);
|
||||
int EVP_CipherFinal_ex(EVP_CIPHER_CTX *, void *, int *);
|
||||
|
||||
int EVP_Cipher(EVP_CIPHER_CTX *,void *,const void *,size_t);
|
||||
|
||||
int PKCS5_PBKDF2_HMAC_SHA1(const void *, size_t, const void *, size_t,
|
||||
unsigned long, size_t, void *);
|
||||
|
||||
int EVP_BytesToKey(const EVP_CIPHER *, const EVP_MD *,
|
||||
const void *, const void *, size_t,
|
||||
unsigned int, void *, void *);
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
void OpenSSL_add_all_algorithms(void);
|
||||
void OpenSSL_add_all_algorithms_conf(void);
|
||||
void OpenSSL_add_all_algorithms_noconf(void);
|
||||
|
||||
HC_CPP_END
|
||||
|
||||
#endif /* HEIM_EVP_H */
|
69
src/external/heimdal/hcrypto/hash.h
vendored
Normal file
69
src/external/heimdal/hcrypto/hash.h
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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. */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* stuff in common between md4, md5, and sha1 */
|
||||
|
||||
#ifndef __hash_h__
|
||||
#define __hash_h__
|
||||
|
||||
#ifdef KRB5
|
||||
#include <krb5-types.h>
|
||||
#endif
|
||||
#include <roken.h>
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) (((a)>(b))?(b):(a))
|
||||
#endif
|
||||
|
||||
/* Vector Crays doesn't have a good 32-bit type, or more precisely,
|
||||
int32_t as defined by <bind/bitypes.h> isn't 32 bits, and we don't
|
||||
want to depend in being able to redefine this type. To cope with
|
||||
this we have to clamp the result in some places to [0,2^32); no
|
||||
need to do this on other machines. Did I say this was a mess?
|
||||
*/
|
||||
|
||||
#ifdef _CRAY
|
||||
#define CRAYFIX(X) ((X) & 0xffffffff)
|
||||
#else
|
||||
#define CRAYFIX(X) (X)
|
||||
#endif
|
||||
|
||||
static inline uint32_t
|
||||
cshift (uint32_t x, unsigned int n)
|
||||
{
|
||||
x = CRAYFIX(x);
|
||||
return CRAYFIX((x << n) | (x >> (32 - n)));
|
||||
}
|
||||
|
||||
#endif /* __hash_h__ */
|
162
src/external/heimdal/hcrypto/hmac.c
vendored
Normal file
162
src/external/heimdal/hcrypto/hmac.c
vendored
Normal file
@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (c) 2006 - 2007 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 <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <hmac.h>
|
||||
|
||||
void
|
||||
HMAC_CTX_init(HMAC_CTX *ctx)
|
||||
{
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
|
||||
void
|
||||
HMAC_CTX_cleanup(HMAC_CTX *ctx)
|
||||
{
|
||||
if (ctx->buf) {
|
||||
memset(ctx->buf, 0, ctx->key_length);
|
||||
free(ctx->buf);
|
||||
ctx->buf = NULL;
|
||||
}
|
||||
if (ctx->opad) {
|
||||
memset(ctx->opad, 0, EVP_MD_block_size(ctx->md));
|
||||
free(ctx->opad);
|
||||
ctx->opad = NULL;
|
||||
}
|
||||
if (ctx->ipad) {
|
||||
memset(ctx->ipad, 0, EVP_MD_block_size(ctx->md));
|
||||
free(ctx->ipad);
|
||||
ctx->ipad = NULL;
|
||||
}
|
||||
if (ctx->ctx) {
|
||||
EVP_MD_CTX_destroy(ctx->ctx);
|
||||
ctx->ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
HMAC_size(const HMAC_CTX *ctx)
|
||||
{
|
||||
return EVP_MD_size(ctx->md);
|
||||
}
|
||||
|
||||
void
|
||||
HMAC_Init_ex(HMAC_CTX *ctx,
|
||||
const void *key,
|
||||
size_t keylen,
|
||||
const EVP_MD *md,
|
||||
ENGINE *engine)
|
||||
{
|
||||
unsigned char *p;
|
||||
size_t i;
|
||||
|
||||
if (ctx->md != md) {
|
||||
ctx->md = md;
|
||||
if (ctx->buf) {
|
||||
memset(ctx->buf, 0, ctx->key_length);
|
||||
free (ctx->buf);
|
||||
}
|
||||
ctx->key_length = EVP_MD_size(ctx->md);
|
||||
ctx->buf = malloc(ctx->key_length);
|
||||
}
|
||||
#if 0
|
||||
ctx->engine = engine;
|
||||
#endif
|
||||
|
||||
if (keylen > EVP_MD_block_size(ctx->md)) {
|
||||
EVP_Digest(key, keylen, ctx->buf, NULL, ctx->md, engine);
|
||||
key = ctx->buf;
|
||||
keylen = EVP_MD_size(ctx->md);
|
||||
}
|
||||
|
||||
if (ctx->opad) {
|
||||
memset(ctx->opad, 0, ctx->key_length);
|
||||
free(ctx->opad);
|
||||
}
|
||||
if (ctx->ipad) {
|
||||
memset(ctx->ipad, 0, ctx->key_length);
|
||||
free(ctx->ipad);
|
||||
}
|
||||
|
||||
ctx->opad = malloc(EVP_MD_block_size(ctx->md));
|
||||
ctx->ipad = malloc(EVP_MD_block_size(ctx->md));
|
||||
memset(ctx->ipad, 0x36, EVP_MD_block_size(ctx->md));
|
||||
memset(ctx->opad, 0x5c, EVP_MD_block_size(ctx->md));
|
||||
|
||||
for (i = 0, p = ctx->ipad; i < keylen; i++)
|
||||
p[i] ^= ((const unsigned char *)key)[i];
|
||||
for (i = 0, p = ctx->opad; i < keylen; i++)
|
||||
p[i] ^= ((const unsigned char *)key)[i];
|
||||
|
||||
if (ctx->ctx == NULL)
|
||||
ctx->ctx = EVP_MD_CTX_create();
|
||||
|
||||
EVP_DigestInit_ex(ctx->ctx, ctx->md, ctx->engine);
|
||||
EVP_DigestUpdate(ctx->ctx, ctx->ipad, EVP_MD_block_size(ctx->md));
|
||||
}
|
||||
|
||||
void
|
||||
HMAC_Update(HMAC_CTX *ctx, const void *data, size_t len)
|
||||
{
|
||||
EVP_DigestUpdate(ctx->ctx, data, len);
|
||||
}
|
||||
|
||||
void
|
||||
HMAC_Final(HMAC_CTX *ctx, void *md, unsigned int *len)
|
||||
{
|
||||
EVP_DigestFinal_ex(ctx->ctx, ctx->buf, NULL);
|
||||
|
||||
EVP_DigestInit_ex(ctx->ctx, ctx->md, ctx->engine);
|
||||
EVP_DigestUpdate(ctx->ctx, ctx->opad, EVP_MD_block_size(ctx->md));
|
||||
EVP_DigestUpdate(ctx->ctx, ctx->buf, ctx->key_length);
|
||||
EVP_DigestFinal_ex(ctx->ctx, md, len);
|
||||
}
|
||||
|
||||
void *
|
||||
HMAC(const EVP_MD *md,
|
||||
const void *key, size_t key_size,
|
||||
const void *data, size_t data_size,
|
||||
void *hash, unsigned int *hash_len)
|
||||
{
|
||||
HMAC_CTX ctx;
|
||||
|
||||
HMAC_CTX_init(&ctx);
|
||||
HMAC_Init_ex(&ctx, key, key_size, md, NULL);
|
||||
HMAC_Update(&ctx, data, data_size);
|
||||
HMAC_Final(&ctx, hash, hash_len);
|
||||
HMAC_CTX_cleanup(&ctx);
|
||||
return hash;
|
||||
}
|
82
src/external/heimdal/hcrypto/hmac.h
vendored
Normal file
82
src/external/heimdal/hcrypto/hmac.h
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2005 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 HEIM_HMAC_H
|
||||
#define HEIM_HMAC_H 1
|
||||
|
||||
#include <hcrypto/evp.h>
|
||||
|
||||
/* symbol renaming */
|
||||
#define HMAC_CTX_init hc_HMAC_CTX_init
|
||||
#define HMAC_CTX_cleanup hc_HMAC_CTX_cleanup
|
||||
#define HMAC_size hc_HMAC_size
|
||||
#define HMAC_Init_ex hc_HMAC_Init_ex
|
||||
#define HMAC_Update hc_HMAC_Update
|
||||
#define HMAC_Final hc_HMAC_Final
|
||||
#define HMAC hc_HMAC
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#define HMAC_MAX_MD_CBLOCK 64
|
||||
|
||||
typedef struct hc_HMAC_CTX HMAC_CTX;
|
||||
|
||||
struct hc_HMAC_CTX {
|
||||
const EVP_MD *md;
|
||||
ENGINE *engine;
|
||||
EVP_MD_CTX *ctx;
|
||||
size_t key_length;
|
||||
void *opad;
|
||||
void *ipad;
|
||||
void *buf;
|
||||
};
|
||||
|
||||
|
||||
void HMAC_CTX_init(HMAC_CTX *);
|
||||
void HMAC_CTX_cleanup(HMAC_CTX *ctx);
|
||||
|
||||
size_t HMAC_size(const HMAC_CTX *ctx);
|
||||
|
||||
void HMAC_Init_ex(HMAC_CTX *, const void *, size_t,
|
||||
const EVP_MD *, ENGINE *);
|
||||
void HMAC_Update(HMAC_CTX *ctx, const void *data, size_t len);
|
||||
void HMAC_Final(HMAC_CTX *ctx, void *md, unsigned int *len);
|
||||
|
||||
void * HMAC(const EVP_MD *evp_md, const void *key, size_t key_len,
|
||||
const void *data, size_t n, void *md, unsigned int *md_len);
|
||||
|
||||
#endif /* HEIM_HMAC_H */
|
134
src/external/heimdal/hcrypto/md2.c
vendored
Normal file
134
src/external/heimdal/hcrypto/md2.c
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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 "md2.h"
|
||||
|
||||
static const unsigned char subst[256] = {
|
||||
41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6,
|
||||
19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188,
|
||||
76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24,
|
||||
138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251,
|
||||
245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63,
|
||||
148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50,
|
||||
39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165,
|
||||
181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210,
|
||||
150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157,
|
||||
112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27,
|
||||
96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
|
||||
85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197,
|
||||
234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65,
|
||||
129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123,
|
||||
8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233,
|
||||
203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228,
|
||||
166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237,
|
||||
31, 26, 219, 153, 141, 51, 159, 17, 131, 20
|
||||
};
|
||||
|
||||
void
|
||||
MD2_Init (struct md2 *m)
|
||||
{
|
||||
memset(m, 0, sizeof(*m));
|
||||
}
|
||||
|
||||
static void
|
||||
calc(struct md2 *m, const void *v)
|
||||
{
|
||||
unsigned char x[48], L;
|
||||
const unsigned char *p = v;
|
||||
int i, j, t;
|
||||
|
||||
L = m->checksum[15];
|
||||
for (i = 0; i < 16; i++)
|
||||
L = m->checksum[i] ^= subst[p[i] ^ L];
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
x[i] = m->state[i];
|
||||
x[i + 16] = p[i];
|
||||
x[i + 32] = x[i] ^ p[i];
|
||||
}
|
||||
|
||||
t = 0;
|
||||
for (i = 0; i < 18; i++) {
|
||||
for (j = 0; j < 48; j++)
|
||||
t = x[j] ^= subst[t];
|
||||
t = (t + i) & 0xff;
|
||||
}
|
||||
|
||||
memcpy(m->state, x, 16);
|
||||
memset(x, 0, sizeof(x));
|
||||
}
|
||||
|
||||
void
|
||||
MD2_Update (struct md2 *m, const void *v, size_t len)
|
||||
{
|
||||
size_t idx = m->len & 0xf;
|
||||
const unsigned char *p = v;
|
||||
|
||||
m->len += len;
|
||||
if (len + idx >= 16) {
|
||||
if (idx) {
|
||||
memcpy(m->data + idx, p, 16 - idx);
|
||||
calc(m, m->data);
|
||||
p += 16;
|
||||
len -= 16 - idx;
|
||||
}
|
||||
while (len >= 16) {
|
||||
calc(m, p);
|
||||
p += 16;
|
||||
len -= 16;
|
||||
}
|
||||
idx = 0;
|
||||
}
|
||||
|
||||
memcpy(m->data + idx, p, len);
|
||||
}
|
||||
|
||||
void
|
||||
MD2_Final (void *res, struct md2 *m)
|
||||
{
|
||||
unsigned char pad[16];
|
||||
size_t padlen;
|
||||
|
||||
padlen = 16 - (m->len % 16);
|
||||
memset(pad, padlen, padlen);
|
||||
|
||||
MD2_Update(m, pad, padlen);
|
||||
memcpy(pad, m->checksum, 16);
|
||||
MD2_Update(m, pad, 16);
|
||||
|
||||
memcpy(res, m->state, MD2_DIGEST_LENGTH);
|
||||
memset(m, 0, sizeof(m));
|
||||
}
|
63
src/external/heimdal/hcrypto/md2.h
vendored
Normal file
63
src/external/heimdal/hcrypto/md2.h
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef HEIM_MD2_H
|
||||
#define HEIM_MD2_H 1
|
||||
|
||||
/* symbol renaming */
|
||||
#define MD2_Init hc_MD2_Init
|
||||
#define MD2_Update hc_MD2_Update
|
||||
#define MD2_Final hc_MD2_Final
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#define MD2_DIGEST_LENGTH 16
|
||||
|
||||
struct md2 {
|
||||
size_t len;
|
||||
unsigned char data[16]; /* stored unalligned data between Update's */
|
||||
unsigned char checksum[16];
|
||||
unsigned char state[16]; /* lower 16 bytes of X */
|
||||
};
|
||||
|
||||
typedef struct md2 MD2_CTX;
|
||||
|
||||
void MD2_Init (struct md2 *m);
|
||||
void MD2_Update (struct md2 *m, const void *p, size_t len);
|
||||
void MD2_Final (void *res, struct md2 *m);
|
||||
|
||||
#endif /* HEIM_MD2_H */
|
246
src/external/heimdal/hcrypto/md4.c
vendored
Normal file
246
src/external/heimdal/hcrypto/md4.c
vendored
Normal file
@ -0,0 +1,246 @@
|
||||
/*
|
||||
* 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 "config.h"
|
||||
|
||||
#include "hash.h"
|
||||
#include "md4.h"
|
||||
|
||||
#define A m->counter[0]
|
||||
#define B m->counter[1]
|
||||
#define C m->counter[2]
|
||||
#define D m->counter[3]
|
||||
#define X data
|
||||
|
||||
void
|
||||
MD4_Init (struct md4 *m)
|
||||
{
|
||||
m->sz[0] = 0;
|
||||
m->sz[1] = 0;
|
||||
D = 0x10325476;
|
||||
C = 0x98badcfe;
|
||||
B = 0xefcdab89;
|
||||
A = 0x67452301;
|
||||
}
|
||||
|
||||
#define F(x,y,z) CRAYFIX((x & y) | (~x & z))
|
||||
#define G(x,y,z) ((x & y) | (x & z) | (y & z))
|
||||
#define H(x,y,z) (x ^ y ^ z)
|
||||
|
||||
#define DOIT(a,b,c,d,k,s,i,OP) \
|
||||
a = cshift(a + OP(b,c,d) + X[k] + i, s)
|
||||
|
||||
#define DO1(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,F)
|
||||
#define DO2(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,G)
|
||||
#define DO3(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,H)
|
||||
|
||||
static inline void
|
||||
calc (struct md4 *m, uint32_t *data)
|
||||
{
|
||||
uint32_t AA, BB, CC, DD;
|
||||
|
||||
AA = A;
|
||||
BB = B;
|
||||
CC = C;
|
||||
DD = D;
|
||||
|
||||
/* Round 1 */
|
||||
|
||||
DO1(A,B,C,D,0,3,0);
|
||||
DO1(D,A,B,C,1,7,0);
|
||||
DO1(C,D,A,B,2,11,0);
|
||||
DO1(B,C,D,A,3,19,0);
|
||||
|
||||
DO1(A,B,C,D,4,3,0);
|
||||
DO1(D,A,B,C,5,7,0);
|
||||
DO1(C,D,A,B,6,11,0);
|
||||
DO1(B,C,D,A,7,19,0);
|
||||
|
||||
DO1(A,B,C,D,8,3,0);
|
||||
DO1(D,A,B,C,9,7,0);
|
||||
DO1(C,D,A,B,10,11,0);
|
||||
DO1(B,C,D,A,11,19,0);
|
||||
|
||||
DO1(A,B,C,D,12,3,0);
|
||||
DO1(D,A,B,C,13,7,0);
|
||||
DO1(C,D,A,B,14,11,0);
|
||||
DO1(B,C,D,A,15,19,0);
|
||||
|
||||
/* Round 2 */
|
||||
|
||||
DO2(A,B,C,D,0,3,0x5A827999);
|
||||
DO2(D,A,B,C,4,5,0x5A827999);
|
||||
DO2(C,D,A,B,8,9,0x5A827999);
|
||||
DO2(B,C,D,A,12,13,0x5A827999);
|
||||
|
||||
DO2(A,B,C,D,1,3,0x5A827999);
|
||||
DO2(D,A,B,C,5,5,0x5A827999);
|
||||
DO2(C,D,A,B,9,9,0x5A827999);
|
||||
DO2(B,C,D,A,13,13,0x5A827999);
|
||||
|
||||
DO2(A,B,C,D,2,3,0x5A827999);
|
||||
DO2(D,A,B,C,6,5,0x5A827999);
|
||||
DO2(C,D,A,B,10,9,0x5A827999);
|
||||
DO2(B,C,D,A,14,13,0x5A827999);
|
||||
|
||||
DO2(A,B,C,D,3,3,0x5A827999);
|
||||
DO2(D,A,B,C,7,5,0x5A827999);
|
||||
DO2(C,D,A,B,11,9,0x5A827999);
|
||||
DO2(B,C,D,A,15,13,0x5A827999);
|
||||
|
||||
/* Round 3 */
|
||||
|
||||
DO3(A,B,C,D,0,3,0x6ED9EBA1);
|
||||
DO3(D,A,B,C,8,9,0x6ED9EBA1);
|
||||
DO3(C,D,A,B,4,11,0x6ED9EBA1);
|
||||
DO3(B,C,D,A,12,15,0x6ED9EBA1);
|
||||
|
||||
DO3(A,B,C,D,2,3,0x6ED9EBA1);
|
||||
DO3(D,A,B,C,10,9,0x6ED9EBA1);
|
||||
DO3(C,D,A,B,6,11,0x6ED9EBA1);
|
||||
DO3(B,C,D,A,14,15,0x6ED9EBA1);
|
||||
|
||||
DO3(A,B,C,D,1,3,0x6ED9EBA1);
|
||||
DO3(D,A,B,C,9,9,0x6ED9EBA1);
|
||||
DO3(C,D,A,B,5,11,0x6ED9EBA1);
|
||||
DO3(B,C,D,A,13,15,0x6ED9EBA1);
|
||||
|
||||
DO3(A,B,C,D,3,3,0x6ED9EBA1);
|
||||
DO3(D,A,B,C,11,9,0x6ED9EBA1);
|
||||
DO3(C,D,A,B,7,11,0x6ED9EBA1);
|
||||
DO3(B,C,D,A,15,15,0x6ED9EBA1);
|
||||
|
||||
A += AA;
|
||||
B += BB;
|
||||
C += CC;
|
||||
D += DD;
|
||||
}
|
||||
|
||||
/*
|
||||
* From `Performance analysis of MD5' by Joseph D. Touch <touch@isi.edu>
|
||||
*/
|
||||
|
||||
#if defined(WORDS_BIGENDIAN)
|
||||
static inline uint32_t
|
||||
swap_uint32_t (uint32_t t)
|
||||
{
|
||||
uint32_t temp1, temp2;
|
||||
|
||||
temp1 = cshift(t, 16);
|
||||
temp2 = temp1 >> 8;
|
||||
temp1 &= 0x00ff00ff;
|
||||
temp2 &= 0x00ff00ff;
|
||||
temp1 <<= 8;
|
||||
return temp1 | temp2;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct x32{
|
||||
unsigned int a:32;
|
||||
unsigned int b:32;
|
||||
};
|
||||
|
||||
void
|
||||
MD4_Update (struct md4 *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) % 64;
|
||||
while(len > 0) {
|
||||
size_t l = min(len, 64 - offset);
|
||||
memcpy(m->save + offset, p, l);
|
||||
offset += l;
|
||||
p += l;
|
||||
len -= l;
|
||||
if(offset == 64) {
|
||||
#if defined(WORDS_BIGENDIAN)
|
||||
int i;
|
||||
uint32_t current[16];
|
||||
struct x32 *u = (struct x32*)m->save;
|
||||
for(i = 0; i < 8; i++){
|
||||
current[2*i+0] = swap_uint32_t(u[i].a);
|
||||
current[2*i+1] = swap_uint32_t(u[i].b);
|
||||
}
|
||||
calc(m, current);
|
||||
#else
|
||||
calc(m, (uint32_t*)m->save);
|
||||
#endif
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MD4_Final (void *res, struct md4 *m)
|
||||
{
|
||||
unsigned char zeros[72];
|
||||
unsigned offset = (m->sz[0] / 8) % 64;
|
||||
unsigned int dstart = (120 - offset - 1) % 64 + 1;
|
||||
|
||||
*zeros = 0x80;
|
||||
memset (zeros + 1, 0, sizeof(zeros) - 1);
|
||||
zeros[dstart+0] = (m->sz[0] >> 0) & 0xff;
|
||||
zeros[dstart+1] = (m->sz[0] >> 8) & 0xff;
|
||||
zeros[dstart+2] = (m->sz[0] >> 16) & 0xff;
|
||||
zeros[dstart+3] = (m->sz[0] >> 24) & 0xff;
|
||||
zeros[dstart+4] = (m->sz[1] >> 0) & 0xff;
|
||||
zeros[dstart+5] = (m->sz[1] >> 8) & 0xff;
|
||||
zeros[dstart+6] = (m->sz[1] >> 16) & 0xff;
|
||||
zeros[dstart+7] = (m->sz[1] >> 24) & 0xff;
|
||||
MD4_Update (m, zeros, dstart + 8);
|
||||
{
|
||||
int i;
|
||||
unsigned char *r = (unsigned char *)res;
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
r[4*i] = m->counter[i] & 0xFF;
|
||||
r[4*i+1] = (m->counter[i] >> 8) & 0xFF;
|
||||
r[4*i+2] = (m->counter[i] >> 16) & 0xFF;
|
||||
r[4*i+3] = (m->counter[i] >> 24) & 0xFF;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
{
|
||||
int i;
|
||||
uint32_t *r = (uint32_t *)res;
|
||||
|
||||
for (i = 0; i < 4; ++i)
|
||||
r[i] = swap_uint32_t (m->counter[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
62
src/external/heimdal/hcrypto/md4.h
vendored
Normal file
62
src/external/heimdal/hcrypto/md4.h
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef HEIM_MD4_H
|
||||
#define HEIM_MD4_H 1
|
||||
|
||||
/* symbol renaming */
|
||||
#define MD4_Init hc_MD4_Init
|
||||
#define MD4_Update hc_MD4_Update
|
||||
#define MD4_Final hc_MD4_Final
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#define MD4_DIGEST_LENGTH 16
|
||||
|
||||
struct md4 {
|
||||
unsigned int sz[2];
|
||||
uint32_t counter[4];
|
||||
unsigned char save[64];
|
||||
};
|
||||
|
||||
typedef struct md4 MD4_CTX;
|
||||
|
||||
void MD4_Init (struct md4 *m);
|
||||
void MD4_Update (struct md4 *m, const void *p, size_t len);
|
||||
void MD4_Final (void *res, struct md4 *m);
|
||||
|
||||
#endif /* HEIM_MD4_H */
|
270
src/external/heimdal/hcrypto/md5.c
vendored
Normal file
270
src/external/heimdal/hcrypto/md5.c
vendored
Normal file
@ -0,0 +1,270 @@
|
||||
/*
|
||||
* 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 "config.h"
|
||||
|
||||
#include "hash.h"
|
||||
#include "md5.h"
|
||||
|
||||
#define A m->counter[0]
|
||||
#define B m->counter[1]
|
||||
#define C m->counter[2]
|
||||
#define D m->counter[3]
|
||||
#define X data
|
||||
|
||||
void
|
||||
MD5_Init (struct md5 *m)
|
||||
{
|
||||
m->sz[0] = 0;
|
||||
m->sz[1] = 0;
|
||||
D = 0x10325476;
|
||||
C = 0x98badcfe;
|
||||
B = 0xefcdab89;
|
||||
A = 0x67452301;
|
||||
}
|
||||
|
||||
#define F(x,y,z) CRAYFIX((x & y) | (~x & z))
|
||||
#define G(x,y,z) CRAYFIX((x & z) | (y & ~z))
|
||||
#define H(x,y,z) (x ^ y ^ z)
|
||||
#define I(x,y,z) CRAYFIX(y ^ (x | ~z))
|
||||
|
||||
#define DOIT(a,b,c,d,k,s,i,OP) \
|
||||
a = b + cshift(a + OP(b,c,d) + X[k] + (i), s)
|
||||
|
||||
#define DO1(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,F)
|
||||
#define DO2(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,G)
|
||||
#define DO3(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,H)
|
||||
#define DO4(a,b,c,d,k,s,i) DOIT(a,b,c,d,k,s,i,I)
|
||||
|
||||
static inline void
|
||||
calc (struct md5 *m, uint32_t *data)
|
||||
{
|
||||
uint32_t AA, BB, CC, DD;
|
||||
|
||||
AA = A;
|
||||
BB = B;
|
||||
CC = C;
|
||||
DD = D;
|
||||
|
||||
/* Round 1 */
|
||||
|
||||
DO1(A,B,C,D,0,7,0xd76aa478);
|
||||
DO1(D,A,B,C,1,12,0xe8c7b756);
|
||||
DO1(C,D,A,B,2,17,0x242070db);
|
||||
DO1(B,C,D,A,3,22,0xc1bdceee);
|
||||
|
||||
DO1(A,B,C,D,4,7,0xf57c0faf);
|
||||
DO1(D,A,B,C,5,12,0x4787c62a);
|
||||
DO1(C,D,A,B,6,17,0xa8304613);
|
||||
DO1(B,C,D,A,7,22,0xfd469501);
|
||||
|
||||
DO1(A,B,C,D,8,7,0x698098d8);
|
||||
DO1(D,A,B,C,9,12,0x8b44f7af);
|
||||
DO1(C,D,A,B,10,17,0xffff5bb1);
|
||||
DO1(B,C,D,A,11,22,0x895cd7be);
|
||||
|
||||
DO1(A,B,C,D,12,7,0x6b901122);
|
||||
DO1(D,A,B,C,13,12,0xfd987193);
|
||||
DO1(C,D,A,B,14,17,0xa679438e);
|
||||
DO1(B,C,D,A,15,22,0x49b40821);
|
||||
|
||||
/* Round 2 */
|
||||
|
||||
DO2(A,B,C,D,1,5,0xf61e2562);
|
||||
DO2(D,A,B,C,6,9,0xc040b340);
|
||||
DO2(C,D,A,B,11,14,0x265e5a51);
|
||||
DO2(B,C,D,A,0,20,0xe9b6c7aa);
|
||||
|
||||
DO2(A,B,C,D,5,5,0xd62f105d);
|
||||
DO2(D,A,B,C,10,9,0x2441453);
|
||||
DO2(C,D,A,B,15,14,0xd8a1e681);
|
||||
DO2(B,C,D,A,4,20,0xe7d3fbc8);
|
||||
|
||||
DO2(A,B,C,D,9,5,0x21e1cde6);
|
||||
DO2(D,A,B,C,14,9,0xc33707d6);
|
||||
DO2(C,D,A,B,3,14,0xf4d50d87);
|
||||
DO2(B,C,D,A,8,20,0x455a14ed);
|
||||
|
||||
DO2(A,B,C,D,13,5,0xa9e3e905);
|
||||
DO2(D,A,B,C,2,9,0xfcefa3f8);
|
||||
DO2(C,D,A,B,7,14,0x676f02d9);
|
||||
DO2(B,C,D,A,12,20,0x8d2a4c8a);
|
||||
|
||||
/* Round 3 */
|
||||
|
||||
DO3(A,B,C,D,5,4,0xfffa3942);
|
||||
DO3(D,A,B,C,8,11,0x8771f681);
|
||||
DO3(C,D,A,B,11,16,0x6d9d6122);
|
||||
DO3(B,C,D,A,14,23,0xfde5380c);
|
||||
|
||||
DO3(A,B,C,D,1,4,0xa4beea44);
|
||||
DO3(D,A,B,C,4,11,0x4bdecfa9);
|
||||
DO3(C,D,A,B,7,16,0xf6bb4b60);
|
||||
DO3(B,C,D,A,10,23,0xbebfbc70);
|
||||
|
||||
DO3(A,B,C,D,13,4,0x289b7ec6);
|
||||
DO3(D,A,B,C,0,11,0xeaa127fa);
|
||||
DO3(C,D,A,B,3,16,0xd4ef3085);
|
||||
DO3(B,C,D,A,6,23,0x4881d05);
|
||||
|
||||
DO3(A,B,C,D,9,4,0xd9d4d039);
|
||||
DO3(D,A,B,C,12,11,0xe6db99e5);
|
||||
DO3(C,D,A,B,15,16,0x1fa27cf8);
|
||||
DO3(B,C,D,A,2,23,0xc4ac5665);
|
||||
|
||||
/* Round 4 */
|
||||
|
||||
DO4(A,B,C,D,0,6,0xf4292244);
|
||||
DO4(D,A,B,C,7,10,0x432aff97);
|
||||
DO4(C,D,A,B,14,15,0xab9423a7);
|
||||
DO4(B,C,D,A,5,21,0xfc93a039);
|
||||
|
||||
DO4(A,B,C,D,12,6,0x655b59c3);
|
||||
DO4(D,A,B,C,3,10,0x8f0ccc92);
|
||||
DO4(C,D,A,B,10,15,0xffeff47d);
|
||||
DO4(B,C,D,A,1,21,0x85845dd1);
|
||||
|
||||
DO4(A,B,C,D,8,6,0x6fa87e4f);
|
||||
DO4(D,A,B,C,15,10,0xfe2ce6e0);
|
||||
DO4(C,D,A,B,6,15,0xa3014314);
|
||||
DO4(B,C,D,A,13,21,0x4e0811a1);
|
||||
|
||||
DO4(A,B,C,D,4,6,0xf7537e82);
|
||||
DO4(D,A,B,C,11,10,0xbd3af235);
|
||||
DO4(C,D,A,B,2,15,0x2ad7d2bb);
|
||||
DO4(B,C,D,A,9,21,0xeb86d391);
|
||||
|
||||
A += AA;
|
||||
B += BB;
|
||||
C += CC;
|
||||
D += DD;
|
||||
}
|
||||
|
||||
/*
|
||||
* From `Performance analysis of MD5' by Joseph D. Touch <touch@isi.edu>
|
||||
*/
|
||||
|
||||
#if defined(WORDS_BIGENDIAN)
|
||||
static inline uint32_t
|
||||
swap_uint32_t (uint32_t t)
|
||||
{
|
||||
uint32_t temp1, temp2;
|
||||
|
||||
temp1 = cshift(t, 16);
|
||||
temp2 = temp1 >> 8;
|
||||
temp1 &= 0x00ff00ff;
|
||||
temp2 &= 0x00ff00ff;
|
||||
temp1 <<= 8;
|
||||
return temp1 | temp2;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct x32{
|
||||
unsigned int a:32;
|
||||
unsigned int b:32;
|
||||
};
|
||||
|
||||
void
|
||||
MD5_Update (struct md5 *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) % 64;
|
||||
while(len > 0){
|
||||
size_t l = min(len, 64 - offset);
|
||||
memcpy(m->save + offset, p, l);
|
||||
offset += l;
|
||||
p += l;
|
||||
len -= l;
|
||||
if(offset == 64){
|
||||
#if defined(WORDS_BIGENDIAN)
|
||||
int i;
|
||||
uint32_t current[16];
|
||||
struct x32 *u = (struct x32*)m->save;
|
||||
for(i = 0; i < 8; i++){
|
||||
current[2*i+0] = swap_uint32_t(u[i].a);
|
||||
current[2*i+1] = swap_uint32_t(u[i].b);
|
||||
}
|
||||
calc(m, current);
|
||||
#else
|
||||
calc(m, (uint32_t*)m->save);
|
||||
#endif
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MD5_Final (void *res, struct md5 *m)
|
||||
{
|
||||
unsigned char zeros[72];
|
||||
unsigned offset = (m->sz[0] / 8) % 64;
|
||||
unsigned int dstart = (120 - offset - 1) % 64 + 1;
|
||||
|
||||
*zeros = 0x80;
|
||||
memset (zeros + 1, 0, sizeof(zeros) - 1);
|
||||
zeros[dstart+0] = (m->sz[0] >> 0) & 0xff;
|
||||
zeros[dstart+1] = (m->sz[0] >> 8) & 0xff;
|
||||
zeros[dstart+2] = (m->sz[0] >> 16) & 0xff;
|
||||
zeros[dstart+3] = (m->sz[0] >> 24) & 0xff;
|
||||
zeros[dstart+4] = (m->sz[1] >> 0) & 0xff;
|
||||
zeros[dstart+5] = (m->sz[1] >> 8) & 0xff;
|
||||
zeros[dstart+6] = (m->sz[1] >> 16) & 0xff;
|
||||
zeros[dstart+7] = (m->sz[1] >> 24) & 0xff;
|
||||
MD5_Update (m, zeros, dstart + 8);
|
||||
{
|
||||
int i;
|
||||
unsigned char *r = (unsigned char *)res;
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
r[4*i] = m->counter[i] & 0xFF;
|
||||
r[4*i+1] = (m->counter[i] >> 8) & 0xFF;
|
||||
r[4*i+2] = (m->counter[i] >> 16) & 0xFF;
|
||||
r[4*i+3] = (m->counter[i] >> 24) & 0xFF;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
{
|
||||
int i;
|
||||
uint32_t *r = (uint32_t *)res;
|
||||
|
||||
for (i = 0; i < 4; ++i)
|
||||
r[i] = swap_uint32_t (m->counter[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
62
src/external/heimdal/hcrypto/md5.h
vendored
Normal file
62
src/external/heimdal/hcrypto/md5.h
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef HEIM_MD5_H
|
||||
#define HEIM_MD5_H 1
|
||||
|
||||
/* symbol renaming */
|
||||
#define MD5_Init hc_MD5_Init
|
||||
#define MD5_Update hc_MD5_Update
|
||||
#define MD5_Final hc_MD5_Final
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#define MD5_DIGEST_LENGTH 16
|
||||
|
||||
struct md5 {
|
||||
unsigned int sz[2];
|
||||
uint32_t counter[4];
|
||||
unsigned char save[64];
|
||||
};
|
||||
|
||||
typedef struct md5 MD5_CTX;
|
||||
|
||||
void MD5_Init (struct md5 *m);
|
||||
void MD5_Update (struct md5 *m, const void *p, size_t len);
|
||||
void MD5_Final (void *res, struct md5 *m); /* uint32_t res[4] */
|
||||
|
||||
#endif /* HEIM_MD5_H */
|
128
src/external/heimdal/hcrypto/pkcs5.c
vendored
Normal file
128
src/external/heimdal/hcrypto/pkcs5.c
vendored
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
#ifdef KRB5
|
||||
#include <krb5-types.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <evp.h>
|
||||
#include <hmac.h>
|
||||
|
||||
#include <roken.h>
|
||||
|
||||
/**
|
||||
* As descriped in PKCS5, convert a password, salt, and iteration counter into a crypto key.
|
||||
*
|
||||
* @param password Password.
|
||||
* @param password_len Length of password.
|
||||
* @param salt Salt
|
||||
* @param salt_len Length of salt.
|
||||
* @param iter iteration counter.
|
||||
* @param keylen the output key length.
|
||||
* @param key the output key.
|
||||
*
|
||||
* @return 1 on success, non 1 on failure.
|
||||
*
|
||||
* @ingroup hcrypto_misc
|
||||
*/
|
||||
|
||||
int
|
||||
PKCS5_PBKDF2_HMAC_SHA1(const void * password, size_t password_len,
|
||||
const void * salt, size_t salt_len,
|
||||
unsigned long iter,
|
||||
size_t keylen, void *key)
|
||||
{
|
||||
size_t datalen, leftofkey, checksumsize;
|
||||
char *data, *tmpcksum;
|
||||
uint32_t keypart;
|
||||
const EVP_MD *md;
|
||||
unsigned long i;
|
||||
int j;
|
||||
char *p;
|
||||
unsigned int hmacsize;
|
||||
|
||||
md = EVP_sha1();
|
||||
checksumsize = EVP_MD_size(md);
|
||||
datalen = salt_len + 4;
|
||||
|
||||
tmpcksum = malloc(checksumsize + datalen);
|
||||
if (tmpcksum == NULL)
|
||||
return 0;
|
||||
|
||||
data = &tmpcksum[checksumsize];
|
||||
|
||||
memcpy(data, salt, salt_len);
|
||||
|
||||
keypart = 1;
|
||||
leftofkey = keylen;
|
||||
p = key;
|
||||
|
||||
while (leftofkey) {
|
||||
int len;
|
||||
|
||||
if (leftofkey > checksumsize)
|
||||
len = checksumsize;
|
||||
else
|
||||
len = leftofkey;
|
||||
|
||||
data[datalen - 4] = (keypart >> 24) & 0xff;
|
||||
data[datalen - 3] = (keypart >> 16) & 0xff;
|
||||
data[datalen - 2] = (keypart >> 8) & 0xff;
|
||||
data[datalen - 1] = (keypart) & 0xff;
|
||||
|
||||
HMAC(md, password, password_len, data, datalen,
|
||||
tmpcksum, &hmacsize);
|
||||
|
||||
memcpy(p, tmpcksum, len);
|
||||
for (i = 1; i < iter; i++) {
|
||||
HMAC(md, password, password_len, tmpcksum, checksumsize,
|
||||
tmpcksum, &hmacsize);
|
||||
|
||||
for (j = 0; j < len; j++)
|
||||
p[j] ^= tmpcksum[j];
|
||||
}
|
||||
|
||||
p += len;
|
||||
leftofkey -= len;
|
||||
keypart++;
|
||||
}
|
||||
|
||||
free(tmpcksum);
|
||||
|
||||
return 1;
|
||||
}
|
260
src/external/heimdal/hcrypto/rand-egd.c
vendored
Normal file
260
src/external/heimdal/hcrypto/rand-egd.c
vendored
Normal file
@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Copyright (c) 2007 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 <sys/types.h>
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
#include <sys/un.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
#include <rand.h>
|
||||
#include <randi.h>
|
||||
|
||||
#include <roken.h>
|
||||
|
||||
static const char *egd_path = "/var/run/egd-pool";
|
||||
|
||||
#define MAX_EGD_DATA 255
|
||||
|
||||
static int
|
||||
connect_egd(const char *path)
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
int fd;
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
|
||||
if (strlen(path) > sizeof(addr.sun_path))
|
||||
return -1;
|
||||
|
||||
addr.sun_family = AF_UNIX;
|
||||
strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
|
||||
|
||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
rk_cloexec(fd);
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int
|
||||
get_entropy(int fd, void *data, size_t len)
|
||||
{
|
||||
unsigned char msg[2];
|
||||
|
||||
assert(len <= MAX_EGD_DATA);
|
||||
|
||||
msg[0] = 0x02; /* read blocking data */
|
||||
msg[1] = len; /* wanted length */
|
||||
|
||||
if (net_write(fd, msg, sizeof(msg)) != sizeof(msg))
|
||||
return 0;
|
||||
|
||||
if (net_read(fd, data, len) != len)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
put_entropy(int fd, const void *data, size_t len)
|
||||
{
|
||||
unsigned char msg[4];
|
||||
|
||||
assert (len <= MAX_EGD_DATA);
|
||||
|
||||
msg[0] = 0x03; /* write data */
|
||||
msg[1] = 0; /* dummy */
|
||||
msg[2] = 0; /* entropy */
|
||||
msg[3] = len; /* length */
|
||||
|
||||
if (net_write(fd, msg, sizeof(msg)) != sizeof(msg))
|
||||
return 0;
|
||||
if (net_write(fd, data, len) != len)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static void
|
||||
egd_seed(const void *indata, int size)
|
||||
{
|
||||
size_t len;
|
||||
int fd, ret = 1;
|
||||
|
||||
fd = connect_egd(egd_path);
|
||||
if (fd < 0)
|
||||
return;
|
||||
|
||||
while(size) {
|
||||
len = size;
|
||||
if (len > MAX_EGD_DATA)
|
||||
len = MAX_EGD_DATA;
|
||||
ret = put_entropy(fd, indata, len);
|
||||
if (ret != 1)
|
||||
break;
|
||||
indata = ((unsigned char *)indata) + len;
|
||||
size -= len;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static int
|
||||
get_bytes(const char *path, unsigned char *outdata, int size)
|
||||
{
|
||||
size_t len;
|
||||
int fd, ret = 1;
|
||||
|
||||
if (path == NULL)
|
||||
path = egd_path;
|
||||
|
||||
fd = connect_egd(path);
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
|
||||
while(size) {
|
||||
len = size;
|
||||
if (len > MAX_EGD_DATA)
|
||||
len = MAX_EGD_DATA;
|
||||
ret = get_entropy(fd, outdata, len);
|
||||
if (ret != 1)
|
||||
break;
|
||||
outdata += len;
|
||||
size -= len;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
egd_bytes(unsigned char *outdata, int size)
|
||||
{
|
||||
return get_bytes(NULL, outdata, size);
|
||||
}
|
||||
|
||||
static void
|
||||
egd_cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
egd_add(const void *indata, int size, double entropi)
|
||||
{
|
||||
egd_seed(indata, size);
|
||||
}
|
||||
|
||||
static int
|
||||
egd_pseudorand(unsigned char *outdata, int size)
|
||||
{
|
||||
return get_bytes(NULL, outdata, size);
|
||||
}
|
||||
|
||||
static int
|
||||
egd_status(void)
|
||||
{
|
||||
int fd;
|
||||
fd = connect_egd(egd_path);
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const RAND_METHOD hc_rand_egd_method = {
|
||||
egd_seed,
|
||||
egd_bytes,
|
||||
egd_cleanup,
|
||||
egd_add,
|
||||
egd_pseudorand,
|
||||
egd_status
|
||||
};
|
||||
|
||||
const RAND_METHOD *
|
||||
RAND_egd_method(void)
|
||||
{
|
||||
return &hc_rand_egd_method;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
RAND_egd(const char *filename)
|
||||
{
|
||||
return RAND_egd_bytes(filename, 128);
|
||||
}
|
||||
|
||||
int
|
||||
RAND_egd_bytes(const char *filename, int size)
|
||||
{
|
||||
void *data;
|
||||
int ret;
|
||||
|
||||
if (size <= 0)
|
||||
return 0;
|
||||
|
||||
data = malloc(size);
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
|
||||
ret = get_bytes(filename, data, size);
|
||||
if (ret != 1) {
|
||||
free(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
RAND_seed(data, size);
|
||||
|
||||
memset(data, 0, size);
|
||||
free(data);
|
||||
|
||||
return 1;
|
||||
}
|
655
src/external/heimdal/hcrypto/rand-fortuna.c
vendored
Normal file
655
src/external/heimdal/hcrypto/rand-fortuna.c
vendored
Normal file
@ -0,0 +1,655 @@
|
||||
/*
|
||||
* fortuna.c
|
||||
* Fortuna-like PRNG.
|
||||
*
|
||||
* Copyright (c) 2005 Marko Kreen
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.c,v 1.8 2006/10/04 00:29:46 momjian Exp $
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <rand.h>
|
||||
#include <heim_threads.h>
|
||||
|
||||
#ifdef KRB5
|
||||
#include <krb5-types.h>
|
||||
#endif
|
||||
#include <roken.h>
|
||||
|
||||
#include "randi.h"
|
||||
#include "aes.h"
|
||||
#include "sha.h"
|
||||
|
||||
/*
|
||||
* Why Fortuna-like: There does not seem to be any definitive reference
|
||||
* on Fortuna in the net. Instead this implementation is based on
|
||||
* following references:
|
||||
*
|
||||
* http://en.wikipedia.org/wiki/Fortuna_(PRNG)
|
||||
* - Wikipedia article
|
||||
* http://jlcooke.ca/random/
|
||||
* - Jean-Luc Cooke Fortuna-based /dev/random driver for Linux.
|
||||
*/
|
||||
|
||||
/*
|
||||
* There is some confusion about whether and how to carry forward
|
||||
* the state of the pools. Seems like original Fortuna does not
|
||||
* do it, resetting hash after each request. I guess expecting
|
||||
* feeding to happen more often that requesting. This is absolutely
|
||||
* unsuitable for pgcrypto, as nothing asynchronous happens here.
|
||||
*
|
||||
* J.L. Cooke fixed this by feeding previous hash to new re-initialized
|
||||
* hash context.
|
||||
*
|
||||
* Fortuna predecessor Yarrow requires ability to query intermediate
|
||||
* 'final result' from hash, without affecting it.
|
||||
*
|
||||
* This implementation uses the Yarrow method - asking intermediate
|
||||
* results, but continuing with old state.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Algorithm parameters
|
||||
*/
|
||||
|
||||
#define NUM_POOLS 32
|
||||
|
||||
/* in microseconds */
|
||||
#define RESEED_INTERVAL 100000 /* 0.1 sec */
|
||||
|
||||
/* for one big request, reseed after this many bytes */
|
||||
#define RESEED_BYTES (1024*1024)
|
||||
|
||||
/*
|
||||
* Skip reseed if pool 0 has less than this many
|
||||
* bytes added since last reseed.
|
||||
*/
|
||||
#define POOL0_FILL (256/8)
|
||||
|
||||
/*
|
||||
* Algorithm constants
|
||||
*/
|
||||
|
||||
/* Both cipher key size and hash result size */
|
||||
#define BLOCK 32
|
||||
|
||||
/* cipher block size */
|
||||
#define CIPH_BLOCK 16
|
||||
|
||||
/* for internal wrappers */
|
||||
#define MD_CTX SHA256_CTX
|
||||
#define CIPH_CTX AES_KEY
|
||||
|
||||
struct fortuna_state
|
||||
{
|
||||
unsigned char counter[CIPH_BLOCK];
|
||||
unsigned char result[CIPH_BLOCK];
|
||||
unsigned char key[BLOCK];
|
||||
MD_CTX pool[NUM_POOLS];
|
||||
CIPH_CTX ciph;
|
||||
unsigned reseed_count;
|
||||
struct timeval last_reseed_time;
|
||||
unsigned pool0_bytes;
|
||||
unsigned rnd_pos;
|
||||
int tricks_done;
|
||||
pid_t pid;
|
||||
};
|
||||
typedef struct fortuna_state FState;
|
||||
|
||||
|
||||
/*
|
||||
* Use our own wrappers here.
|
||||
* - Need to get intermediate result from digest, without affecting it.
|
||||
* - Need re-set key on a cipher context.
|
||||
* - Algorithms are guaranteed to exist.
|
||||
* - No memory allocations.
|
||||
*/
|
||||
|
||||
static void
|
||||
ciph_init(CIPH_CTX * ctx, const unsigned char *key, int klen)
|
||||
{
|
||||
AES_set_encrypt_key(key, klen * 8, ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
ciph_encrypt(CIPH_CTX * ctx, const unsigned char *in, unsigned char *out)
|
||||
{
|
||||
AES_encrypt(in, out, ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
md_init(MD_CTX * ctx)
|
||||
{
|
||||
SHA256_Init(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
md_update(MD_CTX * ctx, const unsigned char *data, int len)
|
||||
{
|
||||
SHA256_Update(ctx, data, len);
|
||||
}
|
||||
|
||||
static void
|
||||
md_result(MD_CTX * ctx, unsigned char *dst)
|
||||
{
|
||||
SHA256_CTX tmp;
|
||||
|
||||
memcpy(&tmp, ctx, sizeof(*ctx));
|
||||
SHA256_Final(dst, &tmp);
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
}
|
||||
|
||||
/*
|
||||
* initialize state
|
||||
*/
|
||||
static void
|
||||
init_state(FState * st)
|
||||
{
|
||||
int i;
|
||||
|
||||
memset(st, 0, sizeof(*st));
|
||||
for (i = 0; i < NUM_POOLS; i++)
|
||||
md_init(&st->pool[i]);
|
||||
st->pid = getpid();
|
||||
}
|
||||
|
||||
/*
|
||||
* Endianess does not matter.
|
||||
* It just needs to change without repeating.
|
||||
*/
|
||||
static void
|
||||
inc_counter(FState * st)
|
||||
{
|
||||
uint32_t *val = (uint32_t *) st->counter;
|
||||
|
||||
if (++val[0])
|
||||
return;
|
||||
if (++val[1])
|
||||
return;
|
||||
if (++val[2])
|
||||
return;
|
||||
++val[3];
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called 'cipher in counter mode'.
|
||||
*/
|
||||
static void
|
||||
encrypt_counter(FState * st, unsigned char *dst)
|
||||
{
|
||||
ciph_encrypt(&st->ciph, st->counter, dst);
|
||||
inc_counter(st);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The time between reseed must be at least RESEED_INTERVAL
|
||||
* microseconds.
|
||||
*/
|
||||
static int
|
||||
enough_time_passed(FState * st)
|
||||
{
|
||||
int ok;
|
||||
struct timeval tv;
|
||||
struct timeval *last = &st->last_reseed_time;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
/* check how much time has passed */
|
||||
ok = 0;
|
||||
if (tv.tv_sec > last->tv_sec + 1)
|
||||
ok = 1;
|
||||
else if (tv.tv_sec == last->tv_sec + 1)
|
||||
{
|
||||
if (1000000 + tv.tv_usec - last->tv_usec >= RESEED_INTERVAL)
|
||||
ok = 1;
|
||||
}
|
||||
else if (tv.tv_usec - last->tv_usec >= RESEED_INTERVAL)
|
||||
ok = 1;
|
||||
|
||||
/* reseed will happen, update last_reseed_time */
|
||||
if (ok)
|
||||
memcpy(last, &tv, sizeof(tv));
|
||||
|
||||
memset(&tv, 0, sizeof(tv));
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* generate new key from all the pools
|
||||
*/
|
||||
static void
|
||||
reseed(FState * st)
|
||||
{
|
||||
unsigned k;
|
||||
unsigned n;
|
||||
MD_CTX key_md;
|
||||
unsigned char buf[BLOCK];
|
||||
|
||||
/* set pool as empty */
|
||||
st->pool0_bytes = 0;
|
||||
|
||||
/*
|
||||
* Both #0 and #1 reseed would use only pool 0. Just skip #0 then.
|
||||
*/
|
||||
n = ++st->reseed_count;
|
||||
|
||||
/*
|
||||
* The goal: use k-th pool only 1/(2^k) of the time.
|
||||
*/
|
||||
md_init(&key_md);
|
||||
for (k = 0; k < NUM_POOLS; k++)
|
||||
{
|
||||
md_result(&st->pool[k], buf);
|
||||
md_update(&key_md, buf, BLOCK);
|
||||
|
||||
if (n & 1 || !n)
|
||||
break;
|
||||
n >>= 1;
|
||||
}
|
||||
|
||||
/* add old key into mix too */
|
||||
md_update(&key_md, st->key, BLOCK);
|
||||
|
||||
/* add pid to make output diverse after fork() */
|
||||
md_update(&key_md, (const unsigned char *)&st->pid, sizeof(st->pid));
|
||||
|
||||
/* now we have new key */
|
||||
md_result(&key_md, st->key);
|
||||
|
||||
/* use new key */
|
||||
ciph_init(&st->ciph, st->key, BLOCK);
|
||||
|
||||
memset(&key_md, 0, sizeof(key_md));
|
||||
memset(buf, 0, BLOCK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pick a random pool. This uses key bytes as random source.
|
||||
*/
|
||||
static unsigned
|
||||
get_rand_pool(FState * st)
|
||||
{
|
||||
unsigned rnd;
|
||||
|
||||
/*
|
||||
* This slightly prefers lower pools - thats OK.
|
||||
*/
|
||||
rnd = st->key[st->rnd_pos] % NUM_POOLS;
|
||||
|
||||
st->rnd_pos++;
|
||||
if (st->rnd_pos >= BLOCK)
|
||||
st->rnd_pos = 0;
|
||||
|
||||
return rnd;
|
||||
}
|
||||
|
||||
/*
|
||||
* update pools
|
||||
*/
|
||||
static void
|
||||
add_entropy(FState * st, const unsigned char *data, unsigned len)
|
||||
{
|
||||
unsigned pos;
|
||||
unsigned char hash[BLOCK];
|
||||
MD_CTX md;
|
||||
|
||||
/* hash given data */
|
||||
md_init(&md);
|
||||
md_update(&md, data, len);
|
||||
md_result(&md, hash);
|
||||
|
||||
/*
|
||||
* Make sure the pool 0 is initialized, then update randomly.
|
||||
*/
|
||||
if (st->reseed_count == 0)
|
||||
pos = 0;
|
||||
else
|
||||
pos = get_rand_pool(st);
|
||||
md_update(&st->pool[pos], hash, BLOCK);
|
||||
|
||||
if (pos == 0)
|
||||
st->pool0_bytes += len;
|
||||
|
||||
memset(hash, 0, BLOCK);
|
||||
memset(&md, 0, sizeof(md));
|
||||
}
|
||||
|
||||
/*
|
||||
* Just take 2 next blocks as new key
|
||||
*/
|
||||
static void
|
||||
rekey(FState * st)
|
||||
{
|
||||
encrypt_counter(st, st->key);
|
||||
encrypt_counter(st, st->key + CIPH_BLOCK);
|
||||
ciph_init(&st->ciph, st->key, BLOCK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Hide public constants. (counter, pools > 0)
|
||||
*
|
||||
* This can also be viewed as spreading the startup
|
||||
* entropy over all of the components.
|
||||
*/
|
||||
static void
|
||||
startup_tricks(FState * st)
|
||||
{
|
||||
int i;
|
||||
unsigned char buf[BLOCK];
|
||||
|
||||
/* Use next block as counter. */
|
||||
encrypt_counter(st, st->counter);
|
||||
|
||||
/* Now shuffle pools, excluding #0 */
|
||||
for (i = 1; i < NUM_POOLS; i++)
|
||||
{
|
||||
encrypt_counter(st, buf);
|
||||
encrypt_counter(st, buf + CIPH_BLOCK);
|
||||
md_update(&st->pool[i], buf, BLOCK);
|
||||
}
|
||||
memset(buf, 0, BLOCK);
|
||||
|
||||
/* Hide the key. */
|
||||
rekey(st);
|
||||
|
||||
/* This can be done only once. */
|
||||
st->tricks_done = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
extract_data(FState * st, unsigned count, unsigned char *dst)
|
||||
{
|
||||
unsigned n;
|
||||
unsigned block_nr = 0;
|
||||
pid_t pid = getpid();
|
||||
|
||||
/* Should we reseed? */
|
||||
if (st->pool0_bytes >= POOL0_FILL || st->reseed_count == 0)
|
||||
if (enough_time_passed(st))
|
||||
reseed(st);
|
||||
|
||||
/* Do some randomization on first call */
|
||||
if (!st->tricks_done)
|
||||
startup_tricks(st);
|
||||
|
||||
/* If we forked, force a reseed again */
|
||||
if (pid != st->pid) {
|
||||
st->pid = pid;
|
||||
reseed(st);
|
||||
}
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
/* produce bytes */
|
||||
encrypt_counter(st, st->result);
|
||||
|
||||
/* copy result */
|
||||
if (count > CIPH_BLOCK)
|
||||
n = CIPH_BLOCK;
|
||||
else
|
||||
n = count;
|
||||
memcpy(dst, st->result, n);
|
||||
dst += n;
|
||||
count -= n;
|
||||
|
||||
/* must not give out too many bytes with one key */
|
||||
block_nr++;
|
||||
if (block_nr > (RESEED_BYTES / CIPH_BLOCK))
|
||||
{
|
||||
rekey(st);
|
||||
block_nr = 0;
|
||||
}
|
||||
}
|
||||
/* Set new key for next request. */
|
||||
rekey(st);
|
||||
}
|
||||
|
||||
/*
|
||||
* public interface
|
||||
*/
|
||||
|
||||
static FState main_state;
|
||||
static int init_done;
|
||||
static int have_entropy;
|
||||
#define FORTUNA_RESEED_BYTE 10000
|
||||
static unsigned resend_bytes;
|
||||
|
||||
/*
|
||||
* This mutex protects all of the above static elements from concurrent
|
||||
* access by multiple threads
|
||||
*/
|
||||
static HEIMDAL_MUTEX fortuna_mutex = HEIMDAL_MUTEX_INITIALIZER;
|
||||
|
||||
/*
|
||||
* Try our best to do an inital seed
|
||||
*/
|
||||
#define INIT_BYTES 128
|
||||
|
||||
/*
|
||||
* fortuna_mutex must be held across calls to this function
|
||||
*/
|
||||
|
||||
static int
|
||||
fortuna_reseed(void)
|
||||
{
|
||||
int entropy_p = 0;
|
||||
|
||||
if (!init_done)
|
||||
abort();
|
||||
|
||||
#ifndef NO_RAND_UNIX_METHOD
|
||||
{
|
||||
unsigned char buf[INIT_BYTES];
|
||||
if ((*hc_rand_unix_method.bytes)(buf, sizeof(buf)) == 1) {
|
||||
add_entropy(&main_state, buf, sizeof(buf));
|
||||
entropy_p = 1;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_ARC4RANDOM
|
||||
{
|
||||
uint32_t buf[INIT_BYTES / sizeof(uint32_t)];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(buf)/sizeof(buf[0]); i++)
|
||||
buf[i] = arc4random();
|
||||
add_entropy(&main_state, (void *)buf, sizeof(buf));
|
||||
entropy_p = 1;
|
||||
}
|
||||
#endif
|
||||
#ifndef NO_RAND_EGD_METHOD
|
||||
/*
|
||||
* Only to get egd entropy if /dev/random or arc4rand failed since
|
||||
* it can be horribly slow to generate new bits.
|
||||
*/
|
||||
if (!entropy_p) {
|
||||
unsigned char buf[INIT_BYTES];
|
||||
if ((*hc_rand_egd_method.bytes)(buf, sizeof(buf)) == 1) {
|
||||
add_entropy(&main_state, buf, sizeof(buf));
|
||||
entropy_p = 1;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Fall back to gattering data from timer and secret files, this
|
||||
* is really the last resort.
|
||||
*/
|
||||
if (!entropy_p) {
|
||||
/* to save stackspace */
|
||||
union {
|
||||
unsigned char buf[INIT_BYTES];
|
||||
unsigned char shad[1001];
|
||||
} u;
|
||||
int fd;
|
||||
|
||||
/* add timer info */
|
||||
if ((*hc_rand_timer_method.bytes)(u.buf, sizeof(u.buf)) == 1)
|
||||
add_entropy(&main_state, u.buf, sizeof(u.buf));
|
||||
/* add /etc/shadow */
|
||||
fd = open("/etc/shadow", O_RDONLY, 0);
|
||||
if (fd >= 0) {
|
||||
ssize_t n;
|
||||
rk_cloexec(fd);
|
||||
/* add_entropy will hash the buf */
|
||||
while ((n = read(fd, (char *)u.shad, sizeof(u.shad))) > 0)
|
||||
add_entropy(&main_state, u.shad, sizeof(u.shad));
|
||||
close(fd);
|
||||
}
|
||||
|
||||
memset(&u, 0, sizeof(u));
|
||||
|
||||
entropy_p = 1; /* sure about this ? */
|
||||
}
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
add_entropy(&main_state, (void *)&pid, sizeof(pid));
|
||||
}
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
add_entropy(&main_state, (void *)&tv, sizeof(tv));
|
||||
}
|
||||
#ifdef HAVE_GETUID
|
||||
{
|
||||
uid_t u = getuid();
|
||||
add_entropy(&main_state, (void *)&u, sizeof(u));
|
||||
}
|
||||
#endif
|
||||
return entropy_p;
|
||||
}
|
||||
|
||||
/*
|
||||
* fortuna_mutex must be held by callers of this function
|
||||
*/
|
||||
static int
|
||||
fortuna_init(void)
|
||||
{
|
||||
if (!init_done)
|
||||
{
|
||||
init_state(&main_state);
|
||||
init_done = 1;
|
||||
}
|
||||
if (!have_entropy)
|
||||
have_entropy = fortuna_reseed();
|
||||
return (init_done && have_entropy);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
fortuna_seed(const void *indata, int size)
|
||||
{
|
||||
HEIMDAL_MUTEX_lock(&fortuna_mutex);
|
||||
|
||||
fortuna_init();
|
||||
add_entropy(&main_state, indata, size);
|
||||
if (size >= INIT_BYTES)
|
||||
have_entropy = 1;
|
||||
|
||||
HEIMDAL_MUTEX_unlock(&fortuna_mutex);
|
||||
}
|
||||
|
||||
static int
|
||||
fortuna_bytes(unsigned char *outdata, int size)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
HEIMDAL_MUTEX_lock(&fortuna_mutex);
|
||||
|
||||
if (!fortuna_init())
|
||||
goto out;
|
||||
|
||||
resend_bytes += size;
|
||||
if (resend_bytes > FORTUNA_RESEED_BYTE || resend_bytes < size) {
|
||||
resend_bytes = 0;
|
||||
fortuna_reseed();
|
||||
}
|
||||
extract_data(&main_state, size, outdata);
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
HEIMDAL_MUTEX_unlock(&fortuna_mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
fortuna_cleanup(void)
|
||||
{
|
||||
HEIMDAL_MUTEX_lock(&fortuna_mutex);
|
||||
|
||||
init_done = 0;
|
||||
have_entropy = 0;
|
||||
memset(&main_state, 0, sizeof(main_state));
|
||||
|
||||
HEIMDAL_MUTEX_unlock(&fortuna_mutex);
|
||||
}
|
||||
|
||||
static void
|
||||
fortuna_add(const void *indata, int size, double entropi)
|
||||
{
|
||||
fortuna_seed(indata, size);
|
||||
}
|
||||
|
||||
static int
|
||||
fortuna_pseudorand(unsigned char *outdata, int size)
|
||||
{
|
||||
return fortuna_bytes(outdata, size);
|
||||
}
|
||||
|
||||
static int
|
||||
fortuna_status(void)
|
||||
{
|
||||
int result;
|
||||
|
||||
HEIMDAL_MUTEX_lock(&fortuna_mutex);
|
||||
result = fortuna_init();
|
||||
HEIMDAL_MUTEX_unlock(&fortuna_mutex);
|
||||
|
||||
return result ? 1 : 0;
|
||||
}
|
||||
|
||||
const RAND_METHOD hc_rand_fortuna_method = {
|
||||
fortuna_seed,
|
||||
fortuna_bytes,
|
||||
fortuna_cleanup,
|
||||
fortuna_add,
|
||||
fortuna_pseudorand,
|
||||
fortuna_status
|
||||
};
|
||||
|
||||
const RAND_METHOD *
|
||||
RAND_fortuna_method(void)
|
||||
{
|
||||
return &hc_rand_fortuna_method;
|
||||
}
|
202
src/external/heimdal/hcrypto/rand-timer.c
vendored
Normal file
202
src/external/heimdal/hcrypto/rand-timer.c
vendored
Normal file
@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 1996, 1997, 1999, 2007 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <rand.h>
|
||||
|
||||
#include <roken.h>
|
||||
|
||||
#include "randi.h"
|
||||
|
||||
#ifndef WIN32 /* don't bother with this on windows */
|
||||
|
||||
static volatile int counter;
|
||||
static volatile unsigned char *gdata; /* Global data */
|
||||
static volatile int igdata; /* Index into global data */
|
||||
static int gsize;
|
||||
|
||||
static
|
||||
RETSIGTYPE
|
||||
sigALRM(int sig)
|
||||
{
|
||||
if (igdata < gsize)
|
||||
gdata[igdata++] ^= counter & 0xff;
|
||||
|
||||
#ifndef HAVE_SIGACTION
|
||||
signal(SIGALRM, sigALRM); /* Reinstall SysV signal handler */
|
||||
#endif
|
||||
SIGRETURN(0);
|
||||
}
|
||||
|
||||
#ifndef HAVE_SETITIMER
|
||||
static void
|
||||
pacemaker(struct timeval *tv)
|
||||
{
|
||||
fd_set fds;
|
||||
pid_t pid;
|
||||
pid = getppid();
|
||||
while(1){
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(0, &fds);
|
||||
select(1, &fds, NULL, NULL, tv);
|
||||
kill(pid, SIGALRM);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
/* XXX ugly hack, should perhaps use function from roken */
|
||||
static RETSIGTYPE
|
||||
(*fake_signal(int sig, RETSIGTYPE (*f)(int)))(int)
|
||||
{
|
||||
struct sigaction sa, osa;
|
||||
sa.sa_handler = f;
|
||||
sa.sa_flags = 0;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sigaction(sig, &sa, &osa);
|
||||
return osa.sa_handler;
|
||||
}
|
||||
#define signal(S, F) fake_signal((S), (F))
|
||||
#endif
|
||||
|
||||
#endif /* WIN32*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static void
|
||||
timer_seed(const void *indata, int size)
|
||||
{
|
||||
}
|
||||
|
||||
static int
|
||||
timer_bytes(unsigned char *outdata, int size)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return 0;
|
||||
#else /* WIN32 */
|
||||
struct itimerval tv, otv;
|
||||
RETSIGTYPE (*osa)(int);
|
||||
int i, j;
|
||||
#ifndef HAVE_SETITIMER
|
||||
RETSIGTYPE (*ochld)(int);
|
||||
pid_t pid;
|
||||
#endif
|
||||
|
||||
gdata = outdata;
|
||||
gsize = size;
|
||||
igdata = 0;
|
||||
|
||||
osa = signal(SIGALRM, sigALRM);
|
||||
|
||||
/* Start timer */
|
||||
tv.it_value.tv_sec = 0;
|
||||
tv.it_value.tv_usec = 10 * 1000; /* 10 ms */
|
||||
tv.it_interval = tv.it_value;
|
||||
#ifdef HAVE_SETITIMER
|
||||
setitimer(ITIMER_REAL, &tv, &otv);
|
||||
#else
|
||||
ochld = signal(SIGCHLD, SIG_IGN);
|
||||
pid = fork();
|
||||
if(pid == -1){
|
||||
signal(SIGCHLD, ochld != SIG_ERR ? ochld : SIG_DFL);
|
||||
des_not_rand_data(data, size);
|
||||
return;
|
||||
}
|
||||
if(pid == 0)
|
||||
pacemaker(&tv.it_interval);
|
||||
#endif
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
for (igdata = 0; igdata < size;) /* igdata++ in sigALRM */
|
||||
counter++;
|
||||
for (j = 0; j < size; j++) /* Only use 2 bits each lap */
|
||||
gdata[j] = (gdata[j]>>2) | (gdata[j]<<6);
|
||||
}
|
||||
#ifdef HAVE_SETITIMER
|
||||
setitimer(ITIMER_REAL, &otv, 0);
|
||||
#else
|
||||
kill(pid, SIGKILL);
|
||||
while(waitpid(pid, NULL, 0) != pid);
|
||||
signal(SIGCHLD, ochld != SIG_ERR ? ochld : SIG_DFL);
|
||||
#endif
|
||||
signal(SIGALRM, osa != SIG_ERR ? osa : SIG_DFL);
|
||||
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
timer_cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
timer_add(const void *indata, int size, double entropi)
|
||||
{
|
||||
}
|
||||
|
||||
static int
|
||||
timer_pseudorand(unsigned char *outdata, int size)
|
||||
{
|
||||
return timer_bytes(outdata, size);
|
||||
}
|
||||
|
||||
static int
|
||||
timer_status(void)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return 0;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
const RAND_METHOD hc_rand_timer_method = {
|
||||
timer_seed,
|
||||
timer_bytes,
|
||||
timer_cleanup,
|
||||
timer_add,
|
||||
timer_pseudorand,
|
||||
timer_status
|
||||
};
|
||||
|
||||
const RAND_METHOD *
|
||||
RAND_timer_method(void)
|
||||
{
|
||||
return &hc_rand_timer_method;
|
||||
}
|
165
src/external/heimdal/hcrypto/rand-unix.c
vendored
Normal file
165
src/external/heimdal/hcrypto/rand-unix.c
vendored
Normal file
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <rand.h>
|
||||
#include <heim_threads.h>
|
||||
|
||||
#include <roken.h>
|
||||
|
||||
#include "randi.h"
|
||||
|
||||
/*
|
||||
* Unix /dev/random
|
||||
*/
|
||||
|
||||
int
|
||||
_hc_unix_device_fd(int flags, const char **fn)
|
||||
{
|
||||
static const char *rnd_devices[] = {
|
||||
"/dev/urandom",
|
||||
"/dev/random",
|
||||
"/dev/srandom",
|
||||
"/dev/arandom",
|
||||
NULL
|
||||
};
|
||||
const char **p;
|
||||
|
||||
for(p = rnd_devices; *p; p++) {
|
||||
int fd = open(*p, flags | O_NDELAY);
|
||||
if(fd >= 0) {
|
||||
if (fn)
|
||||
*fn = *p;
|
||||
rk_cloexec(fd);
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
unix_seed(const void *indata, int size)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (size <= 0)
|
||||
return;
|
||||
|
||||
fd = _hc_unix_device_fd(O_WRONLY, NULL);
|
||||
if (fd < 0)
|
||||
return;
|
||||
|
||||
write(fd, indata, size);
|
||||
close(fd);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
unix_bytes(unsigned char *outdata, int size)
|
||||
{
|
||||
ssize_t count;
|
||||
int fd;
|
||||
|
||||
if (size < 0)
|
||||
return 0;
|
||||
else if (size == 0)
|
||||
return 1;
|
||||
|
||||
fd = _hc_unix_device_fd(O_RDONLY, NULL);
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
|
||||
while (size > 0) {
|
||||
count = read(fd, outdata, size);
|
||||
if (count < 0 && errno == EINTR)
|
||||
continue;
|
||||
else if (count <= 0) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
outdata += count;
|
||||
size -= count;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
unix_cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
unix_add(const void *indata, int size, double entropi)
|
||||
{
|
||||
unix_seed(indata, size);
|
||||
}
|
||||
|
||||
static int
|
||||
unix_pseudorand(unsigned char *outdata, int size)
|
||||
{
|
||||
return unix_bytes(outdata, size);
|
||||
}
|
||||
|
||||
static int
|
||||
unix_status(void)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = _hc_unix_device_fd(O_RDONLY, NULL);
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
close(fd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
const RAND_METHOD hc_rand_unix_method = {
|
||||
unix_seed,
|
||||
unix_bytes,
|
||||
unix_cleanup,
|
||||
unix_add,
|
||||
unix_pseudorand,
|
||||
unix_status
|
||||
};
|
||||
|
||||
const RAND_METHOD *
|
||||
RAND_unix_method(void)
|
||||
{
|
||||
return &hc_rand_unix_method;
|
||||
}
|
383
src/external/heimdal/hcrypto/rand.c
vendored
Normal file
383
src/external/heimdal/hcrypto/rand.c
vendored
Normal file
@ -0,0 +1,383 @@
|
||||
/*
|
||||
* Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Portions Copyright (c) 2009 Apple Inc. 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <rand.h>
|
||||
#include <randi.h>
|
||||
|
||||
#include <roken.h>
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @page page_rand RAND - random number
|
||||
*
|
||||
* See the library functions here: @ref hcrypto_rand
|
||||
*/
|
||||
|
||||
const static RAND_METHOD *selected_meth = NULL;
|
||||
static ENGINE *selected_engine = NULL;
|
||||
|
||||
static void
|
||||
init_method(void)
|
||||
{
|
||||
if (selected_meth != NULL)
|
||||
return;
|
||||
#if defined(_WIN32)
|
||||
selected_meth = &hc_rand_w32crypto_method;
|
||||
#elif defined(__APPLE__)
|
||||
selected_meth = &hc_rand_unix_method;
|
||||
#else
|
||||
selected_meth = &hc_rand_fortuna_method;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed that random number generator. Secret material can securely be
|
||||
* feed into the function, they will never be returned.
|
||||
*
|
||||
* @param indata seed data
|
||||
* @param size length seed data
|
||||
*
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
|
||||
void
|
||||
RAND_seed(const void *indata, size_t size)
|
||||
{
|
||||
init_method();
|
||||
(*selected_meth->seed)(indata, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random block from the random generator, can be used for key material.
|
||||
*
|
||||
* @param outdata random data
|
||||
* @param size length random data
|
||||
*
|
||||
* @return 1 on success, 0 on failure.
|
||||
*
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
int
|
||||
RAND_bytes(void *outdata, size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
return 1;
|
||||
init_method();
|
||||
return (*selected_meth->bytes)(outdata, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset and free memory used by the random generator.
|
||||
*
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
|
||||
void
|
||||
RAND_cleanup(void)
|
||||
{
|
||||
const RAND_METHOD *meth = selected_meth;
|
||||
ENGINE *engine = selected_engine;
|
||||
|
||||
selected_meth = NULL;
|
||||
selected_engine = NULL;
|
||||
|
||||
if (meth)
|
||||
(*meth->cleanup)();
|
||||
if (engine)
|
||||
ENGINE_finish(engine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed that random number generator. Secret material can securely be
|
||||
* feed into the function, they will never be returned.
|
||||
*
|
||||
* @param indata the input data.
|
||||
* @param size size of in data.
|
||||
* @param entropi entropi in data.
|
||||
*
|
||||
*
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
|
||||
void
|
||||
RAND_add(const void *indata, size_t size, double entropi)
|
||||
{
|
||||
init_method();
|
||||
(*selected_meth->add)(indata, size, entropi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random block from the random generator, should NOT be used for key material.
|
||||
*
|
||||
* @param outdata random data
|
||||
* @param size length random data
|
||||
*
|
||||
* @return 1 on success, 0 on failure.
|
||||
*
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
|
||||
int
|
||||
RAND_pseudo_bytes(void *outdata, size_t size)
|
||||
{
|
||||
init_method();
|
||||
return (*selected_meth->pseudorand)(outdata, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return status of the random generator
|
||||
*
|
||||
* @return 1 if the random generator can deliver random data.
|
||||
*
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
|
||||
int
|
||||
RAND_status(void)
|
||||
{
|
||||
init_method();
|
||||
return (*selected_meth->status)();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default random method.
|
||||
*
|
||||
* @param meth set the new default method.
|
||||
*
|
||||
* @return 1 on success.
|
||||
*
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
|
||||
int
|
||||
RAND_set_rand_method(const RAND_METHOD *meth)
|
||||
{
|
||||
const RAND_METHOD *old = selected_meth;
|
||||
selected_meth = meth;
|
||||
if (old)
|
||||
(*old->cleanup)();
|
||||
if (selected_engine) {
|
||||
ENGINE_finish(selected_engine);
|
||||
selected_engine = NULL;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default random method.
|
||||
*
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
|
||||
const RAND_METHOD *
|
||||
RAND_get_rand_method(void)
|
||||
{
|
||||
init_method();
|
||||
return selected_meth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default random method from engine.
|
||||
*
|
||||
* @param engine use engine, if NULL is passed it, old method and engine is cleared.
|
||||
*
|
||||
* @return 1 on success, 0 on failure.
|
||||
*
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
|
||||
int
|
||||
RAND_set_rand_engine(ENGINE *engine)
|
||||
{
|
||||
const RAND_METHOD *meth, *old = selected_meth;
|
||||
|
||||
if (engine) {
|
||||
ENGINE_up_ref(engine);
|
||||
meth = ENGINE_get_RAND(engine);
|
||||
if (meth == NULL) {
|
||||
ENGINE_finish(engine);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
meth = NULL;
|
||||
}
|
||||
|
||||
if (old)
|
||||
(*old->cleanup)();
|
||||
|
||||
if (selected_engine)
|
||||
ENGINE_finish(selected_engine);
|
||||
|
||||
selected_engine = engine;
|
||||
selected_meth = meth;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define RAND_FILE_SIZE 1024
|
||||
|
||||
/**
|
||||
* Load a a file and feed it into RAND_seed().
|
||||
*
|
||||
* @param filename name of file to read.
|
||||
* @param size minimum size to read.
|
||||
*
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
|
||||
int
|
||||
RAND_load_file(const char *filename, size_t size)
|
||||
{
|
||||
unsigned char buf[128];
|
||||
size_t len;
|
||||
ssize_t slen;
|
||||
int fd;
|
||||
|
||||
fd = open(filename, O_RDONLY | O_BINARY, 0600);
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
rk_cloexec(fd);
|
||||
len = 0;
|
||||
while(len < size) {
|
||||
slen = read(fd, buf, sizeof(buf));
|
||||
if (slen <= 0)
|
||||
break;
|
||||
RAND_seed(buf, slen);
|
||||
len += slen;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return len ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write of random numbers to a file to store for later initiation with RAND_load_file().
|
||||
*
|
||||
* @param filename name of file to write.
|
||||
*
|
||||
* @return 1 on success and non-one on failure.
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
|
||||
int
|
||||
RAND_write_file(const char *filename)
|
||||
{
|
||||
unsigned char buf[128];
|
||||
size_t len;
|
||||
int res = 0, fd;
|
||||
|
||||
fd = open(filename, O_WRONLY | O_CREAT | O_BINARY, 0600);
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
rk_cloexec(fd);
|
||||
|
||||
len = 0;
|
||||
while(len < RAND_FILE_SIZE) {
|
||||
res = RAND_bytes(buf, sizeof(buf));
|
||||
if (res != 1)
|
||||
break;
|
||||
if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
|
||||
res = 0;
|
||||
break;
|
||||
}
|
||||
len += sizeof(buf);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default random state filename for a user to use for
|
||||
* RAND_load_file(), and RAND_write_file().
|
||||
*
|
||||
* @param filename buffer to hold file name.
|
||||
* @param size size of buffer filename.
|
||||
*
|
||||
* @return the buffer filename or NULL on failure.
|
||||
*
|
||||
* @ingroup hcrypto_rand
|
||||
*/
|
||||
|
||||
const char *
|
||||
RAND_file_name(char *filename, size_t size)
|
||||
{
|
||||
const char *e = NULL;
|
||||
int pathp = 0, ret;
|
||||
|
||||
if (!issuid()) {
|
||||
e = getenv("RANDFILE");
|
||||
if (e == NULL)
|
||||
e = getenv("HOME");
|
||||
if (e)
|
||||
pathp = 1;
|
||||
}
|
||||
/*
|
||||
* Here we really want to call getpwuid(getuid()) but this will
|
||||
* cause recursive lookups if the nss library uses
|
||||
* gssapi/krb5/hcrypto to authenticate to the ldap servers.
|
||||
*
|
||||
* So at least return the unix /dev/random if we have one
|
||||
*/
|
||||
#ifndef _WIN32
|
||||
if (e == NULL) {
|
||||
int fd;
|
||||
|
||||
fd = _hc_unix_device_fd(O_RDONLY, &e);
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
}
|
||||
#endif
|
||||
if (e == NULL)
|
||||
return NULL;
|
||||
|
||||
if (pathp)
|
||||
ret = snprintf(filename, size, "%s/.rnd", e);
|
||||
else
|
||||
ret = snprintf(filename, size, "%s", e);
|
||||
|
||||
if (ret <= 0 || ret >= size)
|
||||
return NULL;
|
||||
|
||||
return filename;
|
||||
}
|
108
src/external/heimdal/hcrypto/rand.h
vendored
Normal file
108
src/external/heimdal/hcrypto/rand.h
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef _HEIM_RAND_H
|
||||
#define _HEIM_RAND_H 1
|
||||
|
||||
typedef struct RAND_METHOD RAND_METHOD;
|
||||
|
||||
#include <hcrypto/engine.h>
|
||||
|
||||
/* symbol renaming */
|
||||
#define RAND_bytes hc_RAND_bytes
|
||||
#define RAND_pseudo_bytes hc_RAND_pseudo_bytes
|
||||
#define RAND_seed hc_RAND_seed
|
||||
#define RAND_cleanup hc_RAND_cleanup
|
||||
#define RAND_add hc_RAND_add
|
||||
#define RAND_set_rand_method hc_RAND_set_rand_method
|
||||
#define RAND_get_rand_method hc_RAND_get_rand_method
|
||||
#define RAND_set_rand_engine hc_RAND_set_rand_engine
|
||||
#define RAND_file_name hc_RAND_file_name
|
||||
#define RAND_load_file hc_RAND_load_file
|
||||
#define RAND_write_file hc_RAND_write_file
|
||||
#define RAND_status hc_RAND_status
|
||||
#define RAND_egd hc_RAND_egd
|
||||
#define RAND_egd_bytes hc_RAND_egd_bytes
|
||||
#define RAND_fortuna_method hc_RAND_fortuna_method
|
||||
#define RAND_egd_method hc_RAND_egd_method
|
||||
#define RAND_unix_method hc_RAND_unix_method
|
||||
#define RAND_w32crypto_method hc_RAND_w32crypto_method
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
struct RAND_METHOD
|
||||
{
|
||||
void (*seed)(const void *, int);
|
||||
int (*bytes)(unsigned char *, int);
|
||||
void (*cleanup)(void);
|
||||
void (*add)(const void *, int, double);
|
||||
int (*pseudorand)(unsigned char *, int);
|
||||
int (*status)(void);
|
||||
};
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
int RAND_bytes(void *, size_t num);
|
||||
int RAND_pseudo_bytes(void *, size_t);
|
||||
void RAND_seed(const void *, size_t);
|
||||
void RAND_cleanup(void);
|
||||
void RAND_add(const void *, size_t, double);
|
||||
|
||||
int RAND_set_rand_method(const RAND_METHOD *);
|
||||
const RAND_METHOD *
|
||||
RAND_get_rand_method(void);
|
||||
int RAND_set_rand_engine(ENGINE *);
|
||||
|
||||
const char *
|
||||
RAND_file_name(char *, size_t);
|
||||
int RAND_load_file(const char *, size_t);
|
||||
int RAND_write_file(const char *);
|
||||
int RAND_status(void);
|
||||
int RAND_egd(const char *);
|
||||
int RAND_egd_bytes(const char *, int);
|
||||
|
||||
|
||||
const RAND_METHOD * RAND_fortuna_method(void);
|
||||
const RAND_METHOD * RAND_unix_method(void);
|
||||
const RAND_METHOD * RAND_egd_method(void);
|
||||
|
||||
#endif /* _HEIM_RAND_H */
|
50
src/external/heimdal/hcrypto/randi.h
vendored
Normal file
50
src/external/heimdal/hcrypto/randi.h
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2007 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 _HEIM_RANDI_H
|
||||
#define _HEIM_RANDI_H 1
|
||||
|
||||
extern const RAND_METHOD hc_rand_fortuna_method;
|
||||
extern const RAND_METHOD hc_rand_unix_method;
|
||||
extern const RAND_METHOD hc_rand_egd_method;
|
||||
extern const RAND_METHOD hc_rand_timer_method;
|
||||
extern const RAND_METHOD hc_rand_w32crypto_method;
|
||||
|
||||
const RAND_METHOD * RAND_timer_method(void);
|
||||
int _hc_unix_device_fd(int, const char **);
|
||||
|
||||
#endif /* _HEIM_RANDI_H */
|
242
src/external/heimdal/hcrypto/rc2.c
vendored
Normal file
242
src/external/heimdal/hcrypto/rc2.c
vendored
Normal file
@ -0,0 +1,242 @@
|
||||
/*
|
||||
* Copyright (c) 2004 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 "rc2.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Implemented from Peter Gutmann's "Specification for Ron Rivests Cipher No.2"
|
||||
* rfc2268 and "On the Design and Security of RC2" was also useful.
|
||||
*/
|
||||
|
||||
static unsigned int Sbox[256] = {
|
||||
0xd9, 0x78, 0xf9, 0xc4, 0x19, 0xdd, 0xb5, 0xed,
|
||||
0x28, 0xe9, 0xfd, 0x79, 0x4a, 0xa0, 0xd8, 0x9d,
|
||||
0xc6, 0x7e, 0x37, 0x83, 0x2b, 0x76, 0x53, 0x8e,
|
||||
0x62, 0x4c, 0x64, 0x88, 0x44, 0x8b, 0xfb, 0xa2,
|
||||
0x17, 0x9a, 0x59, 0xf5, 0x87, 0xb3, 0x4f, 0x13,
|
||||
0x61, 0x45, 0x6d, 0x8d, 0x09, 0x81, 0x7d, 0x32,
|
||||
0xbd, 0x8f, 0x40, 0xeb, 0x86, 0xb7, 0x7b, 0x0b,
|
||||
0xf0, 0x95, 0x21, 0x22, 0x5c, 0x6b, 0x4e, 0x82,
|
||||
0x54, 0xd6, 0x65, 0x93, 0xce, 0x60, 0xb2, 0x1c,
|
||||
0x73, 0x56, 0xc0, 0x14, 0xa7, 0x8c, 0xf1, 0xdc,
|
||||
0x12, 0x75, 0xca, 0x1f, 0x3b, 0xbe, 0xe4, 0xd1,
|
||||
0x42, 0x3d, 0xd4, 0x30, 0xa3, 0x3c, 0xb6, 0x26,
|
||||
0x6f, 0xbf, 0x0e, 0xda, 0x46, 0x69, 0x07, 0x57,
|
||||
0x27, 0xf2, 0x1d, 0x9b, 0xbc, 0x94, 0x43, 0x03,
|
||||
0xf8, 0x11, 0xc7, 0xf6, 0x90, 0xef, 0x3e, 0xe7,
|
||||
0x06, 0xc3, 0xd5, 0x2f, 0xc8, 0x66, 0x1e, 0xd7,
|
||||
0x08, 0xe8, 0xea, 0xde, 0x80, 0x52, 0xee, 0xf7,
|
||||
0x84, 0xaa, 0x72, 0xac, 0x35, 0x4d, 0x6a, 0x2a,
|
||||
0x96, 0x1a, 0xd2, 0x71, 0x5a, 0x15, 0x49, 0x74,
|
||||
0x4b, 0x9f, 0xd0, 0x5e, 0x04, 0x18, 0xa4, 0xec,
|
||||
0xc2, 0xe0, 0x41, 0x6e, 0x0f, 0x51, 0xcb, 0xcc,
|
||||
0x24, 0x91, 0xaf, 0x50, 0xa1, 0xf4, 0x70, 0x39,
|
||||
0x99, 0x7c, 0x3a, 0x85, 0x23, 0xb8, 0xb4, 0x7a,
|
||||
0xfc, 0x02, 0x36, 0x5b, 0x25, 0x55, 0x97, 0x31,
|
||||
0x2d, 0x5d, 0xfa, 0x98, 0xe3, 0x8a, 0x92, 0xae,
|
||||
0x05, 0xdf, 0x29, 0x10, 0x67, 0x6c, 0xba, 0xc9,
|
||||
0xd3, 0x00, 0xe6, 0xcf, 0xe1, 0x9e, 0xa8, 0x2c,
|
||||
0x63, 0x16, 0x01, 0x3f, 0x58, 0xe2, 0x89, 0xa9,
|
||||
0x0d, 0x38, 0x34, 0x1b, 0xab, 0x33, 0xff, 0xb0,
|
||||
0xbb, 0x48, 0x0c, 0x5f, 0xb9, 0xb1, 0xcd, 0x2e,
|
||||
0xc5, 0xf3, 0xdb, 0x47, 0xe5, 0xa5, 0x9c, 0x77,
|
||||
0x0a, 0xa6, 0x20, 0x68, 0xfe, 0x7f, 0xc1, 0xad
|
||||
};
|
||||
|
||||
void
|
||||
RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
|
||||
{
|
||||
unsigned char k[128];
|
||||
int j, T8, TM;
|
||||
|
||||
if (len <= 0)
|
||||
abort();
|
||||
if (len > 128)
|
||||
len = 128;
|
||||
if (bits <= 0 || bits > 1024)
|
||||
bits = 1024;
|
||||
|
||||
for (j = 0; j < len; j++)
|
||||
k[j] = data[j];
|
||||
for (; j < 128; j++)
|
||||
k[j] = Sbox[(k[j - len] + k[j - 1]) & 0xff];
|
||||
|
||||
T8 = (bits + 7) / 8;
|
||||
j = (8*T8 - bits);
|
||||
TM = 0xff >> j;
|
||||
|
||||
k[128 - T8] = Sbox[k[128 - T8] & TM];
|
||||
|
||||
for (j = 127 - T8; j >= 0; j--)
|
||||
k[j] = Sbox[k[j + 1] ^ k[j + T8]];
|
||||
|
||||
for (j = 0; j < 64; j++)
|
||||
key->data[j] = k[(j * 2) + 0] | (k[(j * 2) + 1] << 8);
|
||||
memset(k, 0, sizeof(k));
|
||||
}
|
||||
|
||||
#define ROT16L(w,n) ((w<<n)|(w>>(16-n)))
|
||||
#define ROT16R(w,n) ((w>>n)|(w<<(16-n)))
|
||||
|
||||
void
|
||||
RC2_encryptc(unsigned char *in, unsigned char *out, const RC2_KEY *key)
|
||||
{
|
||||
int i, j;
|
||||
int w0, w1, w2, w3;
|
||||
int t0, t1, t2, t3;
|
||||
|
||||
w0 = in[0] | (in[1] << 8);
|
||||
w1 = in[2] | (in[3] << 8);
|
||||
w2 = in[4] | (in[5] << 8);
|
||||
w3 = in[6] | (in[7] << 8);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
j = i * 4;
|
||||
t0 = (w0 + (w1 & ~w3) + (w2 & w3) + key->data[j + 0]) & 0xffff;
|
||||
w0 = ROT16L(t0, 1);
|
||||
t1 = (w1 + (w2 & ~w0) + (w3 & w0) + key->data[j + 1]) & 0xffff;
|
||||
w1 = ROT16L(t1, 2);
|
||||
t2 = (w2 + (w3 & ~w1) + (w0 & w1) + key->data[j + 2]) & 0xffff;
|
||||
w2 = ROT16L(t2, 3);
|
||||
t3 = (w3 + (w0 & ~w2) + (w1 & w2) + key->data[j + 3]) & 0xffff;
|
||||
w3 = ROT16L(t3, 5);
|
||||
if(i == 4 || i == 10) {
|
||||
w0 += key->data[w3 & 63];
|
||||
w1 += key->data[w0 & 63];
|
||||
w2 += key->data[w1 & 63];
|
||||
w3 += key->data[w2 & 63];
|
||||
}
|
||||
}
|
||||
|
||||
out[0] = w0 & 0xff;
|
||||
out[1] = (w0 >> 8) & 0xff;
|
||||
out[2] = w1 & 0xff;
|
||||
out[3] = (w1 >> 8) & 0xff;
|
||||
out[4] = w2 & 0xff;
|
||||
out[5] = (w2 >> 8) & 0xff;
|
||||
out[6] = w3 & 0xff;
|
||||
out[7] = (w3 >> 8) & 0xff;
|
||||
}
|
||||
|
||||
void
|
||||
RC2_decryptc(unsigned char *in, unsigned char *out, const RC2_KEY *key)
|
||||
{
|
||||
int i, j;
|
||||
int w0, w1, w2, w3;
|
||||
int t0, t1, t2, t3;
|
||||
|
||||
w0 = in[0] | (in[1] << 8);
|
||||
w1 = in[2] | (in[3] << 8);
|
||||
w2 = in[4] | (in[5] << 8);
|
||||
w3 = in[6] | (in[7] << 8);
|
||||
|
||||
for (i = 15; i >= 0; i--) {
|
||||
j = i * 4;
|
||||
|
||||
if(i == 4 || i == 10) {
|
||||
w3 = (w3 - key->data[w2 & 63]) & 0xffff;
|
||||
w2 = (w2 - key->data[w1 & 63]) & 0xffff;
|
||||
w1 = (w1 - key->data[w0 & 63]) & 0xffff;
|
||||
w0 = (w0 - key->data[w3 & 63]) & 0xffff;
|
||||
}
|
||||
|
||||
t3 = ROT16R(w3, 5);
|
||||
w3 = (t3 - (w0 & ~w2) - (w1 & w2) - key->data[j + 3]) & 0xffff;
|
||||
t2 = ROT16R(w2, 3);
|
||||
w2 = (t2 - (w3 & ~w1) - (w0 & w1) - key->data[j + 2]) & 0xffff;
|
||||
t1 = ROT16R(w1, 2);
|
||||
w1 = (t1 - (w2 & ~w0) - (w3 & w0) - key->data[j + 1]) & 0xffff;
|
||||
t0 = ROT16R(w0, 1);
|
||||
w0 = (t0 - (w1 & ~w3) - (w2 & w3) - key->data[j + 0]) & 0xffff;
|
||||
|
||||
}
|
||||
out[0] = w0 & 0xff;
|
||||
out[1] = (w0 >> 8) & 0xff;
|
||||
out[2] = w1 & 0xff;
|
||||
out[3] = (w1 >> 8) & 0xff;
|
||||
out[4] = w2 & 0xff;
|
||||
out[5] = (w2 >> 8) & 0xff;
|
||||
out[6] = w3 & 0xff;
|
||||
out[7] = (w3 >> 8) & 0xff;
|
||||
}
|
||||
|
||||
void
|
||||
RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long size,
|
||||
RC2_KEY *key, unsigned char *iv, int forward_encrypt)
|
||||
{
|
||||
unsigned char tmp[RC2_BLOCK_SIZE];
|
||||
int i;
|
||||
|
||||
if (forward_encrypt) {
|
||||
while (size >= RC2_BLOCK_SIZE) {
|
||||
for (i = 0; i < RC2_BLOCK_SIZE; i++)
|
||||
tmp[i] = in[i] ^ iv[i];
|
||||
RC2_encryptc(tmp, out, key);
|
||||
memcpy(iv, out, RC2_BLOCK_SIZE);
|
||||
size -= RC2_BLOCK_SIZE;
|
||||
in += RC2_BLOCK_SIZE;
|
||||
out += RC2_BLOCK_SIZE;
|
||||
}
|
||||
if (size) {
|
||||
for (i = 0; i < size; i++)
|
||||
tmp[i] = in[i] ^ iv[i];
|
||||
for (i = size; i < RC2_BLOCK_SIZE; i++)
|
||||
tmp[i] = iv[i];
|
||||
RC2_encryptc(tmp, out, key);
|
||||
memcpy(iv, out, RC2_BLOCK_SIZE);
|
||||
}
|
||||
} else {
|
||||
while (size >= RC2_BLOCK_SIZE) {
|
||||
memcpy(tmp, in, RC2_BLOCK_SIZE);
|
||||
RC2_decryptc(tmp, out, key);
|
||||
for (i = 0; i < RC2_BLOCK_SIZE; i++)
|
||||
out[i] ^= iv[i];
|
||||
memcpy(iv, tmp, RC2_BLOCK_SIZE);
|
||||
size -= RC2_BLOCK_SIZE;
|
||||
in += RC2_BLOCK_SIZE;
|
||||
out += RC2_BLOCK_SIZE;
|
||||
}
|
||||
if (size) {
|
||||
memcpy(tmp, in, RC2_BLOCK_SIZE);
|
||||
RC2_decryptc(tmp, out, key);
|
||||
for (i = 0; i < size; i++)
|
||||
out[i] ^= iv[i];
|
||||
memcpy(iv, tmp, RC2_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
71
src/external/heimdal/hcrypto/rc2.h
vendored
Normal file
71
src/external/heimdal/hcrypto/rc2.h
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2004 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$ */
|
||||
|
||||
/* symbol renaming */
|
||||
#define RC2_set_key hc_RC2_set_key
|
||||
#define RC2_encryptc hc_RC2_encryptc
|
||||
#define RC2_decryptc hc_RC2_decryptc
|
||||
#define RC2_cbc_encrypt hc_RC2_cbc_encrypt
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#define RC2_ENCRYPT 1
|
||||
#define RC2_DECRYPT 0
|
||||
|
||||
#define RC2_BLOCK_SIZE 8
|
||||
#define RC2_BLOCK RC2_BLOCK_SIZE
|
||||
#define RC2_KEY_LENGTH 16
|
||||
|
||||
typedef struct rc2_key {
|
||||
unsigned int data[64];
|
||||
} RC2_KEY;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void RC2_set_key(RC2_KEY *, int, const unsigned char *,int);
|
||||
|
||||
void RC2_encryptc(unsigned char *, unsigned char *, const RC2_KEY *);
|
||||
void RC2_decryptc(unsigned char *, unsigned char *, const RC2_KEY *);
|
||||
|
||||
void RC2_cbc_encrypt(const unsigned char *, unsigned char *, long,
|
||||
RC2_KEY *, unsigned char *, int);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
78
src/external/heimdal/hcrypto/rc4.c
vendored
Normal file
78
src/external/heimdal/hcrypto/rc4.c
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2004 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.
|
||||
*/
|
||||
|
||||
/* implemented from description in draft-kaukonen-cipher-arcfour-03.txt */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <rc4.h>
|
||||
|
||||
#define SWAP(k,x,y) \
|
||||
{ unsigned int _t; \
|
||||
_t = k->state[x]; \
|
||||
k->state[x] = k->state[y]; \
|
||||
k->state[y] = _t; \
|
||||
}
|
||||
|
||||
void
|
||||
RC4_set_key(RC4_KEY *key, const int len, const unsigned char *data)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
key->state[i] = i;
|
||||
for (i = 0, j = 0; i < 256; i++) {
|
||||
j = (j + key->state[i] + data[i % len]) % 256;
|
||||
SWAP(key, i, j);
|
||||
}
|
||||
key->x = key->y = 0;
|
||||
}
|
||||
|
||||
void
|
||||
RC4(RC4_KEY *key, const int len, const unsigned char *in, unsigned char *out)
|
||||
{
|
||||
int i, t;
|
||||
unsigned x, y;
|
||||
|
||||
x = key->x;
|
||||
y = key->y;
|
||||
for (i = 0; i < len; i++) {
|
||||
x = (x + 1) % 256;
|
||||
y = (y + key->state[x]) % 256;
|
||||
SWAP(key, x, y);
|
||||
t = (key->state[x] + key->state[y]) % 256;
|
||||
*out++ = key->state[t] ^ *in++;
|
||||
}
|
||||
key->x = x;
|
||||
key->y = y;
|
||||
}
|
46
src/external/heimdal/hcrypto/rc4.h
vendored
Normal file
46
src/external/heimdal/hcrypto/rc4.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2004 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$ */
|
||||
|
||||
/* symbol renaming */
|
||||
#define RC4_set_key hc_RC4_set_key
|
||||
#define RC4 hc_RC4
|
||||
|
||||
typedef struct rc4_key {
|
||||
unsigned int x, y;
|
||||
unsigned int state[256];
|
||||
} RC4_KEY;
|
||||
|
||||
void RC4_set_key(RC4_KEY *, const int, const unsigned char *);
|
||||
void RC4(RC4_KEY *, const int, const unsigned char *, unsigned char *);
|
1229
src/external/heimdal/hcrypto/rijndael-alg-fst.c
vendored
Normal file
1229
src/external/heimdal/hcrypto/rijndael-alg-fst.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
46
src/external/heimdal/hcrypto/rijndael-alg-fst.h
vendored
Normal file
46
src/external/heimdal/hcrypto/rijndael-alg-fst.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/* $NetBSD: rijndael-alg-fst.h,v 1.2 2000/10/02 17:19:15 itojun Exp $ */
|
||||
/* $KAME: rijndael-alg-fst.h,v 1.5 2003/07/15 10:47:16 itojun Exp $ */
|
||||
/**
|
||||
* rijndael-alg-fst.h
|
||||
*
|
||||
* @version 3.0 (December 2000)
|
||||
*
|
||||
* Optimised ANSI C code for the Rijndael cipher (now AES)
|
||||
*
|
||||
* @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
|
||||
* @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
|
||||
* @author Paulo Barreto <paulo.barreto@terra.com.br>
|
||||
*
|
||||
* This code is hereby placed in the public domain.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''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 AUTHORS 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.
|
||||
*/
|
||||
#ifndef __RIJNDAEL_ALG_FST_H
|
||||
#define __RIJNDAEL_ALG_FST_H
|
||||
|
||||
/* symbol renaming */
|
||||
#define rijndaelKeySetupEnc _hc_rijndaelKeySetupEnc
|
||||
#define rijndaelKeySetupDec _hc_rijndaelKeySetupDec
|
||||
#define rijndaelEncrypt _hc_rijndaelEncrypt
|
||||
#define rijndaelDecrypt _hc_rijndaelDecrypt
|
||||
|
||||
#define RIJNDAEL_MAXKC (256/32)
|
||||
#define RIJNDAEL_MAXKB (256/8)
|
||||
#define RIJNDAEL_MAXNR 14
|
||||
|
||||
int rijndaelKeySetupEnc(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits);
|
||||
int rijndaelKeySetupDec(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits);
|
||||
void rijndaelEncrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t pt[16], uint8_t ct[16]);
|
||||
void rijndaelDecrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t ct[16], uint8_t pt[16]);
|
||||
|
||||
#endif /* __RIJNDAEL_ALG_FST_H */
|
139
src/external/heimdal/hcrypto/rnd_keys.c
vendored
Normal file
139
src/external/heimdal/hcrypto/rnd_keys.c
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 1996, 1997, 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 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"
|
||||
|
||||
|
||||
#define HC_DEPRECATED
|
||||
|
||||
#ifdef KRB5
|
||||
#include <krb5-types.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <des.h>
|
||||
#include <rand.h>
|
||||
|
||||
#undef __attribute__
|
||||
#define __attribute__(X)
|
||||
|
||||
void HC_DEPRECATED
|
||||
DES_rand_data(void *outdata, int size)
|
||||
{
|
||||
RAND_bytes(outdata, size);
|
||||
}
|
||||
|
||||
void HC_DEPRECATED
|
||||
DES_generate_random_block(DES_cblock *block)
|
||||
{
|
||||
RAND_bytes(block, sizeof(*block));
|
||||
}
|
||||
|
||||
#define DES_rand_data_key hc_DES_rand_data_key
|
||||
|
||||
void HC_DEPRECATED
|
||||
DES_rand_data_key(DES_cblock *key);
|
||||
|
||||
/*
|
||||
* Generate a random DES key.
|
||||
*/
|
||||
|
||||
void HC_DEPRECATED
|
||||
DES_rand_data_key(DES_cblock *key)
|
||||
{
|
||||
DES_new_random_key(key);
|
||||
}
|
||||
|
||||
void HC_DEPRECATED
|
||||
DES_set_sequence_number(void *ll)
|
||||
{
|
||||
}
|
||||
|
||||
void HC_DEPRECATED
|
||||
DES_set_random_generator_seed(DES_cblock *seed)
|
||||
{
|
||||
RAND_seed(seed, sizeof(*seed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random des key using a random block, fixup parity and
|
||||
* skip weak keys.
|
||||
*
|
||||
* @param key is set to a random key.
|
||||
*
|
||||
* @return 0 on success, non zero on random number generator failure.
|
||||
*
|
||||
* @ingroup hcrypto_des
|
||||
*/
|
||||
|
||||
int HC_DEPRECATED
|
||||
DES_new_random_key(DES_cblock *key)
|
||||
{
|
||||
do {
|
||||
if (RAND_bytes(key, sizeof(*key)) != 1)
|
||||
return 1;
|
||||
DES_set_odd_parity(key);
|
||||
} while(DES_is_weak_key(key));
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed the random number generator. Deprecated, use @ref page_rand
|
||||
*
|
||||
* @param seed a seed to seed that random number generate with.
|
||||
*
|
||||
* @ingroup hcrypto_des
|
||||
*/
|
||||
|
||||
void HC_DEPRECATED
|
||||
DES_init_random_number_generator(DES_cblock *seed)
|
||||
{
|
||||
RAND_seed(seed, sizeof(*seed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random key, deprecated since it doesn't return an error
|
||||
* code, use DES_new_random_key().
|
||||
*
|
||||
* @param key is set to a random key.
|
||||
*
|
||||
* @ingroup hcrypto_des
|
||||
*/
|
||||
|
||||
void HC_DEPRECATED
|
||||
DES_random_key(DES_cblock *key)
|
||||
{
|
||||
if (DES_new_random_key(key))
|
||||
abort();
|
||||
}
|
296
src/external/heimdal/hcrypto/sha.c
vendored
Normal file
296
src/external/heimdal/hcrypto/sha.c
vendored
Normal file
@ -0,0 +1,296 @@
|
||||
/*
|
||||
* 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 "config.h"
|
||||
|
||||
#include "hash.h"
|
||||
#include "sha.h"
|
||||
|
||||
#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 X data
|
||||
|
||||
void
|
||||
SHA1_Init (struct sha *m)
|
||||
{
|
||||
m->sz[0] = 0;
|
||||
m->sz[1] = 0;
|
||||
A = 0x67452301;
|
||||
B = 0xefcdab89;
|
||||
C = 0x98badcfe;
|
||||
D = 0x10325476;
|
||||
E = 0xc3d2e1f0;
|
||||
}
|
||||
|
||||
|
||||
#define F0(x,y,z) CRAYFIX((x & y) | (~x & z))
|
||||
#define F1(x,y,z) (x ^ y ^ z)
|
||||
#define F2(x,y,z) ((x & y) | (x & z) | (y & z))
|
||||
#define F3(x,y,z) F1(x,y,z)
|
||||
|
||||
#define K0 0x5a827999
|
||||
#define K1 0x6ed9eba1
|
||||
#define K2 0x8f1bbcdc
|
||||
#define K3 0xca62c1d6
|
||||
|
||||
#define DO(t,f,k) \
|
||||
do { \
|
||||
uint32_t temp; \
|
||||
\
|
||||
temp = cshift(AA, 5) + f(BB,CC,DD) + EE + data[t] + k; \
|
||||
EE = DD; \
|
||||
DD = CC; \
|
||||
CC = cshift(BB, 30); \
|
||||
BB = AA; \
|
||||
AA = temp; \
|
||||
} while(0)
|
||||
|
||||
static inline void
|
||||
calc (struct sha *m, uint32_t *in)
|
||||
{
|
||||
uint32_t AA, BB, CC, DD, EE;
|
||||
uint32_t data[80];
|
||||
int i;
|
||||
|
||||
AA = A;
|
||||
BB = B;
|
||||
CC = C;
|
||||
DD = D;
|
||||
EE = E;
|
||||
|
||||
for (i = 0; i < 16; ++i)
|
||||
data[i] = in[i];
|
||||
for (i = 16; i < 80; ++i)
|
||||
data[i] = cshift(data[i-3] ^ data[i-8] ^ data[i-14] ^ data[i-16], 1);
|
||||
|
||||
/* t=[0,19] */
|
||||
|
||||
DO(0,F0,K0);
|
||||
DO(1,F0,K0);
|
||||
DO(2,F0,K0);
|
||||
DO(3,F0,K0);
|
||||
DO(4,F0,K0);
|
||||
DO(5,F0,K0);
|
||||
DO(6,F0,K0);
|
||||
DO(7,F0,K0);
|
||||
DO(8,F0,K0);
|
||||
DO(9,F0,K0);
|
||||
DO(10,F0,K0);
|
||||
DO(11,F0,K0);
|
||||
DO(12,F0,K0);
|
||||
DO(13,F0,K0);
|
||||
DO(14,F0,K0);
|
||||
DO(15,F0,K0);
|
||||
DO(16,F0,K0);
|
||||
DO(17,F0,K0);
|
||||
DO(18,F0,K0);
|
||||
DO(19,F0,K0);
|
||||
|
||||
/* t=[20,39] */
|
||||
|
||||
DO(20,F1,K1);
|
||||
DO(21,F1,K1);
|
||||
DO(22,F1,K1);
|
||||
DO(23,F1,K1);
|
||||
DO(24,F1,K1);
|
||||
DO(25,F1,K1);
|
||||
DO(26,F1,K1);
|
||||
DO(27,F1,K1);
|
||||
DO(28,F1,K1);
|
||||
DO(29,F1,K1);
|
||||
DO(30,F1,K1);
|
||||
DO(31,F1,K1);
|
||||
DO(32,F1,K1);
|
||||
DO(33,F1,K1);
|
||||
DO(34,F1,K1);
|
||||
DO(35,F1,K1);
|
||||
DO(36,F1,K1);
|
||||
DO(37,F1,K1);
|
||||
DO(38,F1,K1);
|
||||
DO(39,F1,K1);
|
||||
|
||||
/* t=[40,59] */
|
||||
|
||||
DO(40,F2,K2);
|
||||
DO(41,F2,K2);
|
||||
DO(42,F2,K2);
|
||||
DO(43,F2,K2);
|
||||
DO(44,F2,K2);
|
||||
DO(45,F2,K2);
|
||||
DO(46,F2,K2);
|
||||
DO(47,F2,K2);
|
||||
DO(48,F2,K2);
|
||||
DO(49,F2,K2);
|
||||
DO(50,F2,K2);
|
||||
DO(51,F2,K2);
|
||||
DO(52,F2,K2);
|
||||
DO(53,F2,K2);
|
||||
DO(54,F2,K2);
|
||||
DO(55,F2,K2);
|
||||
DO(56,F2,K2);
|
||||
DO(57,F2,K2);
|
||||
DO(58,F2,K2);
|
||||
DO(59,F2,K2);
|
||||
|
||||
/* t=[60,79] */
|
||||
|
||||
DO(60,F3,K3);
|
||||
DO(61,F3,K3);
|
||||
DO(62,F3,K3);
|
||||
DO(63,F3,K3);
|
||||
DO(64,F3,K3);
|
||||
DO(65,F3,K3);
|
||||
DO(66,F3,K3);
|
||||
DO(67,F3,K3);
|
||||
DO(68,F3,K3);
|
||||
DO(69,F3,K3);
|
||||
DO(70,F3,K3);
|
||||
DO(71,F3,K3);
|
||||
DO(72,F3,K3);
|
||||
DO(73,F3,K3);
|
||||
DO(74,F3,K3);
|
||||
DO(75,F3,K3);
|
||||
DO(76,F3,K3);
|
||||
DO(77,F3,K3);
|
||||
DO(78,F3,K3);
|
||||
DO(79,F3,K3);
|
||||
|
||||
A += AA;
|
||||
B += BB;
|
||||
C += CC;
|
||||
D += DD;
|
||||
E += EE;
|
||||
}
|
||||
|
||||
/*
|
||||
* From `Performance analysis of MD5' by Joseph D. Touch <touch@isi.edu>
|
||||
*/
|
||||
|
||||
#if !defined(WORDS_BIGENDIAN) || defined(_CRAY)
|
||||
static inline uint32_t
|
||||
swap_uint32_t (uint32_t t)
|
||||
{
|
||||
#define ROL(x,n) ((x)<<(n))|((x)>>(32-(n)))
|
||||
uint32_t temp1, temp2;
|
||||
|
||||
temp1 = cshift(t, 16);
|
||||
temp2 = temp1 >> 8;
|
||||
temp1 &= 0x00ff00ff;
|
||||
temp2 &= 0x00ff00ff;
|
||||
temp1 <<= 8;
|
||||
return temp1 | temp2;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct x32{
|
||||
unsigned int a:32;
|
||||
unsigned int b:32;
|
||||
};
|
||||
|
||||
void
|
||||
SHA1_Update (struct sha *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) % 64;
|
||||
while(len > 0){
|
||||
size_t l = min(len, 64 - offset);
|
||||
memcpy(m->save + offset, p, l);
|
||||
offset += l;
|
||||
p += l;
|
||||
len -= l;
|
||||
if(offset == 64){
|
||||
#if !defined(WORDS_BIGENDIAN) || defined(_CRAY)
|
||||
int i;
|
||||
uint32_t current[16];
|
||||
struct x32 *u = (struct x32*)m->save;
|
||||
for(i = 0; i < 8; i++){
|
||||
current[2*i+0] = swap_uint32_t(u[i].a);
|
||||
current[2*i+1] = swap_uint32_t(u[i].b);
|
||||
}
|
||||
calc(m, current);
|
||||
#else
|
||||
calc(m, (uint32_t*)m->save);
|
||||
#endif
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SHA1_Final (void *res, struct sha *m)
|
||||
{
|
||||
unsigned char zeros[72];
|
||||
unsigned offset = (m->sz[0] / 8) % 64;
|
||||
unsigned int dstart = (120 - offset - 1) % 64 + 1;
|
||||
|
||||
*zeros = 0x80;
|
||||
memset (zeros + 1, 0, sizeof(zeros) - 1);
|
||||
zeros[dstart+7] = (m->sz[0] >> 0) & 0xff;
|
||||
zeros[dstart+6] = (m->sz[0] >> 8) & 0xff;
|
||||
zeros[dstart+5] = (m->sz[0] >> 16) & 0xff;
|
||||
zeros[dstart+4] = (m->sz[0] >> 24) & 0xff;
|
||||
zeros[dstart+3] = (m->sz[1] >> 0) & 0xff;
|
||||
zeros[dstart+2] = (m->sz[1] >> 8) & 0xff;
|
||||
zeros[dstart+1] = (m->sz[1] >> 16) & 0xff;
|
||||
zeros[dstart+0] = (m->sz[1] >> 24) & 0xff;
|
||||
SHA1_Update (m, zeros, dstart + 8);
|
||||
{
|
||||
int i;
|
||||
unsigned char *r = (unsigned char*)res;
|
||||
|
||||
for (i = 0; i < 5; ++i) {
|
||||
r[4*i+3] = m->counter[i] & 0xFF;
|
||||
r[4*i+2] = (m->counter[i] >> 8) & 0xFF;
|
||||
r[4*i+1] = (m->counter[i] >> 16) & 0xFF;
|
||||
r[4*i] = (m->counter[i] >> 24) & 0xFF;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
{
|
||||
int i;
|
||||
uint32_t *r = (uint32_t *)res;
|
||||
|
||||
for (i = 0; i < 5; ++i)
|
||||
r[i] = swap_uint32_t (m->counter[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
83
src/external/heimdal/hcrypto/sha.h
vendored
Normal file
83
src/external/heimdal/hcrypto/sha.h
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef HEIM_SHA_H
|
||||
#define HEIM_SHA_H 1
|
||||
|
||||
/* symbol renaming */
|
||||
#define SHA1_Init hc_SHA1_Init
|
||||
#define SHA1_Update hc_SHA1_Update
|
||||
#define SHA1_Final hc_SHA1_Final
|
||||
#define SHA256_Init hc_SHA256_Init
|
||||
#define SHA256_Update hc_SHA256_Update
|
||||
#define SHA256_Final hc_SHA256_Final
|
||||
|
||||
/*
|
||||
* SHA-1
|
||||
*/
|
||||
|
||||
#define SHA_DIGEST_LENGTH 20
|
||||
|
||||
struct sha {
|
||||
unsigned int sz[2];
|
||||
uint32_t counter[5];
|
||||
unsigned char save[64];
|
||||
};
|
||||
|
||||
typedef struct sha SHA_CTX;
|
||||
|
||||
void SHA1_Init (struct sha *m);
|
||||
void SHA1_Update (struct sha *m, const void *v, size_t len);
|
||||
void SHA1_Final (void *res, struct sha *m);
|
||||
|
||||
/*
|
||||
* SHA-2 256
|
||||
*/
|
||||
|
||||
#define SHA256_DIGEST_LENGTH 32
|
||||
|
||||
struct hc_sha256state {
|
||||
unsigned int sz[2];
|
||||
uint32_t counter[8];
|
||||
unsigned char save[64];
|
||||
};
|
||||
|
||||
typedef struct hc_sha256state SHA256_CTX;
|
||||
|
||||
void SHA256_Init (SHA256_CTX *);
|
||||
void SHA256_Update (SHA256_CTX *, const void *, size_t);
|
||||
void SHA256_Final (void *, SHA256_CTX *);
|
||||
|
||||
#endif /* HEIM_SHA_H */
|
229
src/external/heimdal/hcrypto/sha256.c
vendored
Normal file
229
src/external/heimdal/hcrypto/sha256.c
vendored
Normal file
@ -0,0 +1,229 @@
|
||||
/*
|
||||
* 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) << (32 - (n))))
|
||||
|
||||
#define Sigma0(x) (ROTR(x,2) ^ ROTR(x,13) ^ ROTR(x,22))
|
||||
#define Sigma1(x) (ROTR(x,6) ^ ROTR(x,11) ^ ROTR(x,25))
|
||||
#define sigma0(x) (ROTR(x,7) ^ ROTR(x,18) ^ ((x)>>3))
|
||||
#define sigma1(x) (ROTR(x,17) ^ ROTR(x,19) ^ ((x)>>10))
|
||||
|
||||
#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 uint32_t constant_256[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
||||
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
||||
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
||||
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
||||
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
|
||||
void
|
||||
SHA256_Init (SHA256_CTX *m)
|
||||
{
|
||||
m->sz[0] = 0;
|
||||
m->sz[1] = 0;
|
||||
A = 0x6a09e667;
|
||||
B = 0xbb67ae85;
|
||||
C = 0x3c6ef372;
|
||||
D = 0xa54ff53a;
|
||||
E = 0x510e527f;
|
||||
F = 0x9b05688c;
|
||||
G = 0x1f83d9ab;
|
||||
H = 0x5be0cd19;
|
||||
}
|
||||
|
||||
static void
|
||||
calc (SHA256_CTX *m, uint32_t *in)
|
||||
{
|
||||
uint32_t AA, BB, CC, DD, EE, FF, GG, HH;
|
||||
uint32_t data[64];
|
||||
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 < 64; ++i)
|
||||
data[i] = sigma1(data[i-2]) + data[i-7] +
|
||||
sigma0(data[i-15]) + data[i - 16];
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
uint32_t T1, T2;
|
||||
|
||||
T1 = HH + Sigma1(EE) + Ch(EE, FF, GG) + constant_256[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 <touch@isi.edu>
|
||||
*/
|
||||
|
||||
#if !defined(WORDS_BIGENDIAN) || defined(_CRAY)
|
||||
static inline uint32_t
|
||||
swap_uint32_t (uint32_t t)
|
||||
{
|
||||
#define ROL(x,n) ((x)<<(n))|((x)>>(32-(n)))
|
||||
uint32_t temp1, temp2;
|
||||
|
||||
temp1 = cshift(t, 16);
|
||||
temp2 = temp1 >> 8;
|
||||
temp1 &= 0x00ff00ff;
|
||||
temp2 &= 0x00ff00ff;
|
||||
temp1 <<= 8;
|
||||
return temp1 | temp2;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct x32{
|
||||
unsigned int a:32;
|
||||
unsigned int b:32;
|
||||
};
|
||||
|
||||
void
|
||||
SHA256_Update (SHA256_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) % 64;
|
||||
while(len > 0){
|
||||
size_t l = min(len, 64 - offset);
|
||||
memcpy(m->save + offset, p, l);
|
||||
offset += l;
|
||||
p += l;
|
||||
len -= l;
|
||||
if(offset == 64){
|
||||
#if !defined(WORDS_BIGENDIAN) || defined(_CRAY)
|
||||
int i;
|
||||
uint32_t current[16];
|
||||
struct x32 *u = (struct x32*)m->save;
|
||||
for(i = 0; i < 8; i++){
|
||||
current[2*i+0] = swap_uint32_t(u[i].a);
|
||||
current[2*i+1] = swap_uint32_t(u[i].b);
|
||||
}
|
||||
calc(m, current);
|
||||
#else
|
||||
calc(m, (uint32_t*)m->save);
|
||||
#endif
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SHA256_Final (void *res, SHA256_CTX *m)
|
||||
{
|
||||
unsigned char zeros[72];
|
||||
unsigned offset = (m->sz[0] / 8) % 64;
|
||||
unsigned int dstart = (120 - offset - 1) % 64 + 1;
|
||||
|
||||
*zeros = 0x80;
|
||||
memset (zeros + 1, 0, sizeof(zeros) - 1);
|
||||
zeros[dstart+7] = (m->sz[0] >> 0) & 0xff;
|
||||
zeros[dstart+6] = (m->sz[0] >> 8) & 0xff;
|
||||
zeros[dstart+5] = (m->sz[0] >> 16) & 0xff;
|
||||
zeros[dstart+4] = (m->sz[0] >> 24) & 0xff;
|
||||
zeros[dstart+3] = (m->sz[1] >> 0) & 0xff;
|
||||
zeros[dstart+2] = (m->sz[1] >> 8) & 0xff;
|
||||
zeros[dstart+1] = (m->sz[1] >> 16) & 0xff;
|
||||
zeros[dstart+0] = (m->sz[1] >> 24) & 0xff;
|
||||
SHA256_Update (m, zeros, dstart + 8);
|
||||
{
|
||||
int i;
|
||||
unsigned char *r = (unsigned char*)res;
|
||||
|
||||
for (i = 0; i < 8; ++i) {
|
||||
r[4*i+3] = m->counter[i] & 0xFF;
|
||||
r[4*i+2] = (m->counter[i] >> 8) & 0xFF;
|
||||
r[4*i+1] = (m->counter[i] >> 16) & 0xFF;
|
||||
r[4*i] = (m->counter[i] >> 24) & 0xFF;
|
||||
}
|
||||
}
|
||||
}
|
367
src/external/heimdal/hcrypto/test_cipher.c
vendored
Normal file
367
src/external/heimdal/hcrypto/test_cipher.c
vendored
Normal file
@ -0,0 +1,367 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
#define HC_DEPRECATED_CRYPTO
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getarg.h>
|
||||
#include <roken.h>
|
||||
|
||||
#include <evp.h>
|
||||
#include <evp-hcrypto.h>
|
||||
#include <evp-cc.h>
|
||||
#include <hex.h>
|
||||
#include <err.h>
|
||||
|
||||
struct tests {
|
||||
const char *name;
|
||||
void *key;
|
||||
size_t keysize;
|
||||
void *iv;
|
||||
size_t datasize;
|
||||
void *indata;
|
||||
void *outdata;
|
||||
void *outiv;
|
||||
};
|
||||
|
||||
struct tests aes_tests[] = {
|
||||
{ "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"
|
||||
}
|
||||
};
|
||||
|
||||
struct tests aes_cfb_tests[] = {
|
||||
{ "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"
|
||||
}
|
||||
};
|
||||
|
||||
struct tests rc2_40_tests[] = {
|
||||
{ "rc2-40",
|
||||
"\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",
|
||||
"\xc0\xb8\xff\xa5\xd6\xeb\xc9\x62\xcc\x52\x5f\xfe\x9a\x3c\x97\xe6"
|
||||
}
|
||||
};
|
||||
|
||||
struct tests des_ede3_tests[] = {
|
||||
{ "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"
|
||||
}
|
||||
};
|
||||
|
||||
struct tests camellia128_tests[] = {
|
||||
{ "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
|
||||
}
|
||||
};
|
||||
|
||||
struct tests rc4_tests[] = {
|
||||
{
|
||||
"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
|
||||
},
|
||||
{
|
||||
"rc4 5",
|
||||
"\x61\x8a\x63\xd2\xfb",
|
||||
5,
|
||||
NULL,
|
||||
5,
|
||||
"\xdc\xee\x4c\xf9\x2c",
|
||||
"\xf1\x38\x29\xc9\xde",
|
||||
NULL
|
||||
},
|
||||
{
|
||||
"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(int i, const EVP_CIPHER *c, struct tests *t)
|
||||
{
|
||||
EVP_CIPHER_CTX ectx;
|
||||
EVP_CIPHER_CTX dctx;
|
||||
void *d;
|
||||
|
||||
if (c == NULL) {
|
||||
printf("%s not supported\n", t->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
EVP_CIPHER_CTX_init(&ectx);
|
||||
EVP_CIPHER_CTX_init(&dctx);
|
||||
|
||||
if (EVP_CipherInit_ex(&ectx, c, NULL, NULL, NULL, 1) != 1)
|
||||
errx(1, "%s: %d EVP_CipherInit_ex einit", t->name, i);
|
||||
if (EVP_CipherInit_ex(&dctx, c, NULL, NULL, NULL, 0) != 1)
|
||||
errx(1, "%s: %d EVP_CipherInit_ex dinit", t->name, i);
|
||||
|
||||
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: %d EVP_CipherInit_ex encrypt", t->name, i);
|
||||
if (EVP_CipherInit_ex(&dctx, NULL, NULL, t->key, t->iv, 0) != 1)
|
||||
errx(1, "%s: %d EVP_CipherInit_ex decrypt", t->name, i);
|
||||
|
||||
d = emalloc(t->datasize);
|
||||
|
||||
if (!EVP_Cipher(&ectx, d, t->indata, t->datasize))
|
||||
return 1;
|
||||
|
||||
if (memcmp(d, t->outdata, t->datasize) != 0) {
|
||||
char *s, *s2;
|
||||
hex_encode(d, t->datasize, &s);
|
||||
hex_encode(t->outdata, t->datasize, &s2);
|
||||
errx(1, "%s: %d encrypt not the same: %s != %s", t->name, i, s, s2);
|
||||
}
|
||||
|
||||
if (!EVP_Cipher(&dctx, d, d, t->datasize))
|
||||
return 1;
|
||||
|
||||
if (memcmp(d, t->indata, t->datasize) != 0) {
|
||||
char *s;
|
||||
hex_encode(d, t->datasize, &s);
|
||||
errx(1, "%s: %d decrypt not the same: %s", t->name, i, s);
|
||||
}
|
||||
if (t->outiv)
|
||||
/* XXXX check */;
|
||||
|
||||
EVP_CIPHER_CTX_cleanup(&ectx);
|
||||
EVP_CIPHER_CTX_cleanup(&dctx);
|
||||
free(d);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int version_flag;
|
||||
static int help_flag;
|
||||
|
||||
static struct getargs args[] = {
|
||||
{ "version", 0, arg_flag, &version_flag,
|
||||
"print version", NULL },
|
||||
{ "help", 0, arg_flag, &help_flag,
|
||||
NULL, NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
usage (int ret)
|
||||
{
|
||||
arg_printusage (args,
|
||||
sizeof(args)/sizeof(*args),
|
||||
NULL,
|
||||
"");
|
||||
exit (ret);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
int i, idx = 0;
|
||||
|
||||
setprogname(argv[0]);
|
||||
|
||||
if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &idx))
|
||||
usage(1);
|
||||
|
||||
if (help_flag)
|
||||
usage(0);
|
||||
|
||||
if(version_flag){
|
||||
print_version(NULL);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
argc -= idx;
|
||||
argv += idx;
|
||||
|
||||
/* hcrypto */
|
||||
for (i = 0; i < sizeof(aes_tests)/sizeof(aes_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_hcrypto_aes_256_cbc(), &aes_tests[i]);
|
||||
for (i = 0; i < sizeof(aes_cfb_tests)/sizeof(aes_cfb_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_hcrypto_aes_128_cfb8(), &aes_cfb_tests[i]);
|
||||
|
||||
for (i = 0; i < sizeof(rc2_40_tests)/sizeof(rc2_40_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_hcrypto_rc2_40_cbc(), &rc2_40_tests[i]);
|
||||
for (i = 0; i < sizeof(des_ede3_tests)/sizeof(des_ede3_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_hcrypto_des_ede3_cbc(), &des_ede3_tests[i]);
|
||||
for (i = 0; i < sizeof(camellia128_tests)/sizeof(camellia128_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_hcrypto_camellia_128_cbc(),
|
||||
&camellia128_tests[i]);
|
||||
for (i = 0; i < sizeof(rc4_tests)/sizeof(rc4_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_hcrypto_rc4(), &rc4_tests[i]);
|
||||
|
||||
/* Common Crypto */
|
||||
#ifdef __APPLE__
|
||||
for (i = 0; i < sizeof(aes_tests)/sizeof(aes_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_cc_aes_256_cbc(), &aes_tests[i]);
|
||||
#if 0
|
||||
for (i = 0; i < sizeof(aes_cfb_tests)/sizeof(aes_cfb_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_cc_aes_128_cfb8(), &aes_cfb_tests[i]);
|
||||
#endif
|
||||
for (i = 0; i < sizeof(rc2_40_tests)/sizeof(rc2_40_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_cc_rc2_40_cbc(), &rc2_40_tests[i]);
|
||||
for (i = 0; i < sizeof(des_ede3_tests)/sizeof(des_ede3_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_cc_des_ede3_cbc(), &des_ede3_tests[i]);
|
||||
for (i = 0; i < sizeof(camellia128_tests)/sizeof(camellia128_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_cc_camellia_128_cbc(),
|
||||
&camellia128_tests[i]);
|
||||
for (i = 0; i < sizeof(rc4_tests)/sizeof(rc4_tests[0]); i++)
|
||||
ret += test_cipher(i, EVP_cc_rc4(), &rc4_tests[i]);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
217
src/external/heimdal/hcrypto/ui.c
vendored
Normal file
217
src/external/heimdal/hcrypto/ui.c
vendored
Normal file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
* Copyright (c) 1997 - 2000, 2005 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#include <termios.h>
|
||||
#endif
|
||||
#include <roken.h>
|
||||
|
||||
#include <ui.h>
|
||||
#ifdef HAVE_CONIO_H
|
||||
#include <conio.h>
|
||||
#endif
|
||||
|
||||
static sig_atomic_t intr_flag;
|
||||
|
||||
static void
|
||||
intr(int sig)
|
||||
{
|
||||
intr_flag++;
|
||||
}
|
||||
|
||||
#ifdef HAVE_CONIO_H
|
||||
|
||||
/*
|
||||
* Windows does console slightly different then then unix case.
|
||||
*/
|
||||
|
||||
static int
|
||||
read_string(const char *preprompt, const char *prompt,
|
||||
char *buf, size_t len, int echo)
|
||||
{
|
||||
int of = 0;
|
||||
int c;
|
||||
char *p;
|
||||
void (*oldsigintr)(int);
|
||||
|
||||
_cprintf("%s%s", preprompt, prompt);
|
||||
|
||||
oldsigintr = signal(SIGINT, intr);
|
||||
|
||||
p = buf;
|
||||
while(intr_flag == 0){
|
||||
c = ((echo)? _getche(): _getch());
|
||||
if(c == '\n' || c == '\r')
|
||||
break;
|
||||
if(of == 0)
|
||||
*p++ = c;
|
||||
of = (p == buf + len);
|
||||
}
|
||||
if(of)
|
||||
p--;
|
||||
*p = 0;
|
||||
|
||||
if(echo == 0){
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
signal(SIGINT, oldsigintr);
|
||||
|
||||
if(intr_flag)
|
||||
return -2;
|
||||
if(of)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* !HAVE_CONIO_H */
|
||||
|
||||
#ifndef NSIG
|
||||
#define NSIG 47
|
||||
#endif
|
||||
|
||||
static int
|
||||
read_string(const char *preprompt, const char *prompt,
|
||||
char *buf, size_t len, int echo)
|
||||
{
|
||||
struct sigaction sigs[NSIG];
|
||||
int oksigs[NSIG];
|
||||
struct sigaction sa;
|
||||
FILE *tty;
|
||||
int ret = 0;
|
||||
int of = 0;
|
||||
int i;
|
||||
int c;
|
||||
char *p;
|
||||
|
||||
struct termios t_new, t_old;
|
||||
|
||||
memset(&oksigs, 0, sizeof(oksigs));
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = intr;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
for(i = 1; i < sizeof(sigs) / sizeof(sigs[0]); i++)
|
||||
if (i != SIGALRM)
|
||||
if (sigaction(i, &sa, &sigs[i]) == 0)
|
||||
oksigs[i] = 1;
|
||||
|
||||
if((tty = fopen("/dev/tty", "r")) != NULL)
|
||||
rk_cloexec_file(tty);
|
||||
else
|
||||
tty = stdin;
|
||||
|
||||
fprintf(stderr, "%s%s", preprompt, prompt);
|
||||
fflush(stderr);
|
||||
|
||||
if(echo == 0){
|
||||
tcgetattr(fileno(tty), &t_old);
|
||||
memcpy(&t_new, &t_old, sizeof(t_new));
|
||||
t_new.c_lflag &= ~ECHO;
|
||||
tcsetattr(fileno(tty), TCSANOW, &t_new);
|
||||
}
|
||||
intr_flag = 0;
|
||||
p = buf;
|
||||
while(intr_flag == 0){
|
||||
c = getc(tty);
|
||||
if(c == EOF){
|
||||
if(!ferror(tty))
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
if(c == '\n')
|
||||
break;
|
||||
if(of == 0)
|
||||
*p++ = c;
|
||||
of = (p == buf + len);
|
||||
}
|
||||
if(of)
|
||||
p--;
|
||||
*p = 0;
|
||||
|
||||
if(echo == 0){
|
||||
fprintf(stderr, "\n");
|
||||
tcsetattr(fileno(tty), TCSANOW, &t_old);
|
||||
}
|
||||
|
||||
if(tty != stdin)
|
||||
fclose(tty);
|
||||
|
||||
for(i = 1; i < sizeof(sigs) / sizeof(sigs[0]); i++)
|
||||
if (oksigs[i])
|
||||
sigaction(i, &sigs[i], NULL);
|
||||
|
||||
if(ret)
|
||||
return -3;
|
||||
if(intr_flag)
|
||||
return -2;
|
||||
if(of)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* HAVE_CONIO_H */
|
||||
|
||||
int
|
||||
UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = read_string("", prompt, buf, length, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (verify) {
|
||||
char *buf2;
|
||||
buf2 = malloc(length);
|
||||
if (buf2 == NULL)
|
||||
return 1;
|
||||
|
||||
ret = read_string("Verify password - ", prompt, buf2, length, 0);
|
||||
if (ret) {
|
||||
free(buf2);
|
||||
return ret;
|
||||
}
|
||||
if (strcmp(buf2, buf) != 0)
|
||||
ret = 1;
|
||||
free(buf2);
|
||||
}
|
||||
return ret;
|
||||
}
|
44
src/external/heimdal/hcrypto/ui.h
vendored
Normal file
44
src/external/heimdal/hcrypto/ui.h
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2005 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 _HEIM_UI_H
|
||||
#define _HEIM_UI_H 1
|
||||
|
||||
/* symbol renaming */
|
||||
#define UI_UTIL_read_pw_string hc_UI_UTIL_read_pw_string
|
||||
|
||||
int UI_UTIL_read_pw_string(char *, int, const char *, int); /* XXX */
|
||||
|
||||
#endif /* _HEIM_UI_H */
|
5
src/external/heimdal/krb5/config_file.c
vendored
5
src/external/heimdal/krb5/config_file.c
vendored
@ -447,8 +447,9 @@ krb5_config_parse_file_multi (krb5_context context,
|
||||
fname = newfname;
|
||||
}
|
||||
#else /* KRB5_USE_PATH_TOKENS */
|
||||
asprintf(&newfname, "%%{USERCONFIG}/%s", &fname[1]);
|
||||
if (newfname == NULL) {
|
||||
if (asprintf(&newfname, "%%{USERCONFIG}%s", &fname[1]) < 0 ||
|
||||
newfname == NULL)
|
||||
{
|
||||
krb5_set_error_message(context, ENOMEM,
|
||||
N_("malloc: out of memory", ""));
|
||||
return ENOMEM;
|
||||
|
66
src/external/heimdal/roken/cloexec.c
vendored
Normal file
66
src/external/heimdal/roken/cloexec.c
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2008 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 "roken.h"
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
rk_cloexec(int fd)
|
||||
{
|
||||
#ifdef HAVE_FCNTL
|
||||
int ret;
|
||||
|
||||
ret = fcntl(fd, F_GETFD);
|
||||
if (ret == -1)
|
||||
return;
|
||||
if (fcntl(fd, F_SETFD, ret | FD_CLOEXEC) == -1)
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
rk_cloexec_file(FILE *f)
|
||||
{
|
||||
#ifdef HAVE_FCNTL
|
||||
rk_cloexec(fileno(f));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
rk_cloexec_dir(DIR * d)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
rk_cloexec(dirfd(d));
|
||||
#endif
|
||||
}
|
64
src/external/heimdal/roken/ct.c
vendored
Normal file
64
src/external/heimdal/roken/ct.c
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2009 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 "roken.h"
|
||||
|
||||
/**
|
||||
* Constant time compare to memory regions. The reason for making it
|
||||
* constant time is to make sure that timeing information leak from
|
||||
* where in the function the diffrence is.
|
||||
*
|
||||
* ct_memcmp() can't be used to order memory regions like memcmp(),
|
||||
* for example, use ct_memcmp() with qsort().
|
||||
*
|
||||
* @param p1 memory region 1 to compare
|
||||
* @param p2 memory region 2 to compare
|
||||
* @param len length of memory
|
||||
*
|
||||
* @return 0 when the memory regions are equal, non zero if not
|
||||
*
|
||||
* @ingroup roken
|
||||
*/
|
||||
|
||||
int
|
||||
ct_memcmp(const void *p1, const void *p2, size_t len)
|
||||
{
|
||||
const unsigned char *s1 = p1, *s2 = p2;
|
||||
size_t i;
|
||||
int r = 0;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
r |= (s1[i] ^ s2[i]);
|
||||
return !!r;
|
||||
}
|
105
src/external/heimdal/roken/hex.c
vendored
Normal file
105
src/external/heimdal/roken/hex.c
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2005 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 "roken.h"
|
||||
#include <ctype.h>
|
||||
#include "hex.h"
|
||||
|
||||
const static char hexchar[] = "0123456789ABCDEF";
|
||||
|
||||
static int
|
||||
pos(char c)
|
||||
{
|
||||
const char *p;
|
||||
c = toupper((unsigned char)c);
|
||||
for (p = hexchar; *p; p++)
|
||||
if (*p == c)
|
||||
return p - hexchar;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
hex_encode(const void *data, size_t size, char **str)
|
||||
{
|
||||
const unsigned char *q = data;
|
||||
size_t i;
|
||||
char *p;
|
||||
|
||||
/* check for overflow */
|
||||
if (size * 2 < size) {
|
||||
*str = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
p = malloc(size * 2 + 1);
|
||||
if (p == NULL) {
|
||||
*str = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
p[i * 2] = hexchar[(*q >> 4) & 0xf];
|
||||
p[i * 2 + 1] = hexchar[*q & 0xf];
|
||||
q++;
|
||||
}
|
||||
p[i * 2] = '\0';
|
||||
*str = p;
|
||||
|
||||
return i * 2;
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
hex_decode(const char *str, void *data, size_t len)
|
||||
{
|
||||
size_t l;
|
||||
unsigned char *p = data;
|
||||
size_t i;
|
||||
|
||||
l = strlen(str);
|
||||
|
||||
/* check for overflow, same as (l+1)/2 but overflow safe */
|
||||
if ((l/2) + (l&1) > len)
|
||||
return -1;
|
||||
|
||||
i = 0;
|
||||
if (l & 1) {
|
||||
p[0] = pos(str[0]);
|
||||
str++;
|
||||
p++;
|
||||
}
|
||||
for (i = 0; i < l / 2; i++)
|
||||
p[i] = pos(str[i * 2]) << 4 | pos(str[(i * 2) + 1]);
|
||||
return i + (l & 1);
|
||||
}
|
56
src/external/heimdal/roken/issuid.c
vendored
Normal file
56
src/external/heimdal/roken/issuid.c
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 1998 - 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 <config.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
issuid(void)
|
||||
{
|
||||
#if defined(HAVE_ISSETUGID)
|
||||
return issetugid();
|
||||
#else /* !HAVE_ISSETUGID */
|
||||
|
||||
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
|
||||
if(getuid() != geteuid())
|
||||
return 1;
|
||||
#endif
|
||||
#if defined(HAVE_GETGID) && defined(HAVE_GETEGID)
|
||||
if(getgid() != getegid())
|
||||
return 2;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
#endif /* HAVE_ISSETUGID */
|
||||
}
|
117
src/external/heimdal/roken/net_read.c
vendored
Normal file
117
src/external/heimdal/roken/net_read.c
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 1996, 1997, 1998 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 "roken.h"
|
||||
|
||||
/*
|
||||
* Like read but never return partial data.
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
net_read (rk_socket_t fd, void *buf, size_t nbytes)
|
||||
{
|
||||
char *cbuf = (char *)buf;
|
||||
ssize_t count;
|
||||
size_t rem = nbytes;
|
||||
|
||||
while (rem > 0) {
|
||||
count = read (fd, cbuf, rem);
|
||||
if (count < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
return count;
|
||||
} else if (count == 0) {
|
||||
return count;
|
||||
}
|
||||
cbuf += count;
|
||||
rem -= count;
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
net_read(rk_socket_t sock, void *buf, size_t nbytes)
|
||||
{
|
||||
char *cbuf = (char *)buf;
|
||||
ssize_t count;
|
||||
size_t rem = nbytes;
|
||||
|
||||
#ifdef SOCKET_IS_NOT_AN_FD
|
||||
int use_read = 0;
|
||||
#endif
|
||||
|
||||
while (rem > 0) {
|
||||
#ifdef SOCKET_IS_NOT_AN_FD
|
||||
if (use_read)
|
||||
count = _read (sock, cbuf, rem);
|
||||
else
|
||||
count = recv (sock, cbuf, rem, 0);
|
||||
|
||||
if (use_read == 0 &&
|
||||
rk_IS_SOCKET_ERROR(count) &&
|
||||
rk_SOCK_ERRNO == WSAENOTSOCK) {
|
||||
use_read = 1;
|
||||
|
||||
count = _read (sock, cbuf, rem);
|
||||
}
|
||||
#else
|
||||
count = recv (sock, cbuf, rem, 0);
|
||||
#endif
|
||||
if (count < 0) {
|
||||
|
||||
/* With WinSock, the error EINTR (WSAEINTR), is used to
|
||||
indicate that a blocking call was cancelled using
|
||||
WSACancelBlockingCall(). */
|
||||
|
||||
#ifndef HAVE_WINSOCK
|
||||
if (rk_SOCK_ERRNO == EINTR)
|
||||
continue;
|
||||
#endif
|
||||
return count;
|
||||
} else if (count == 0) {
|
||||
return count;
|
||||
}
|
||||
cbuf += count;
|
||||
rem -= count;
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
#endif
|
106
src/external/heimdal/roken/net_write.c
vendored
Normal file
106
src/external/heimdal/roken/net_write.c
vendored
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 1996, 1997, 1998 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 "roken.h"
|
||||
|
||||
/*
|
||||
* Like write but never return partial data.
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
net_write (rk_socket_t fd, const void *buf, size_t nbytes)
|
||||
{
|
||||
const char *cbuf = (const char *)buf;
|
||||
ssize_t count;
|
||||
size_t rem = nbytes;
|
||||
|
||||
while (rem > 0) {
|
||||
count = write (fd, cbuf, rem);
|
||||
if (count < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
return count;
|
||||
}
|
||||
cbuf += count;
|
||||
rem -= count;
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
net_write(rk_socket_t sock, const void *buf, size_t nbytes)
|
||||
{
|
||||
const char *cbuf = (const char *)buf;
|
||||
ssize_t count;
|
||||
size_t rem = nbytes;
|
||||
#ifdef SOCKET_IS_NOT_AN_FD
|
||||
int use_write = 0;
|
||||
#endif
|
||||
|
||||
while (rem > 0) {
|
||||
#ifdef SOCKET_IS_NOT_AN_FD
|
||||
if (use_write)
|
||||
count = _write (sock, cbuf, rem);
|
||||
else
|
||||
count = send (sock, cbuf, rem, 0);
|
||||
|
||||
if (use_write == 0 &&
|
||||
rk_IS_SOCKET_ERROR(count) &&
|
||||
rk_SOCK_ERRNO == WSAENOTSOCK) {
|
||||
use_write = 1;
|
||||
|
||||
count = _write (sock, cbuf, rem);
|
||||
}
|
||||
#else
|
||||
count = send (sock, cbuf, rem, 0);
|
||||
#endif
|
||||
if (count < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
return count;
|
||||
}
|
||||
cbuf += count;
|
||||
rem -= count;
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
#endif
|
72
src/external/heimdal/roken/strlcpy.c
vendored
Normal file
72
src/external/heimdal/roken/strlcpy.c
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 1995-2002 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 "roken.h"
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
strlcpy (char *dst, const char *src, size_t dst_cch)
|
||||
{
|
||||
errno_t e;
|
||||
|
||||
e = strcpy_s(dst, dst_cch, src);
|
||||
|
||||
return strlen (src);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
strlcpy (char *dst, const char *src, size_t dst_sz)
|
||||
{
|
||||
size_t n;
|
||||
|
||||
for (n = 0; n < dst_sz; n++) {
|
||||
if ((*dst++ = *src++) == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
if (n < dst_sz)
|
||||
return n;
|
||||
if (n > 0)
|
||||
*(dst - 1) = '\0';
|
||||
return n + strlen (src);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user