11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ci * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. 31cb0ef41Sopenharmony_ci * 41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 51cb0ef41Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at 71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html 81cb0ef41Sopenharmony_ci */ 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci/* 111cb0ef41Sopenharmony_ci * From "Message Authentication" R.R. Jueneman, S.M. Matyas, C.H. Meyer IEEE 121cb0ef41Sopenharmony_ci * Communications Magazine Sept 1985 Vol. 23 No. 9 p 29-40 This module in 131cb0ef41Sopenharmony_ci * only based on the code in this paper and is almost definitely not the same 141cb0ef41Sopenharmony_ci * as the MIT implementation. 151cb0ef41Sopenharmony_ci */ 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci/* 181cb0ef41Sopenharmony_ci * DES low level APIs are deprecated for public use, but still ok for internal 191cb0ef41Sopenharmony_ci * use. 201cb0ef41Sopenharmony_ci */ 211cb0ef41Sopenharmony_ci#include "internal/deprecated.h" 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci#include "des_local.h" 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci#define Q_B0(a) (((DES_LONG)(a))) 261cb0ef41Sopenharmony_ci#define Q_B1(a) (((DES_LONG)(a))<<8) 271cb0ef41Sopenharmony_ci#define Q_B2(a) (((DES_LONG)(a))<<16) 281cb0ef41Sopenharmony_ci#define Q_B3(a) (((DES_LONG)(a))<<24) 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci/* used to scramble things a bit */ 311cb0ef41Sopenharmony_ci/* Got the value MIT uses via brute force :-) 2/10/90 eay */ 321cb0ef41Sopenharmony_ci#define NOISE ((DES_LONG)83653421L) 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ciDES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[], 351cb0ef41Sopenharmony_ci long length, int out_count, DES_cblock *seed) 361cb0ef41Sopenharmony_ci{ 371cb0ef41Sopenharmony_ci DES_LONG z0, z1, t0, t1; 381cb0ef41Sopenharmony_ci int i; 391cb0ef41Sopenharmony_ci long l; 401cb0ef41Sopenharmony_ci const unsigned char *cp; 411cb0ef41Sopenharmony_ci DES_LONG *lp; 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci if (out_count < 1) 441cb0ef41Sopenharmony_ci out_count = 1; 451cb0ef41Sopenharmony_ci lp = (DES_LONG *)&(output[0])[0]; 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci z0 = Q_B0((*seed)[0]) | Q_B1((*seed)[1]) | Q_B2((*seed)[2]) | 481cb0ef41Sopenharmony_ci Q_B3((*seed)[3]); 491cb0ef41Sopenharmony_ci z1 = Q_B0((*seed)[4]) | Q_B1((*seed)[5]) | Q_B2((*seed)[6]) | 501cb0ef41Sopenharmony_ci Q_B3((*seed)[7]); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci for (i = 0; ((i < 4) && (i < out_count)); i++) { 531cb0ef41Sopenharmony_ci cp = input; 541cb0ef41Sopenharmony_ci l = length; 551cb0ef41Sopenharmony_ci while (l > 0) { 561cb0ef41Sopenharmony_ci if (l > 1) { 571cb0ef41Sopenharmony_ci t0 = (DES_LONG)(*(cp++)); 581cb0ef41Sopenharmony_ci t0 |= (DES_LONG)Q_B1(*(cp++)); 591cb0ef41Sopenharmony_ci l--; 601cb0ef41Sopenharmony_ci } else 611cb0ef41Sopenharmony_ci t0 = (DES_LONG)(*(cp++)); 621cb0ef41Sopenharmony_ci l--; 631cb0ef41Sopenharmony_ci /* add */ 641cb0ef41Sopenharmony_ci t0 += z0; 651cb0ef41Sopenharmony_ci t0 &= 0xffffffffL; 661cb0ef41Sopenharmony_ci t1 = z1; 671cb0ef41Sopenharmony_ci /* square, well sort of square */ 681cb0ef41Sopenharmony_ci z0 = ((((t0 * t0) & 0xffffffffL) + ((t1 * t1) & 0xffffffffL)) 691cb0ef41Sopenharmony_ci & 0xffffffffL) % 0x7fffffffL; 701cb0ef41Sopenharmony_ci z1 = ((t0 * ((t1 + NOISE) & 0xffffffffL)) & 0xffffffffL) % 711cb0ef41Sopenharmony_ci 0x7fffffffL; 721cb0ef41Sopenharmony_ci } 731cb0ef41Sopenharmony_ci if (lp != NULL) { 741cb0ef41Sopenharmony_ci /* 751cb0ef41Sopenharmony_ci * The MIT library assumes that the checksum is composed of 761cb0ef41Sopenharmony_ci * 2*out_count 32 bit ints 771cb0ef41Sopenharmony_ci */ 781cb0ef41Sopenharmony_ci *lp++ = z0; 791cb0ef41Sopenharmony_ci *lp++ = z1; 801cb0ef41Sopenharmony_ci } 811cb0ef41Sopenharmony_ci } 821cb0ef41Sopenharmony_ci return z0; 831cb0ef41Sopenharmony_ci} 84