Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) #include <netinet/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifdef __sun__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <inttypes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <stdint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "modpost.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Stolen form Cryptographic API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * MD4 Message Digest Algorithm (RFC1320).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * Implementation derived from Andrew Tridgell and Steve French's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * CIFS MD4 implementation, and the cryptoapi implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * originally based on the public domain implementation written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * by Colin Plumb in 1993.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * Copyright (c) Andrew Tridgell 1997-1998.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * Modified by Steve French (sfrench@us.ibm.com) 2002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * Copyright (c) Cryptoapi developers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * Copyright (c) 2002 David S. Miller (davem@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * the Free Software Foundation; either version 2 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define MD4_DIGEST_SIZE		16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define MD4_HMAC_BLOCK_SIZE	64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define MD4_BLOCK_WORDS		16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define MD4_HASH_WORDS		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) struct md4_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	uint32_t hash[MD4_HASH_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	uint32_t block[MD4_BLOCK_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	uint64_t byte_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static inline uint32_t lshift(uint32_t x, unsigned int s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	x &= 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static inline uint32_t F(uint32_t x, uint32_t y, uint32_t z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	return (x & y) | ((~x) & z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static inline uint32_t G(uint32_t x, uint32_t y, uint32_t z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	return (x & y) | (x & z) | (y & z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static inline uint32_t H(uint32_t x, uint32_t y, uint32_t z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return x ^ y ^ z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (uint32_t)0x5A827999,s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (uint32_t)0x6ED9EBA1,s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) /* XXX: this stuff can be optimized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static inline void le32_to_cpu_array(uint32_t *buf, unsigned int words)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	while (words--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		*buf = ntohl(*buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static inline void cpu_to_le32_array(uint32_t *buf, unsigned int words)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	while (words--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		*buf = htonl(*buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static void md4_transform(uint32_t *hash, uint32_t const *in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	uint32_t a, b, c, d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	a = hash[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	b = hash[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	c = hash[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	d = hash[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	ROUND1(a, b, c, d, in[0], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	ROUND1(d, a, b, c, in[1], 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	ROUND1(c, d, a, b, in[2], 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	ROUND1(b, c, d, a, in[3], 19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	ROUND1(a, b, c, d, in[4], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	ROUND1(d, a, b, c, in[5], 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	ROUND1(c, d, a, b, in[6], 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	ROUND1(b, c, d, a, in[7], 19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	ROUND1(a, b, c, d, in[8], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	ROUND1(d, a, b, c, in[9], 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	ROUND1(c, d, a, b, in[10], 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	ROUND1(b, c, d, a, in[11], 19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	ROUND1(a, b, c, d, in[12], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	ROUND1(d, a, b, c, in[13], 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	ROUND1(c, d, a, b, in[14], 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	ROUND1(b, c, d, a, in[15], 19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	ROUND2(a, b, c, d,in[ 0], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	ROUND2(d, a, b, c, in[4], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	ROUND2(c, d, a, b, in[8], 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	ROUND2(b, c, d, a, in[12], 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	ROUND2(a, b, c, d, in[1], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	ROUND2(d, a, b, c, in[5], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	ROUND2(c, d, a, b, in[9], 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	ROUND2(b, c, d, a, in[13], 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	ROUND2(a, b, c, d, in[2], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	ROUND2(d, a, b, c, in[6], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	ROUND2(c, d, a, b, in[10], 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	ROUND2(b, c, d, a, in[14], 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	ROUND2(a, b, c, d, in[3], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	ROUND2(d, a, b, c, in[7], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	ROUND2(c, d, a, b, in[11], 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	ROUND2(b, c, d, a, in[15], 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	ROUND3(a, b, c, d,in[ 0], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	ROUND3(d, a, b, c, in[8], 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ROUND3(c, d, a, b, in[4], 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	ROUND3(b, c, d, a, in[12], 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	ROUND3(a, b, c, d, in[2], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	ROUND3(d, a, b, c, in[10], 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	ROUND3(c, d, a, b, in[6], 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	ROUND3(b, c, d, a, in[14], 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	ROUND3(a, b, c, d, in[1], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	ROUND3(d, a, b, c, in[9], 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	ROUND3(c, d, a, b, in[5], 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	ROUND3(b, c, d, a, in[13], 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	ROUND3(a, b, c, d, in[3], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	ROUND3(d, a, b, c, in[11], 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	ROUND3(c, d, a, b, in[7], 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	ROUND3(b, c, d, a, in[15], 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	hash[0] += a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	hash[1] += b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	hash[2] += c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	hash[3] += d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static inline void md4_transform_helper(struct md4_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(uint32_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	md4_transform(ctx->hash, ctx->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static void md4_init(struct md4_ctx *mctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	mctx->hash[0] = 0x67452301;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	mctx->hash[1] = 0xefcdab89;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	mctx->hash[2] = 0x98badcfe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	mctx->hash[3] = 0x10325476;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	mctx->byte_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static void md4_update(struct md4_ctx *mctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		       const unsigned char *data, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	const uint32_t avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	mctx->byte_count += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (avail > len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		       data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	       data, avail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	md4_transform_helper(mctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	data += avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	len -= avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	while (len >= sizeof(mctx->block)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		memcpy(mctx->block, data, sizeof(mctx->block));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		md4_transform_helper(mctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		data += sizeof(mctx->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		len -= sizeof(mctx->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	memcpy(mctx->block, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static void md4_final_ascii(struct md4_ctx *mctx, char *out, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	const unsigned int offset = mctx->byte_count & 0x3f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	char *p = (char *)mctx->block + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	int padding = 56 - (offset + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	*p++ = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (padding < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		memset(p, 0x00, padding + sizeof (uint64_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		md4_transform_helper(mctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		p = (char *)mctx->block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		padding = 56;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	memset(p, 0, padding);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	mctx->block[14] = mctx->byte_count << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	mctx->block[15] = mctx->byte_count >> 29;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	le32_to_cpu_array(mctx->block, (sizeof(mctx->block) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			  sizeof(uint64_t)) / sizeof(uint32_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	md4_transform(mctx->hash, mctx->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(uint32_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	snprintf(out, len, "%08X%08X%08X%08X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		 mctx->hash[0], mctx->hash[1], mctx->hash[2], mctx->hash[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static inline void add_char(unsigned char c, struct md4_ctx *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	md4_update(md, &c, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static int parse_string(const char *file, unsigned long len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			struct md4_ctx *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	add_char(file[0], md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	for (i = 1; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		add_char(file[i], md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		if (file[i] == '"' && file[i-1] != '\\')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static int parse_comment(const char *file, unsigned long len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	for (i = 2; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		if (file[i-1] == '*' && file[i] == '/')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /* FIXME: Handle .s files differently (eg. # starts comments) --RR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int parse_file(const char *fname, struct md4_ctx *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	char *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	unsigned long i, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	file = read_text_file(fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	len = strlen(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	for (i = 0; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		/* Collapse and ignore \ and CR. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		if (file[i] == '\\' && (i+1 < len) && file[i+1] == '\n') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		/* Ignore whitespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		if (isspace(file[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		/* Handle strings as whole units */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		if (file[i] == '"') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			i += parse_string(file+i, len - i, md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		/* Comments: ignore */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		if (file[i] == '/' && file[i+1] == '*') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			i += parse_comment(file+i, len - i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		add_char(file[i], md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	free(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* Check whether the file is a static library or not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static int is_static_library(const char *objfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	int len = strlen(objfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (objfile[len - 2] == '.' && objfile[len - 1] == 'a')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /* We have dir/file.o.  Open dir/.file.o.cmd, look for source_ and deps_ line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * to figure out source files. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static int parse_source_files(const char *objfile, struct md4_ctx *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	char *cmd, *file, *line, *dir, *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	const char *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	int dirlen, ret = 0, check_files = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	cmd = NOFAIL(malloc(strlen(objfile) + sizeof("..cmd")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	base = strrchr(objfile, '/');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		base++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		dirlen = base - objfile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		sprintf(cmd, "%.*s.%s.cmd", dirlen, objfile, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		dirlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		sprintf(cmd, ".%s.cmd", objfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	dir = NOFAIL(malloc(dirlen + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	strncpy(dir, objfile, dirlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	dir[dirlen] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	file = read_text_file(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	pos = file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	/* Sum all files in the same dir or subdirs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	while ((line = get_line(&pos))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		char* p = line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		if (strncmp(line, "source_", sizeof("source_")-1) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			p = strrchr(line, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			if (!p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 				warn("malformed line: %s\n", line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 				goto out_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			if (!parse_file(p, md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 				warn("could not open %s: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 				     p, strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 				goto out_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		if (strncmp(line, "deps_", sizeof("deps_")-1) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			check_files = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		if (!check_files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		/* Continue until line does not end with '\' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		if ( *(p + strlen(p)-1) != '\\')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		/* Terminate line at first space, to get rid of final ' \' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		while (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			if (isspace(*p)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 				*p = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		/* Check if this file is in same dir as objfile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		if ((strstr(line, dir)+strlen(dir)-1) == strrchr(line, '/')) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 			if (!parse_file(line, md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 				warn("could not open %s: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 				     line, strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 				goto out_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	/* Everyone parsed OK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) out_file:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	free(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	free(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	free(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /* Calc and record src checksum. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) void get_src_version(const char *modname, char sum[], unsigned sumlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	char *buf, *pos, *firstline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	struct md4_ctx md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	char *fname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	char filelist[PATH_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	int postfix_len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (strends(modname, ".lto.o"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		postfix_len = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	/* objects for a module are listed in the first line of *.mod file. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	snprintf(filelist, sizeof(filelist), "%.*smod",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		 (int)strlen(modname) - postfix_len, modname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	buf = read_text_file(filelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	pos = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	firstline = get_line(&pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	if (!firstline) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		warn("bad ending versions file for %s\n", modname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	md4_init(&md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	while ((fname = strsep(&firstline, " "))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		if (!*fname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		if (!(is_static_library(fname)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 				!parse_source_files(fname, &md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 			goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	md4_final_ascii(&md, sum, sumlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	free(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }