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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Keyed 32-bit hash function using TEA in a Davis-Meyer function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *   H0 = Key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *   Hi = E Mi(Hi-1) + Hi-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * (see Applied Cryptography, 2nd edition, p448).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Jeremy Fitzhardinge <jeremy@zip.com.au> 1998
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Jeremy has agreed to the contents of reiserfs/README. -Hans
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Yura's function is added (04/07/2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "reiserfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define DELTA 0x9E3779B9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define FULLROUNDS 10		/* 32 is overkill, 16 is strong crypto */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define PARTROUNDS 6		/* 6 gets complete mixing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /* a, b, c, d - data; h0, h1 - accumulated hash */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define TEACORE(rounds)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		u32 sum = 0;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		int n = rounds;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		u32 b0, b1;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		b0 = h0;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		b1 = h1;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		do							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		{							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 			sum += DELTA;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 			b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		} while(--n);						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		h0 += b0;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		h1 += b1;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	} while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) u32 keyed_hash(const signed char *msg, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	u32 k[] = { 0x9464a485, 0x542e1a94, 0x3e846bff, 0xb75bcfc3 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u32 h0 = k[0], h1 = k[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	u32 a, b, c, d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	u32 pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	/*      assert(len >= 0 && len < 256); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	pad = (u32) len | ((u32) len << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	pad |= pad << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	while (len >= 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		a = (u32) msg[0] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		    (u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		b = (u32) msg[4] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		    (u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		c = (u32) msg[8] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		    (u32) msg[9] << 8 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		    (u32) msg[10] << 16 | (u32) msg[11] << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		d = (u32) msg[12] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		    (u32) msg[13] << 8 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		    (u32) msg[14] << 16 | (u32) msg[15] << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		TEACORE(PARTROUNDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		len -= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		msg += 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (len >= 12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		a = (u32) msg[0] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		    (u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		b = (u32) msg[4] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		    (u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		c = (u32) msg[8] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		    (u32) msg[9] << 8 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		    (u32) msg[10] << 16 | (u32) msg[11] << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		d = pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		for (i = 12; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			d <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			d |= msg[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	} else if (len >= 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		a = (u32) msg[0] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		    (u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		b = (u32) msg[4] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		    (u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		c = d = pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		for (i = 8; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			c <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			c |= msg[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	} else if (len >= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		a = (u32) msg[0] |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		    (u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		b = c = d = pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		for (i = 4; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			b <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			b |= msg[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		a = b = c = d = pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		for (i = 0; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			a <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			a |= msg[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	TEACORE(FULLROUNDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /*	return 0;*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return h0 ^ h1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * What follows in this file is copyright 2000 by Hans Reiser, and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * licensing of what follows is governed by reiserfs/README
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u32 yura_hash(const signed char *msg, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	int j, pow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	u32 a, c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	for (pow = 1, i = 1; i < len; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		pow = pow * 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (len == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		a = msg[0] - 48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		a = (msg[0] - 48) * pow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	for (i = 1; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		c = msg[i] - 48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		for (pow = 1, j = i; j < len - 1; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			pow = pow * 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		a = a + c * pow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	for (; i < 40; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		c = '0' - 48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		for (pow = 1, j = i; j < len - 1; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			pow = pow * 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		a = a + c * pow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	for (; i < 256; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		c = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		for (pow = 1, j = i; j < len - 1; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			pow = pow * 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		a = a + c * pow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	a = a << 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) u32 r5_hash(const signed char *msg, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	u32 a = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	while (*msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		a += *msg << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		a += *msg >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		a *= 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		msg++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }