Merge remote-tracking branch 'upstream/master'

This commit is contained in:
conor42
2018-11-07 14:34:48 +10:00
36 changed files with 1926 additions and 27 deletions

View File

@@ -28,6 +28,9 @@ extern "C" {
#if defined(_MSC_VER) /* Visual Studio */
# include <stdlib.h> /* _byteswap_ulong */
# include <intrin.h> /* _byteswap_* */
# pragma warning(disable : 4389) /* disable: C4389: '==' : signed/unsigned mismatch */
#endif
#endif
#if defined(__GNUC__)
# define MEM_STATIC static __inline __attribute__((unused))

View File

@@ -102,6 +102,7 @@ extern "C" {
#elif defined(_MSC_VER)
# define UTIL_STATIC static __inline
# pragma warning(disable : 4996) /* disable: C4996: 'strncpy': This function or variable may be unsafe. */
# pragma warning(disable : 4389) /* disable: C4389: '==' : signed/unsigned mismatch */
#else
# define UTIL_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
#endif

57
C/hashes/hash.h Normal file
View File

@@ -0,0 +1,57 @@
/*
* 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__
#include <string.h>
#include "../7zTypes.h"
#ifndef uint32_t
typedef UInt32 uint32_t;
#endif
#ifndef uint64_t
typedef UInt64 uint64_t;
#endif
#ifndef min
#define min(a,b) (((a)>(b))?(b):(a))
#endif
#endif /* __hash_h__ */

133
C/hashes/md2.c Normal file
View File

@@ -0,0 +1,133 @@
/*
* 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 "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, (int)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));
}

57
C/hashes/md2.h Normal file
View File

@@ -0,0 +1,57 @@
/*
* 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
#include "hash.h"
#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 */

264
C/hashes/md4.c Normal file
View File

@@ -0,0 +1,264 @@
/*
* 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 "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
/* 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 uint32_t cshift (uint32_t x, unsigned int n)
{
x = CRAYFIX(x);
return CRAYFIX((x << n) | (x >> (32 - n)));
}
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 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 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] += (unsigned int)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 *us = (struct x32*)m->save;
for(i = 0; i < 8; i++){
current[2*i+0] = swap_uint32_t(us[i].a);
current[2*i+1] = swap_uint32_t(us[i].b);
}
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
}

56
C/hashes/md4.h Normal file
View File

@@ -0,0 +1,56 @@
/*
* 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
#include "hash.h"
#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 */

288
C/hashes/md5.c Normal file
View File

@@ -0,0 +1,288 @@
/*
* 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 "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
/* 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 uint32_t cshift (uint32_t x, unsigned int n)
{
x = CRAYFIX(x);
return CRAYFIX((x << n) | (x >> (32 - n)));
}
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 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 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] += (unsigned int)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 *us = (struct x32*)m->save;
for(i = 0; i < 8; i++){
current[2*i+0] = swap_uint32_t(us[i].a);
current[2*i+1] = swap_uint32_t(us[i].b);
}
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
}

56
C/hashes/md5.h Normal file
View File

@@ -0,0 +1,56 @@
/*
* 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
#include "hash.h"
#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 */

68
C/hashes/sha.h Normal file
View File

@@ -0,0 +1,68 @@
/*
* 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
#include "hash.h"
/*
* SHA-2 512
*/
#define SHA512_DIGEST_LENGTH 64
struct hc_sha512state {
uint64_t sz[2];
uint64_t counter[8];
unsigned char save[128];
};
typedef struct hc_sha512state SHA512_CTX;
void SHA512_Init (SHA512_CTX *);
void SHA512_Update (SHA512_CTX *, const void *, size_t);
void SHA512_Final (void *, SHA512_CTX *);
#define SHA384_DIGEST_LENGTH 48
typedef struct hc_sha512state SHA384_CTX;
void SHA384_Init (SHA384_CTX *);
void SHA384_Update (SHA384_CTX *, const void *, size_t);
void SHA384_Final (void *, SHA384_CTX *);
#endif /* HEIM_SHA_H */

297
C/hashes/sha512.c Normal file
View File

@@ -0,0 +1,297 @@
/*
* Copyright (c) 2006, 2010 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "hash.h"
#include "sha.h"
#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
#define ROTR(x,n) (((x)>>(n)) | ((x) << (64 - (n))))
#define Sigma0(x) (ROTR(x,28) ^ ROTR(x,34) ^ ROTR(x,39))
#define Sigma1(x) (ROTR(x,14) ^ ROTR(x,18) ^ ROTR(x,41))
#define sigma0(x) (ROTR(x,1) ^ ROTR(x,8) ^ ((x)>>7))
#define sigma1(x) (ROTR(x,19) ^ ROTR(x,61) ^ ((x)>>6))
#define A m->counter[0]
#define B m->counter[1]
#define C m->counter[2]
#define D m->counter[3]
#define E m->counter[4]
#define F m->counter[5]
#define G m->counter[6]
#define H m->counter[7]
static uint64_t cshift64 (uint64_t x, unsigned int n)
{
return ((uint64_t)x << (uint64_t)n) | ((uint64_t)x >> ((uint64_t)64 - (uint64_t)n));
}
static const uint64_t constant_512[80] = {
0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL,
0xd807aa98a3030242ULL, 0x12835b0145706fbeULL,
0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL,
0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL,
0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL,
0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL,
0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL,
0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL,
0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
0x06ca6351e003826fULL, 0x142929670a0e6e70ULL,
0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL,
0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL,
0x81c2c92e47edaee6ULL, 0x92722c851482353bULL,
0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL,
0xd192e819d6ef5218ULL, 0xd69906245565a910ULL,
0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL,
0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL,
0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL,
0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL,
0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL,
0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL,
0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL,
0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL,
0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
0x28db77f523047d84ULL, 0x32caab7b40c72493ULL,
0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL,
0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
};
void
SHA512_Init (SHA512_CTX *m)
{
m->sz[0] = 0;
m->sz[1] = 0;
A = 0x6a09e667f3bcc908ULL;
B = 0xbb67ae8584caa73bULL;
C = 0x3c6ef372fe94f82bULL;
D = 0xa54ff53a5f1d36f1ULL;
E = 0x510e527fade682d1ULL;
F = 0x9b05688c2b3e6c1fULL;
G = 0x1f83d9abfb41bd6bULL;
H = 0x5be0cd19137e2179ULL;
}
static void
calc (SHA512_CTX *m, uint64_t *in)
{
uint64_t AA, BB, CC, DD, EE, FF, GG, HH;
uint64_t data[80];
int i;
AA = A;
BB = B;
CC = C;
DD = D;
EE = E;
FF = F;
GG = G;
HH = H;
for (i = 0; i < 16; ++i)
data[i] = in[i];
for (i = 16; i < 80; ++i)
data[i] = sigma1(data[i-2]) + data[i-7] +
sigma0(data[i-15]) + data[i - 16];
for (i = 0; i < 80; i++) {
uint64_t T1, T2;
T1 = HH + Sigma1(EE) + Ch(EE, FF, GG) + constant_512[i] + data[i];
T2 = Sigma0(AA) + Maj(AA,BB,CC);
HH = GG;
GG = FF;
FF = EE;
EE = DD + T1;
DD = CC;
CC = BB;
BB = AA;
AA = T1 + T2;
}
A += AA;
B += BB;
C += CC;
D += DD;
E += EE;
F += FF;
G += GG;
H += HH;
}
/*
* From `Performance analysis of MD5' by Joseph D. Touch <touch@isi.edu>
*/
#if !defined(WORDS_BIGENDIAN) || defined(_CRAY)
static uint64_t
swap_uint64_t (uint64_t t)
{
uint64_t temp;
temp = cshift64(t, 32);
temp = ((temp & 0xff00ff00ff00ff00ULL) >> 8) |
((temp & 0x00ff00ff00ff00ffULL) << 8);
return ((temp & 0xffff0000ffff0000ULL) >> 16) |
((temp & 0x0000ffff0000ffffULL) << 16);
}
struct x64{
uint64_t a;
uint64_t b;
};
#endif
void
SHA512_Update (SHA512_CTX *m, const void *v, size_t len)
{
const unsigned char *p = v;
size_t old_sz = (size_t)m->sz[0];
size_t offset;
m->sz[0] += len * 8;
if (m->sz[0] < old_sz)
++m->sz[1];
offset = (old_sz / 8) % 128;
while(len > 0){
size_t l = min(len, 128 - offset);
memcpy(m->save + offset, p, l);
offset += l;
p += l;
len -= l;
if(offset == 128){
#if !defined(WORDS_BIGENDIAN) || defined(_CRAY)
int i;
uint64_t current[16];
struct x64 *us = (struct x64*)m->save;
for(i = 0; i < 8; i++){
current[2*i+0] = swap_uint64_t(us[i].a);
current[2*i+1] = swap_uint64_t(us[i].b);
}
calc(m, current);
#else
calc(m, (uint64_t*)m->save);
#endif
offset = 0;
}
}
}
void
SHA512_Final (void *res, SHA512_CTX *m)
{
unsigned char zeros[128 + 16];
unsigned offset = (m->sz[0] / 8) % 128;
unsigned int dstart = (240 - offset - 1) % 128 + 1;
*zeros = 0x80;
memset (zeros + 1, 0, sizeof(zeros) - 1);
zeros[dstart+15] = (m->sz[0] >> 0) & 0xff;
zeros[dstart+14] = (m->sz[0] >> 8) & 0xff;
zeros[dstart+13] = (m->sz[0] >> 16) & 0xff;
zeros[dstart+12] = (m->sz[0] >> 24) & 0xff;
zeros[dstart+11] = (m->sz[0] >> 32) & 0xff;
zeros[dstart+10] = (m->sz[0] >> 40) & 0xff;
zeros[dstart+9] = (m->sz[0] >> 48) & 0xff;
zeros[dstart+8] = (m->sz[0] >> 56) & 0xff;
zeros[dstart+7] = (m->sz[1] >> 0) & 0xff;
zeros[dstart+6] = (m->sz[1] >> 8) & 0xff;
zeros[dstart+5] = (m->sz[1] >> 16) & 0xff;
zeros[dstart+4] = (m->sz[1] >> 24) & 0xff;
zeros[dstart+3] = (m->sz[1] >> 32) & 0xff;
zeros[dstart+2] = (m->sz[1] >> 40) & 0xff;
zeros[dstart+1] = (m->sz[1] >> 48) & 0xff;
zeros[dstart+0] = (m->sz[1] >> 56) & 0xff;
SHA512_Update (m, zeros, dstart + 16);
{
int i;
unsigned char *r = (unsigned char*)res;
for (i = 0; i < 8; ++i) {
r[8*i+7] = m->counter[i] & 0xFF;
r[8*i+6] = (m->counter[i] >> 8) & 0xFF;
r[8*i+5] = (m->counter[i] >> 16) & 0xFF;
r[8*i+4] = (m->counter[i] >> 24) & 0xFF;
r[8*i+3] = (m->counter[i] >> 32) & 0XFF;
r[8*i+2] = (m->counter[i] >> 40) & 0xFF;
r[8*i+1] = (m->counter[i] >> 48) & 0xFF;
r[8*i] = (m->counter[i] >> 56) & 0xFF;
}
}
}
void
SHA384_Init(SHA384_CTX *m)
{
m->sz[0] = 0;
m->sz[1] = 0;
A = 0xcbbb9d5dc1059ed8ULL;
B = 0x629a292a367cd507ULL;
C = 0x9159015a3070dd17ULL;
D = 0x152fecd8f70e5939ULL;
E = 0x67332667ffc00b31ULL;
F = 0x8eb44a8768581511ULL;
G = 0xdb0c2e0d64f98fa7ULL;
H = 0x47b5481dbefa4fa4ULL;
}
void
SHA384_Update (SHA384_CTX *m, const void *v, size_t len)
{
SHA512_Update(m, v, len);
}
void
SHA384_Final (void *res, SHA384_CTX *m)
{
unsigned char data[SHA512_DIGEST_LENGTH];
SHA512_Final(data, m);
memcpy(res, data, SHA384_DIGEST_LENGTH);
}

View File

@@ -267,7 +267,7 @@ static void *pt_compress(void *arg)
uint8_t *obuf = (uint8_t*)wl->out.buf + 16;
wl->out.size -= 16;
rv = BrotliEncoderCompress(ctx->level,
BROTLI_MAX_WINDOW_BITS,
BROTLI_LARGE_MAX_WINDOW_BITS,
BROTLI_MODE_GENERIC, in.size,
ibuf, &wl->out.size, obuf);

View File

@@ -28,6 +28,7 @@ OBJS = \
$(CRYPTO_OBJS) \
$(C_OBJS) \
$(BROTLI_OBJS) \
$(HASHES_OBJS) \
$(LIZARD_OBJS) \
$(LZ4_OBJS) \
$(LZ5_OBJS) \
@@ -278,6 +279,8 @@ $(FASTLZMA2_OBJS): ../../../../C/fast-lzma2/$(*B).c
$(COMPLB_O2)
{../../../../C/brotli}.c{$O}.obj::
$(COMPLB_O2)
{../../../../C/hashes}.c{$O}.obj::
$(COMPLB_O2)
{../../../../C/lizard}.c{$O}.obj::
$(COMPLB_O2)
{../../../../C/lz4}.c{$O}.obj::
@@ -289,6 +292,7 @@ $(FASTLZMA2_OBJS): ../../../../C/fast-lzma2/$(*B).c
{../../../../C/zstdmt}.c{$O}.obj::
$(COMPLB_O2) \
-I ../../../../C/brotli \
-I ../../../../C/hashes \
-I ../../../../C/lizard \
-I ../../../../C/lz4 \
-I ../../../../C/lz5 \

View File

@@ -3,6 +3,9 @@ COMMON_OBJS = \
$O\CrcReg.obj \
$O\DynLimBuf.obj \
$O\IntToString.obj \
$O\Md2Reg.obj \
$O\Md4Reg.obj \
$O\Md5Reg.obj \
$O\MyMap.obj \
$O\MyString.obj \
$O\MyVector.obj \
@@ -10,10 +13,14 @@ COMMON_OBJS = \
$O\NewHandler.obj \
$O\Sha1Reg.obj \
$O\Sha256Reg.obj \
$O\Sha384Reg.obj \
$O\Sha512Reg.obj \
$O\StringConvert.obj \
$O\StringToInt.obj \
$O\UTFConvert.obj \
$O\Wildcard.obj \
$O\XXH32Reg.obj \
$O\XXH64Reg.obj \
$O\XzCrc64Init.obj \
$O\XzCrc64Reg.obj \
@@ -249,6 +256,12 @@ CRYPTO_OBJS = \
$O\ZipCrypto.obj \
$O\ZipStrong.obj \
HASHES_OBJS = \
$O\md2.obj \
$O\md4.obj \
$O\md5.obj \
$O\sha512.obj \
C_OBJS = \
$O\7zBuf2.obj \
$O\7zStream.obj \

View File

@@ -3,6 +3,9 @@ COMMON_OBJS = \
$O\CrcReg.obj \
$O\DynLimBuf.obj \
$O\IntToString.obj \
$O\Md2Reg.obj \
$O\Md4Reg.obj \
$O\Md5Reg.obj \
$O\MyMap.obj \
$O\MyString.obj \
$O\MyVector.obj \
@@ -10,10 +13,14 @@ COMMON_OBJS = \
$O\NewHandler.obj \
$O\Sha1Reg.obj \
$O\Sha256Reg.obj \
$O\Sha384Reg.obj \
$O\Sha512Reg.obj \
$O\StringConvert.obj \
$O\StringToInt.obj \
$O\UTFConvert.obj \
$O\Wildcard.obj \
$O\XXH32Reg.obj \
$O\XXH64Reg.obj \
$O\XzCrc64Init.obj \
$O\XzCrc64Reg.obj \
@@ -249,6 +256,12 @@ CRYPTO_OBJS = \
$O\ZipCrypto.obj \
$O\ZipStrong.obj \
HASHES_OBJS = \
$O\md2.obj \
$O\md4.obj \
$O\md5.obj \
$O\sha512.obj \
C_OBJS = \
$O\7zBuf2.obj \
$O\7zStream.obj \

View File

@@ -1,7 +1,6 @@
PROG = 7z.dll
DEF_FILE = ../../Archive/Archive2.def
CFLAGS = $(CFLAGS) \
-DEXTERNAL_CODECS -DNEED_7ZIP_GUID -DZSTD_LEGACY_SUPPORT \
CFLAGS = $(CFLAGS) -DNEED_7ZIP_GUID -DEXTERNAL_CODECS -DZSTD_LEGACY_SUPPORT -DZSTD_MULTITHREAD
!IFNDEF UNDER_CE
CFLAGS = $(CFLAGS) -DNEED_7ZIP_GUID -D_7ZIP_LARGE_PAGES

View File

@@ -133,8 +133,8 @@ C_OBJS = \
!include "../../LzmaDec.mak"
COMPRESS_OBJS = $(COMPRESS_OBJS) \
$O\ZstdEncoder.obj \
$O\ZstdDecoder.obj \
$O\ZstdEncoder.obj \
$O\ZstdRegister.obj \
ZSTD_OBJS = \

View File

@@ -44,7 +44,6 @@ WIN_OBJS = \
$O\Shell.obj \
$O\System.obj \
$O\Synchronization.obj \
$O\System.obj \
$O\Window.obj \
WIN_CTRL_OBJS = \
@@ -152,8 +151,8 @@ C_OBJS = \
!include "../../LzmaDec.mak"
COMPRESS_OBJS = $(COMPRESS_OBJS) \
$O\ZstdEncoder.obj \
$O\ZstdDecoder.obj \
$O\ZstdEncoder.obj \
$O\ZstdRegister.obj \
ZSTD_OBJS = \

View File

@@ -102,5 +102,5 @@ void RegisterHasher(const CHasherInfo *hasher) throw();
static const CHasherInfo g_HasherInfo = { CreateHasherSpec, id, name, size }; \
struct REGISTER_HASHER_NAME(cls) { REGISTER_HASHER_NAME(cls)() { RegisterHasher(&g_HasherInfo); }}; \
static REGISTER_HASHER_NAME(cls) g_RegisterHasher;
#endif

View File

@@ -84,11 +84,6 @@ HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
ZSTD_resetDStream(_ctx);
}
// _processedOut += zOut.pos;
// RINOK(ReadStream(inStream, _srcBuf, &size));
// RINOK(WriteStream(outStream, _dstBuf, zOut.pos));
// RINOK(progress->SetRatioInfo(&_processedIn, &_processedOut));
zIn.src = _srcBuf;
zIn.size = _srcBufSize;
zIn.pos = 0;
@@ -141,10 +136,11 @@ HRESULT CDecoder::CodeSpec(ISequentialInStream * inStream,
result = ZSTD_resetDStream(_ctx);
if (ZSTD_isError(result))
return E_FAIL;
/* read next input, or eof */
break;
}
} /* for() decompress */
/* read next input */
srcBufLen = _srcBufSize;
RINOK(ReadStream(inStream, _srcBuf, &srcBufLen));
@@ -173,11 +169,6 @@ STDMETHODIMP CDecoder::SetInStream(ISequentialInStream * inStream)
return S_OK;
}
STDMETHODIMP CDecoder::SetNumberOfThreads(UInt32 /* numThreads */)
{
return S_OK;
}
STDMETHODIMP CDecoder::ReleaseInStream()
{
_inStream.Release();
@@ -185,6 +176,11 @@ STDMETHODIMP CDecoder::ReleaseInStream()
}
#endif
STDMETHODIMP CDecoder::SetNumberOfThreads(UInt32 /* numThreads */)
{
return S_OK;
}
HRESULT CDecoder::CodeResume(ISequentialOutStream * outStream, const UInt64 * outSize, ICompressProgressInfo * progress)
{
RINOK(SetOutStreamSizeResume(outSize));

View File

@@ -104,15 +104,19 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
if (!_dstBuf)
return E_OUTOFMEMORY;
/* setup level */
err = ZSTD_CCtx_setParameter(_ctx, ZSTD_p_compressionLevel, _props._level);
if (ZSTD_isError(err)) return E_FAIL;
/* setup thread count */
err = ZSTD_CCtx_setParameter(_ctx, ZSTD_p_nbWorkers, _numThreads);
if (ZSTD_isError(err)) return E_FAIL;
/* set the content size flag */
err = ZSTD_CCtx_setParameter(_ctx, ZSTD_p_contentSizeFlag, 1);
if (ZSTD_isError(err)) return E_FAIL;
/* todo: make this optional */
err = ZSTD_CCtx_setParameter(_ctx, ZSTD_p_enableLongDistanceMatching, 1);
if (ZSTD_isError(err)) return E_FAIL;
}

View File

@@ -221,11 +221,19 @@ struct CHashCommand
static const CHashCommand g_HashCommands[] =
{
{ CZipContextMenu::kHash_CRC32, "CRC-32", "CRC32" },
{ CZipContextMenu::kHash_CRC64, "CRC-64", "CRC64" },
{ CZipContextMenu::kHash_SHA1, "SHA-1", "SHA1" },
{ CZipContextMenu::kHash_SHA256, "SHA-256", "SHA256" },
{ CZipContextMenu::kHash_All, "*", "*" }
{ CZipContextMenu::kHash_CRC32, "CRC-32", "CRC32" },
{ CZipContextMenu::kHash_CRC64, "CRC-64", "CRC64" },
{ CZipContextMenu::kHash_XXH32, "XXH-32", "XXH32" },
{ CZipContextMenu::kHash_XXH64, "XXH-64", "XXH64" },
{ CZipContextMenu::kHash_MD5, "MD2", "MD2" },
{ CZipContextMenu::kHash_MD5, "MD4", "MD4" },
{ CZipContextMenu::kHash_MD5, "MD5", "MD5" },
{ CZipContextMenu::kHash_SHA1, "SHA-1", "SHA1" },
{ CZipContextMenu::kHash_SHA256, "SHA-256", "SHA256" },
{ CZipContextMenu::kHash_SHA256, "SHA-384", "SHA384" },
{ CZipContextMenu::kHash_SHA256, "SHA-512", "SHA512" },
{ CZipContextMenu::kHash_BLAKE2sp, "BLAKE2sp", "BLAKE2sp" },
{ CZipContextMenu::kHash_All, "*", "*" }
};
static int FindCommand(CZipContextMenu::ECommandInternalID &id)
@@ -926,8 +934,16 @@ STDMETHODIMP CZipContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO commandInfo)
case kHash_CRC32:
case kHash_CRC64:
case kHash_XXH32:
case kHash_XXH64:
case kHash_MD2:
case kHash_MD4:
case kHash_MD5:
case kHash_SHA1:
case kHash_SHA256:
case kHash_SHA384:
case kHash_SHA512:
case kHash_BLAKE2sp:
case kHash_All:
{
for (unsigned i = 0; i < ARRAY_SIZE(g_HashCommands); i++)

View File

@@ -34,8 +34,16 @@ public:
kCompressToZipEmail,
kHash_CRC32,
kHash_CRC64,
kHash_XXH32,
kHash_XXH64,
kHash_MD2,
kHash_MD4,
kHash_MD5,
kHash_SHA1,
kHash_SHA256,
kHash_SHA384,
kHash_SHA512,
kHash_BLAKE2sp,
kHash_All
};

