2016-05-17 18:51:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2015-01-22 03:40:55 +00:00
|
|
|
*
|
2018-12-06 12:35:45 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 18:51:04 +00:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* From "Message Authentication" R.R. Jueneman, S.M. Matyas, C.H. Meyer IEEE
|
|
|
|
* Communications Magazine Sept 1985 Vol. 23 No. 9 p 29-40 This module in
|
|
|
|
* only based on the code in this paper and is almost definitely not the same
|
|
|
|
* as the MIT implementation.
|
1998-12-21 10:52:47 +00:00
|
|
|
*/
|
|
|
|
#include "des_locl.h"
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
#define Q_B0(a) (((DES_LONG)(a)))
|
|
|
|
#define Q_B1(a) (((DES_LONG)(a))<<8)
|
|
|
|
#define Q_B2(a) (((DES_LONG)(a))<<16)
|
|
|
|
#define Q_B3(a) (((DES_LONG)(a))<<24)
|
1998-12-21 10:52:47 +00:00
|
|
|
|
|
|
|
/* used to scramble things a bit */
|
|
|
|
/* Got the value MIT uses via brute force :-) 2/10/90 eay */
|
2015-01-22 03:40:55 +00:00
|
|
|
#define NOISE ((DES_LONG)83653421L)
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2001-10-24 21:21:12 +00:00
|
|
|
DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
|
2015-01-22 03:40:55 +00:00
|
|
|
long length, int out_count, DES_cblock *seed)
|
|
|
|
{
|
|
|
|
DES_LONG z0, z1, t0, t1;
|
|
|
|
int i;
|
|
|
|
long l;
|
|
|
|
const unsigned char *cp;
|
|
|
|
DES_LONG *lp;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (out_count < 1)
|
|
|
|
out_count = 1;
|
|
|
|
lp = (DES_LONG *)&(output[0])[0];
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
z0 = Q_B0((*seed)[0]) | Q_B1((*seed)[1]) | Q_B2((*seed)[2]) |
|
|
|
|
Q_B3((*seed)[3]);
|
|
|
|
z1 = Q_B0((*seed)[4]) | Q_B1((*seed)[5]) | Q_B2((*seed)[6]) |
|
|
|
|
Q_B3((*seed)[7]);
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
for (i = 0; ((i < 4) && (i < out_count)); i++) {
|
|
|
|
cp = input;
|
|
|
|
l = length;
|
|
|
|
while (l > 0) {
|
|
|
|
if (l > 1) {
|
|
|
|
t0 = (DES_LONG)(*(cp++));
|
|
|
|
t0 |= (DES_LONG)Q_B1(*(cp++));
|
|
|
|
l--;
|
|
|
|
} else
|
|
|
|
t0 = (DES_LONG)(*(cp++));
|
|
|
|
l--;
|
|
|
|
/* add */
|
|
|
|
t0 += z0;
|
|
|
|
t0 &= 0xffffffffL;
|
|
|
|
t1 = z1;
|
|
|
|
/* square, well sort of square */
|
|
|
|
z0 = ((((t0 * t0) & 0xffffffffL) + ((t1 * t1) & 0xffffffffL))
|
|
|
|
& 0xffffffffL) % 0x7fffffffL;
|
|
|
|
z1 = ((t0 * ((t1 + NOISE) & 0xffffffffL)) & 0xffffffffL) %
|
|
|
|
0x7fffffffL;
|
|
|
|
}
|
|
|
|
if (lp != NULL) {
|
|
|
|
/*
|
|
|
|
* The MIT library assumes that the checksum is composed of
|
|
|
|
* 2*out_count 32 bit ints
|
|
|
|
*/
|
|
|
|
*lp++ = z0;
|
|
|
|
*lp++ = z1;
|
|
|
|
}
|
|
|
|
}
|
2017-10-17 14:04:09 +00:00
|
|
|
return z0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|