Add pointers to SHA1 and SHA256 implementation functions

These pointers will be required in next commits
where subroutines with new instructions are introduced.
Depending on CPUID dynamic check, pointers will refer to old
SW-only implementations or to new instructions subroutines
This commit is contained in:
Pavel I. Kryukov 2018-02-11 13:40:24 +03:00 коммит произвёл Simon Tatham
Родитель 5a38b293bd
Коммит 59e2334029
3 изменённых файлов: 23 добавлений и 6 удалений

6
ssh.h
Просмотреть файл

@ -258,11 +258,12 @@ void hmacmd5_key(void *handle, void const *key, int len);
void hmacmd5_do_hmac(void *handle, unsigned char const *blk, int len,
unsigned char *hmac);
typedef struct {
typedef struct SHA_State {
uint32 h[5];
unsigned char block[64];
int blkused;
uint32 lenhi, lenlo;
void (*sha1)(struct SHA_State * s, const unsigned char *p, int len);
} SHA_State;
void SHA_Init(SHA_State * s);
void SHA_Bytes(SHA_State * s, const void *p, int len);
@ -271,11 +272,12 @@ void SHA_Simple(const void *p, int len, unsigned char *output);
void hmac_sha1_simple(void *key, int keylen, void *data, int datalen,
unsigned char *output);
typedef struct {
typedef struct SHA256_State {
uint32 h[8];
unsigned char block[64];
int blkused;
uint32 lenhi, lenlo;
void (*sha256)(struct SHA256_State * s, const unsigned char *p, int len);
} SHA256_State;
void SHA256_Init(SHA256_State * s);
void SHA256_Bytes(SHA256_State * s, const void *p, int len);

Просмотреть файл

@ -19,6 +19,8 @@
#define smallsigma0(x) ( ror((x),7) ^ ror((x),18) ^ shr((x),3) )
#define smallsigma1(x) ( ror((x),17) ^ ror((x),19) ^ shr((x),10) )
static void SHA256_sw(SHA256_State *s, const unsigned char *q, int len);
void SHA256_Core_Init(SHA256_State *s) {
s->h[0] = 0x6a09e667;
s->h[1] = 0xbb67ae85;
@ -97,19 +99,24 @@ void SHA256_Init(SHA256_State *s) {
SHA256_Core_Init(s);
s->blkused = 0;
s->lenhi = s->lenlo = 0;
s->sha256 = &SHA256_sw;
}
void SHA256_Bytes(SHA256_State *s, const void *p, int len) {
unsigned char *q = (unsigned char *)p;
uint32 wordblock[16];
uint32 lenw = len;
int i;
/*
* Update the length field.
*/
s->lenlo += lenw;
s->lenhi += (s->lenlo < lenw);
(*(s->sha256))(s, q, len);
}
static void SHA256_sw(SHA256_State *s, const unsigned char *q, int len) {
uint32 wordblock[16];
int i;
if (s->blkused && s->blkused+len < BLKSIZE) {
/*

Просмотреть файл

@ -13,6 +13,8 @@
#define rol(x,y) ( ((x) << (y)) | (((uint32)x) >> (32-y)) )
static void sha1_sw(SHA_State * s, const unsigned char *q, int len);
static void SHA_Core_Init(uint32 h[5])
{
h[0] = 0x67452301;
@ -124,20 +126,26 @@ void SHA_Init(SHA_State * s)
SHA_Core_Init(s->h);
s->blkused = 0;
s->lenhi = s->lenlo = 0;
s->sha1 = &sha1_sw;
}
void SHA_Bytes(SHA_State * s, const void *p, int len)
{
const unsigned char *q = (const unsigned char *) p;
uint32 wordblock[16];
uint32 lenw = len;
int i;
/*
* Update the length field.
*/
s->lenlo += lenw;
s->lenhi += (s->lenlo < lenw);
(*(s->sha1))(s, q, len);
}
static void sha1_sw(SHA_State * s, const unsigned char *q, int len)
{
uint32 wordblock[16];
int i;
if (s->blkused && s->blkused + len < 64) {
/*