View File

@@ -578,8 +578,16 @@ bool ExecuteFileCommand(int id)
case IDM_HASH_ALL: g_App.CalculateCrc("*"); break;
case IDM_CRC32: g_App.CalculateCrc("CRC32"); break;
case IDM_CRC64: g_App.CalculateCrc("CRC64"); break;
case IDM_SHA1: g_App.CalculateCrc("SHA1"); break;
case IDM_XXH32: g_App.CalculateCrc("XXH32"); break;
case IDM_XXH64: g_App.CalculateCrc("XXH64"); break;
case IDM_MD2: g_App.CalculateCrc("MD2"); break;
case IDM_MD4: g_App.CalculateCrc("MD4"); break;
case IDM_MD5: g_App.CalculateCrc("MD5"); break;
case IDM_SHA1: g_App.CalculateCrc("SHA1"); break;
case IDM_SHA256: g_App.CalculateCrc("SHA256"); break;
case IDM_SHA384: g_App.CalculateCrc("SHA384"); break;
case IDM_SHA512: g_App.CalculateCrc("SHA512"); break;
case IDM_BLAKE2sp: g_App.CalculateCrc("BLAKE2sp"); break;
case IDM_DIFF: g_App.DiffFiles(); break;
case IDM_SPLIT: g_App.Split(); break;

View File

@@ -23,8 +23,16 @@
#define IDM_HASH_ALL 101
#define IDM_CRC32 102
#define IDM_CRC64 103
#define IDM_SHA1 104
#define IDM_SHA256 105
#define IDM_XXH32 104
#define IDM_XXH64 105
#define IDM_MD2 106
#define IDM_MD4 107
#define IDM_MD5 108
#define IDM_SHA1 109
#define IDM_SHA256 110
#define IDM_SHA384 111
#define IDM_SHA512 112
#define IDM_BLAKE2sp 113
#define IDM_OPEN 540
#define IDM_OPEN_INSIDE 541

View File

@@ -40,8 +40,16 @@ BEGIN
BEGIN
MENUITEM "CRC-32", IDM_CRC32
MENUITEM "CRC-64", IDM_CRC64
MENUITEM "xxHash-32", IDM_XXH32
MENUITEM "xxHash-64", IDM_XXH64
MENUITEM "MD2", IDM_MD2
MENUITEM "MD4", IDM_MD4
MENUITEM "MD5", IDM_MD5
MENUITEM "SHA-1", IDM_SHA1
MENUITEM "SHA-256", IDM_SHA256
MENUITEM "SHA-384", IDM_SHA384
MENUITEM "SHA-512", IDM_SHA512
MENUITEM "Blake2sp", IDM_BLAKE2sp
MENUITEM "*", IDM_HASH_ALL
END
MENUITEM "Di&ff", IDM_DIFF

237
CPP/Common/HashesReg.cpp Normal file
View File

@@ -0,0 +1,237 @@
// XXH32Reg.cpp
#include "StdAfx.h"
#include "../../C/CpuArch.h"
#define XXH_STATIC_LINKING_ONLY
#include "../../C/zstd/xxhash.h"
#include "../../C/hashes/md2.h"
#include "../../C/hashes/md4.h"
#include "../../C/hashes/md5.h"
#include "../../C/hashes/sha.h"
#include "../Common/MyCom.h"
#include "../7zip/Common/RegisterCodec.h"
// XXH32
class CXXH32Hasher:
public IHasher,
public CMyUnknownImp
{
XXH32_state_t *_ctx;
Byte mtDummy[1 << 7];
public:
CXXH32Hasher() { _ctx = XXH32_createState(); }
~CXXH32Hasher() { XXH32_freeState(_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CXXH32Hasher::Init() throw()
{
XXH32_reset(_ctx, 0);
}
STDMETHODIMP_(void) CXXH32Hasher::Update(const void *data, UInt32 size) throw()
{
XXH32_update(_ctx, data, size);
}
STDMETHODIMP_(void) CXXH32Hasher::Final(Byte *digest) throw()
{
UInt32 val = XXH32_digest(_ctx);
SetUi32(digest, val);
}
REGISTER_HASHER(CXXH32Hasher, 0x203, "XXH32", 4)
// XXH64
class CXXH64Hasher:
public IHasher,
public CMyUnknownImp
{
XXH64_state_t *_ctx;
Byte mtDummy[1 << 7];
public:
CXXH64Hasher() { _ctx = XXH64_createState(); }
~CXXH64Hasher() { XXH64_freeState(_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CXXH64Hasher::Init() throw()
{
XXH64_reset(_ctx, 0);
}
STDMETHODIMP_(void) CXXH64Hasher::Update(const void *data, UInt32 size) throw()
{
XXH64_update(_ctx, data, size);
}
STDMETHODIMP_(void) CXXH64Hasher::Final(Byte *digest) throw()
{
UInt64 val = XXH64_digest(_ctx);
SetUi64(digest, val);
}
REGISTER_HASHER(CXXH64Hasher, 0x204, "XXH64", 8)
// MD2
class CMD2Hasher:
public IHasher,
public CMyUnknownImp
{
MD2_CTX _ctx;
Byte mtDummy[1 << 7];
public:
CMD2Hasher() { MD2_Init(&_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CMD2Hasher::Init() throw()
{
MD2_Init(&_ctx);
}
STDMETHODIMP_(void) CMD2Hasher::Update(const void *data, UInt32 size) throw()
{
MD2_Update(&_ctx, (const Byte *)data, size);
}
STDMETHODIMP_(void) CMD2Hasher::Final(Byte *digest) throw()
{
MD2_Final(digest, &_ctx);
}
REGISTER_HASHER(CMD2Hasher, 0x205, "MD2", MD2_DIGEST_LENGTH)
// MD4
class CMD4Hasher:
public IHasher,
public CMyUnknownImp
{
MD4_CTX _ctx;
Byte mtDummy[1 << 7];
public:
CMD4Hasher() { MD4_Init(&_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CMD4Hasher::Init() throw()
{
MD4_Init(&_ctx);
}
STDMETHODIMP_(void) CMD4Hasher::Update(const void *data, UInt32 size) throw()
{
MD4_Update(&_ctx, (const Byte *)data, size);
}
STDMETHODIMP_(void) CMD4Hasher::Final(Byte *digest) throw()
{
MD4_Final(digest, &_ctx);
}
REGISTER_HASHER(CMD4Hasher, 0x206, "MD4", MD4_DIGEST_LENGTH)
// MD5
class CMD5Hasher:
public IHasher,
public CMyUnknownImp
{
MD5_CTX _ctx;
Byte mtDummy[1 << 7];
public:
CMD5Hasher() { MD5_Init(&_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CMD5Hasher::Init() throw()
{
MD5_Init(&_ctx);
}
STDMETHODIMP_(void) CMD5Hasher::Update(const void *data, UInt32 size) throw()
{
MD5_Update(&_ctx, (const Byte *)data, size);
}
STDMETHODIMP_(void) CMD5Hasher::Final(Byte *digest) throw()
{
MD5_Final(digest, &_ctx);
}
REGISTER_HASHER(CMD5Hasher, 0x207, "MD5", MD5_DIGEST_LENGTH)
// SHA384
class CSHA384Hasher:
public IHasher,
public CMyUnknownImp
{
SHA384_CTX _ctx;
Byte mtDummy[1 << 7];
public:
CSHA384Hasher() { SHA384_Init(&_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CSHA384Hasher::Init() throw()
{
SHA384_Init(&_ctx);
}
STDMETHODIMP_(void) CSHA384Hasher::Update(const void *data, UInt32 size) throw()
{
SHA384_Update(&_ctx, (const Byte *)data, size);
}
STDMETHODIMP_(void) CSHA384Hasher::Final(Byte *digest) throw()
{
SHA384_Final(digest, &_ctx);
}
REGISTER_HASHER(CSHA384Hasher, 0x208, "SHA384", SHA384_DIGEST_LENGTH)
// SHA512
class CSHA512Hasher:
public IHasher,
public CMyUnknownImp
{
SHA512_CTX _ctx;
Byte mtDummy[1 << 7];
public:
CSHA512Hasher() { SHA512_Init(&_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CSHA512Hasher::Init() throw()
{
SHA512_Init(&_ctx);
}
STDMETHODIMP_(void) CSHA512Hasher::Update(const void *data, UInt32 size) throw()
{
SHA512_Update(&_ctx, (const Byte *)data, size);
}
STDMETHODIMP_(void) CSHA512Hasher::Final(Byte *digest) throw()
{
SHA512_Final(digest, &_ctx);
}
REGISTER_HASHER(CSHA512Hasher, 0x209, "SHA512", SHA512_DIGEST_LENGTH)

43
CPP/Common/Md2Reg.cpp Normal file
View File

@@ -0,0 +1,43 @@
// Md2Reg.cpp /TR 2018-11-02
#include "StdAfx.h"
#include "../../C/CpuArch.h"
EXTERN_C_BEGIN
#include "../../C/hashes/md2.h"
EXTERN_C_END
#include "../Common/MyCom.h"
#include "../7zip/Common/RegisterCodec.h"
// MD2
class CMD2Hasher:
public IHasher,
public CMyUnknownImp
{
MD2_CTX _ctx;
Byte mtDummy[1 << 7];
public:
CMD2Hasher() { MD2_Init(&_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CMD2Hasher::Init() throw()
{
MD2_Init(&_ctx);
}
STDMETHODIMP_(void) CMD2Hasher::Update(const void *data, UInt32 size) throw()
{
MD2_Update(&_ctx, (const Byte *)data, size);
}
STDMETHODIMP_(void) CMD2Hasher::Final(Byte *digest) throw()
{
MD2_Final(digest, &_ctx);
}
REGISTER_HASHER(CMD2Hasher, 0x205, "MD2", MD2_DIGEST_LENGTH)

43
CPP/Common/Md4Reg.cpp Normal file
View File

@@ -0,0 +1,43 @@
// Md4Reg.cpp /TR 2018-11-02
#include "StdAfx.h"
#include "../../C/CpuArch.h"
EXTERN_C_BEGIN
#include "../../C/hashes/md4.h"
EXTERN_C_END
#include "../Common/MyCom.h"
#include "../7zip/Common/RegisterCodec.h"
// MD4
class CMD4Hasher:
public IHasher,
public CMyUnknownImp
{
MD4_CTX _ctx;
Byte mtDummy[1 << 7];
public:
CMD4Hasher() { MD4_Init(&_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CMD4Hasher::Init() throw()
{
MD4_Init(&_ctx);
}
STDMETHODIMP_(void) CMD4Hasher::Update(const void *data, UInt32 size) throw()
{
MD4_Update(&_ctx, (const Byte *)data, size);
}
STDMETHODIMP_(void) CMD4Hasher::Final(Byte *digest) throw()
{
MD4_Final(digest, &_ctx);
}
REGISTER_HASHER(CMD4Hasher, 0x206, "MD4", MD4_DIGEST_LENGTH)

43
CPP/Common/Md5Reg.cpp Normal file
View File

@@ -0,0 +1,43 @@
// Md5Reg.cpp /TR 2018-11-02
#include "StdAfx.h"
#include "../../C/CpuArch.h"
EXTERN_C_BEGIN
#include "../../C/hashes/md5.h"
EXTERN_C_END
#include "../Common/MyCom.h"
#include "../7zip/Common/RegisterCodec.h"
// MD5
class CMD5Hasher:
public IHasher,
public CMyUnknownImp
{
MD5_CTX _ctx;
Byte mtDummy[1 << 7];
public:
CMD5Hasher() { MD5_Init(&_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CMD5Hasher::Init() throw()
{
MD5_Init(&_ctx);
}
STDMETHODIMP_(void) CMD5Hasher::Update(const void *data, UInt32 size) throw()
{
MD5_Update(&_ctx, (const Byte *)data, size);
}
STDMETHODIMP_(void) CMD5Hasher::Final(Byte *digest) throw()
{
MD5_Final(digest, &_ctx);
}
REGISTER_HASHER(CMD5Hasher, 0x207, "MD5", MD5_DIGEST_LENGTH)

43
CPP/Common/Sha384Reg.cpp Normal file
View File

@@ -0,0 +1,43 @@
// Sha384Reg.cpp /TR 2018-11-02
#include "StdAfx.h"
#include "../../C/CpuArch.h"
EXTERN_C_BEGIN
#include "../../C/hashes/sha.h"
EXTERN_C_END
#include "../Common/MyCom.h"
#include "../7zip/Common/RegisterCodec.h"
// SHA384
class CSHA384Hasher:
public IHasher,
public CMyUnknownImp
{
SHA384_CTX _ctx;
Byte mtDummy[1 << 7];
public:
CSHA384Hasher() { SHA384_Init(&_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CSHA384Hasher::Init() throw()
{
SHA384_Init(&_ctx);
}
STDMETHODIMP_(void) CSHA384Hasher::Update(const void *data, UInt32 size) throw()
{
SHA384_Update(&_ctx, (const Byte *)data, size);
}
STDMETHODIMP_(void) CSHA384Hasher::Final(Byte *digest) throw()
{
SHA384_Final(digest, &_ctx);
}
REGISTER_HASHER(CSHA384Hasher, 0x208, "SHA384", SHA384_DIGEST_LENGTH)

43
CPP/Common/Sha512Reg.cpp Normal file
View File

@@ -0,0 +1,43 @@
// Sha512Reg.cpp /TR 2018-11-02
#include "StdAfx.h"
#include "../../C/CpuArch.h"
EXTERN_C_BEGIN
#include "../../C/hashes/sha.h"
EXTERN_C_END
#include "../Common/MyCom.h"
#include "../7zip/Common/RegisterCodec.h"
// SHA512
class CSHA512Hasher:
public IHasher,
public CMyUnknownImp
{
SHA512_CTX _ctx;
Byte mtDummy[1 << 7];
public:
CSHA512Hasher() { SHA512_Init(&_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CSHA512Hasher::Init() throw()
{
SHA512_Init(&_ctx);
}
STDMETHODIMP_(void) CSHA512Hasher::Update(const void *data, UInt32 size) throw()
{
SHA512_Update(&_ctx, (const Byte *)data, size);
}
STDMETHODIMP_(void) CSHA512Hasher::Final(Byte *digest) throw()
{
SHA512_Final(digest, &_ctx);
}
REGISTER_HASHER(CSHA512Hasher, 0x209, "SHA512", SHA512_DIGEST_LENGTH)

45
CPP/Common/XXH32Reg.cpp Normal file
View File

@@ -0,0 +1,45 @@
// XXH32Reg.cpp /TR 2018-11-02
#include "StdAfx.h"
#include "../../C/CpuArch.h"
#define XXH_STATIC_LINKING_ONLY
#include "../../C/zstd/xxhash.h"
#include "../Common/MyCom.h"
#include "../7zip/Common/RegisterCodec.h"
// XXH32
class CXXH32Hasher:
public IHasher,
public CMyUnknownImp
{
XXH32_state_t *_ctx;
Byte mtDummy[1 << 7];
public:
CXXH32Hasher() { _ctx = XXH32_createState(); }
~CXXH32Hasher() { XXH32_freeState(_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CXXH32Hasher::Init() throw()
{
XXH32_reset(_ctx, 0);
}
STDMETHODIMP_(void) CXXH32Hasher::Update(const void *data, UInt32 size) throw()
{
XXH32_update(_ctx, data, size);
}
STDMETHODIMP_(void) CXXH32Hasher::Final(Byte *digest) throw()
{
UInt32 val = XXH32_digest(_ctx);
SetUi32(digest, val);
}
REGISTER_HASHER(CXXH32Hasher, 0x203, "XXH32", 4)

44
CPP/Common/XXH64Reg.cpp Normal file
View File

@@ -0,0 +1,44 @@
// XXH64Reg.cpp /TR 2018-11-02
#include "StdAfx.h"
#include "../../C/CpuArch.h"
#define XXH_STATIC_LINKING_ONLY
#include "../../C/zstd/xxhash.h"
#include "../Common/MyCom.h"
#include "../7zip/Common/RegisterCodec.h"
// XXH64
class CXXH64Hasher:
public IHasher,
public CMyUnknownImp
{
XXH64_state_t *_ctx;
Byte mtDummy[1 << 7];
public:
CXXH64Hasher() { _ctx = XXH64_createState(); }
~CXXH64Hasher() { XXH64_freeState(_ctx); }
MY_UNKNOWN_IMP1(IHasher)
INTERFACE_IHasher(;)
};
STDMETHODIMP_(void) CXXH64Hasher::Init() throw()
{
XXH64_reset(_ctx, 0);
}
STDMETHODIMP_(void) CXXH64Hasher::Update(const void *data, UInt32 size) throw()
{
XXH64_update(_ctx, data, size);
}
STDMETHODIMP_(void) CXXH64Hasher::Final(Byte *digest) throw()
{
UInt64 val = XXH64_digest(_ctx);
SetUi64(digest, val);
}
REGISTER_HASHER(CXXH64Hasher, 0x204, "XXH64", 8)

View File

@@ -1,9 +1,11 @@
@echo off
REM Microsoft Windows SDK 7.1 (VC=sdk71)
REM Microsoft Visual Studio 2010 (VC=10.0)
REM Microsoft Visual Studio 2012 (VC=11.0)
REM Microsoft Visual Studio 2013 (VC=12.0)
REM Microsoft Visual Studio 2015 (VC=14.0)
REM Microsoft Visual Studio 2017 (VC=15.0)
REM to many vcvarsall.cmd calls will blow it up!
set OPATH=%PATH%

View File

@@ -4,7 +4,7 @@ set ROOT=%cd%\7zip
if not defined OUTDIR set OUTDIR=%ROOT%\binIA64
mkdir %OUTDIR%
set OPTS=CPU=IA64 MY_STATIC_LINK=1 /NOLOGO
set OPTS=CPU=IA64 MY_STATIC_LINK=1 /NOLOGO /TP
set LFLAGS=/SUBSYSTEM:WINDOWS,"5.02"
cd %ROOT%\Bundles\Format7zExtract