[Hardware] matching unrolled RC5-72 core generator

John L. Bass jbass at dmsd.com
Sun Nov 26 16:49:00 EST 2006


Hi Guys,

This is a matching unrolled non-pipelined core generator.


Use with previous test bench to validate:
	cc     rc5-72gen-nonpipe.c   -o rc5-72gen-nonpipe
	./rc5-72gen-nonpipe > rc5-72core.h; rm -f rc5-72gen-nonpipe
	cc     rc5-72tb.c   -o rc5-72tb
	./rc5-72tb; rm -f rc5-72tb
	Core IS correct, latency=101

Again, test bench inserts a 100 cycle latency before correct key, so the
reported latency is 101 (one clock cycle per key tested).

Have fun,
John

--------------------------- rc5-72gen-nonpipe.c ----------------------------
/*
 * Construct unrolled RC5 key check engine
 * This may freely be used, as long as copyright notices are maintained per BSD licensing
 * John L. Bass, Copyright 2001
 */
main( )
{
	const unsigned int P = 0xB7E15163;
	const unsigned int Q = 0x9E3779B9;
	
	unsigned int S[26];
	unsigned int e, i, s, l;

	printf("/* John L. Bass, Copyright 2003 */\n\t{\n");
	for (s=0;s<(3*26);s++) {
            if((s%10) == 0) printf("\t\tunsigned int ");
            printf("S%02d",s);
            if((s%10) < 9 && s != 77) printf(", ");
            else printf(";\n");
        }

	printf("\n");
	for (s=0;s<(3*26+2);s++) {
            if((s%10) == 0) printf("\t\tunsigned int ");
            printf("L%02d",s);
            if((s%10) < 9 && s != 79) printf(", ");
            else printf(";\n");
        }

	printf("\n");
	for (s=0;s<(1*26+3);s++) {
            if((s%10) == 0) printf("\t\tunsigned int ");
            printf("E%02d",s);
            if((s%10) < 9 && s != 28) printf(", ");
            else printf(";\n");
        }

	printf("\n");

	/* round 0 - Key Expansion */
	S[0]= P;
	for (s=1;s<26;s++)
		S[s]= S[s-1] + Q;
	l=0;
	printf("\t\tL%02d = Key(%d);\n",l,l);l++;
	printf("\t\tL%02d = Key(%d);\n",l,l);l++;
	printf("\t\tL%02d = Key(%d);\n",l,l);l++;

	/* round 1 - Key Expansion */
	printf("\t\tS%02d = Rotl3(0x%08x);\n", 0,S[0]);
	printf("\t\tL%02d = Rotl(L%02d + S%02d, S%02d);\n", l,0,0,0);l++;

	for (s=1;s<(1*26);s++,l++)
	{
		printf("\t\tS%02d = Rotl3(0x%08x + S%02d + L%02d);\n", s,S[s],s-1,l-1);
		printf("\t\tL%02d = Rotl(L%02d + S%02d + L%02d, S%02d + L%02d);\n", l,l-3,s,l-1,s,l-1);
	}

	/* rounds 2,3 - Key Expansion*/
	for (;s<(3*26);s++,l++)
	{
		printf("\t\tS%02d = Rotl3(S%02d + S%02d + L%02d);\n", s,s-26,s-1,l-1);
		if(s != 77)
		printf("\t\tL%02d = Rotl(L%02d + S%02d + L%02d, S%02d + L%02d);\n", l,l-3,s,l-1,s,l-1);
	}

	/* round 3 - encrypt */
	printf("\n");
	for (s=52;s<(3*26);s++,l++)
	{
		if(s == 52)
		    printf("\t\tE%02d = Plain(0) + S%02d;\n",e=0,s);
		if(s == 53)
		    printf("\t\tE%02d = Plain(1) + S%02d;\n",++e,s);
		if(s > 53)
		printf("\t\tE%02d = Rotl(E%02d ^ E%02d, E%02d) + S%02d;\n",e, e-2,e-1,++e-1,s);
	}
	printf("\t\tE%02d = E%02d ^ Cipher(0);\n",e,++e-2);
	printf("\t\tE%02d = E%02d ^ Cipher(1);\n",e,++e-2);
	printf("\t\tMiss = E%02d & E%02d;\n",e-1,++e-2);
	printf("\t}\n");
        exit(0);
}

--------------------------- rc5-72core.h ----------------------------
/* John L. Bass, Copyright 2003 */
	{
		unsigned int S00, S01, S02, S03, S04, S05, S06, S07, S08, S09;
		unsigned int S10, S11, S12, S13, S14, S15, S16, S17, S18, S19;
		unsigned int S20, S21, S22, S23, S24, S25, S26, S27, S28, S29;
		unsigned int S30, S31, S32, S33, S34, S35, S36, S37, S38, S39;
		unsigned int S40, S41, S42, S43, S44, S45, S46, S47, S48, S49;
		unsigned int S50, S51, S52, S53, S54, S55, S56, S57, S58, S59;
		unsigned int S60, S61, S62, S63, S64, S65, S66, S67, S68, S69;
		unsigned int S70, S71, S72, S73, S74, S75, S76, S77;

		unsigned int L00, L01, L02, L03, L04, L05, L06, L07, L08, L09;
		unsigned int L10, L11, L12, L13, L14, L15, L16, L17, L18, L19;
		unsigned int L20, L21, L22, L23, L24, L25, L26, L27, L28, L29;
		unsigned int L30, L31, L32, L33, L34, L35, L36, L37, L38, L39;
		unsigned int L40, L41, L42, L43, L44, L45, L46, L47, L48, L49;
		unsigned int L50, L51, L52, L53, L54, L55, L56, L57, L58, L59;
		unsigned int L60, L61, L62, L63, L64, L65, L66, L67, L68, L69;
		unsigned int L70, L71, L72, L73, L74, L75, L76, L77, L78, L79;

		unsigned int E00, E01, E02, E03, E04, E05, E06, E07, E08, E09;
		unsigned int E10, E11, E12, E13, E14, E15, E16, E17, E18, E19;
		unsigned int E20, E21, E22, E23, E24, E25, E26, E27, E28;

		L00 = Key(0);
		L01 = Key(1);
		L02 = Key(2);
		S00 = Rotl3(0xb7e15163);
		L03 = Rotl(L00 + S00, S00);
		S01 = Rotl3(0x5618cb1c + S00 + L03);
		L04 = Rotl(L01 + S01 + L03, S01 + L03);
		S02 = Rotl3(0xf45044d5 + S01 + L04);
		L05 = Rotl(L02 + S02 + L04, S02 + L04);
		S03 = Rotl3(0x9287be8e + S02 + L05);
		L06 = Rotl(L03 + S03 + L05, S03 + L05);
		S04 = Rotl3(0x30bf3847 + S03 + L06);
		L07 = Rotl(L04 + S04 + L06, S04 + L06);
		S05 = Rotl3(0xcef6b200 + S04 + L07);
		L08 = Rotl(L05 + S05 + L07, S05 + L07);
		S06 = Rotl3(0x6d2e2bb9 + S05 + L08);
		L09 = Rotl(L06 + S06 + L08, S06 + L08);
		S07 = Rotl3(0x0b65a572 + S06 + L09);
		L10 = Rotl(L07 + S07 + L09, S07 + L09);
		S08 = Rotl3(0xa99d1f2b + S07 + L10);
		L11 = Rotl(L08 + S08 + L10, S08 + L10);
		S09 = Rotl3(0x47d498e4 + S08 + L11);
		L12 = Rotl(L09 + S09 + L11, S09 + L11);
		S10 = Rotl3(0xe60c129d + S09 + L12);
		L13 = Rotl(L10 + S10 + L12, S10 + L12);
		S11 = Rotl3(0x84438c56 + S10 + L13);
		L14 = Rotl(L11 + S11 + L13, S11 + L13);
		S12 = Rotl3(0x227b060f + S11 + L14);
		L15 = Rotl(L12 + S12 + L14, S12 + L14);
		S13 = Rotl3(0xc0b27fc8 + S12 + L15);
		L16 = Rotl(L13 + S13 + L15, S13 + L15);
		S14 = Rotl3(0x5ee9f981 + S13 + L16);
		L17 = Rotl(L14 + S14 + L16, S14 + L16);
		S15 = Rotl3(0xfd21733a + S14 + L17);
		L18 = Rotl(L15 + S15 + L17, S15 + L17);
		S16 = Rotl3(0x9b58ecf3 + S15 + L18);
		L19 = Rotl(L16 + S16 + L18, S16 + L18);
		S17 = Rotl3(0x399066ac + S16 + L19);
		L20 = Rotl(L17 + S17 + L19, S17 + L19);
		S18 = Rotl3(0xd7c7e065 + S17 + L20);
		L21 = Rotl(L18 + S18 + L20, S18 + L20);
		S19 = Rotl3(0x75ff5a1e + S18 + L21);
		L22 = Rotl(L19 + S19 + L21, S19 + L21);
		S20 = Rotl3(0x1436d3d7 + S19 + L22);
		L23 = Rotl(L20 + S20 + L22, S20 + L22);
		S21 = Rotl3(0xb26e4d90 + S20 + L23);
		L24 = Rotl(L21 + S21 + L23, S21 + L23);
		S22 = Rotl3(0x50a5c749 + S21 + L24);
		L25 = Rotl(L22 + S22 + L24, S22 + L24);
		S23 = Rotl3(0xeedd4102 + S22 + L25);
		L26 = Rotl(L23 + S23 + L25, S23 + L25);
		S24 = Rotl3(0x8d14babb + S23 + L26);
		L27 = Rotl(L24 + S24 + L26, S24 + L26);
		S25 = Rotl3(0x2b4c3474 + S24 + L27);
		L28 = Rotl(L25 + S25 + L27, S25 + L27);
		S26 = Rotl3(S00 + S25 + L28);
		L29 = Rotl(L26 + S26 + L28, S26 + L28);
		S27 = Rotl3(S01 + S26 + L29);
		L30 = Rotl(L27 + S27 + L29, S27 + L29);
		S28 = Rotl3(S02 + S27 + L30);
		L31 = Rotl(L28 + S28 + L30, S28 + L30);
		S29 = Rotl3(S03 + S28 + L31);
		L32 = Rotl(L29 + S29 + L31, S29 + L31);
		S30 = Rotl3(S04 + S29 + L32);
		L33 = Rotl(L30 + S30 + L32, S30 + L32);
		S31 = Rotl3(S05 + S30 + L33);
		L34 = Rotl(L31 + S31 + L33, S31 + L33);
		S32 = Rotl3(S06 + S31 + L34);
		L35 = Rotl(L32 + S32 + L34, S32 + L34);
		S33 = Rotl3(S07 + S32 + L35);
		L36 = Rotl(L33 + S33 + L35, S33 + L35);
		S34 = Rotl3(S08 + S33 + L36);
		L37 = Rotl(L34 + S34 + L36, S34 + L36);
		S35 = Rotl3(S09 + S34 + L37);
		L38 = Rotl(L35 + S35 + L37, S35 + L37);
		S36 = Rotl3(S10 + S35 + L38);
		L39 = Rotl(L36 + S36 + L38, S36 + L38);
		S37 = Rotl3(S11 + S36 + L39);
		L40 = Rotl(L37 + S37 + L39, S37 + L39);
		S38 = Rotl3(S12 + S37 + L40);
		L41 = Rotl(L38 + S38 + L40, S38 + L40);
		S39 = Rotl3(S13 + S38 + L41);
		L42 = Rotl(L39 + S39 + L41, S39 + L41);
		S40 = Rotl3(S14 + S39 + L42);
		L43 = Rotl(L40 + S40 + L42, S40 + L42);
		S41 = Rotl3(S15 + S40 + L43);
		L44 = Rotl(L41 + S41 + L43, S41 + L43);
		S42 = Rotl3(S16 + S41 + L44);
		L45 = Rotl(L42 + S42 + L44, S42 + L44);
		S43 = Rotl3(S17 + S42 + L45);
		L46 = Rotl(L43 + S43 + L45, S43 + L45);
		S44 = Rotl3(S18 + S43 + L46);
		L47 = Rotl(L44 + S44 + L46, S44 + L46);
		S45 = Rotl3(S19 + S44 + L47);
		L48 = Rotl(L45 + S45 + L47, S45 + L47);
		S46 = Rotl3(S20 + S45 + L48);
		L49 = Rotl(L46 + S46 + L48, S46 + L48);
		S47 = Rotl3(S21 + S46 + L49);
		L50 = Rotl(L47 + S47 + L49, S47 + L49);
		S48 = Rotl3(S22 + S47 + L50);
		L51 = Rotl(L48 + S48 + L50, S48 + L50);
		S49 = Rotl3(S23 + S48 + L51);
		L52 = Rotl(L49 + S49 + L51, S49 + L51);
		S50 = Rotl3(S24 + S49 + L52);
		L53 = Rotl(L50 + S50 + L52, S50 + L52);
		S51 = Rotl3(S25 + S50 + L53);
		L54 = Rotl(L51 + S51 + L53, S51 + L53);
		S52 = Rotl3(S26 + S51 + L54);
		L55 = Rotl(L52 + S52 + L54, S52 + L54);
		S53 = Rotl3(S27 + S52 + L55);
		L56 = Rotl(L53 + S53 + L55, S53 + L55);
		S54 = Rotl3(S28 + S53 + L56);
		L57 = Rotl(L54 + S54 + L56, S54 + L56);
		S55 = Rotl3(S29 + S54 + L57);
		L58 = Rotl(L55 + S55 + L57, S55 + L57);
		S56 = Rotl3(S30 + S55 + L58);
		L59 = Rotl(L56 + S56 + L58, S56 + L58);
		S57 = Rotl3(S31 + S56 + L59);
		L60 = Rotl(L57 + S57 + L59, S57 + L59);
		S58 = Rotl3(S32 + S57 + L60);
		L61 = Rotl(L58 + S58 + L60, S58 + L60);
		S59 = Rotl3(S33 + S58 + L61);
		L62 = Rotl(L59 + S59 + L61, S59 + L61);
		S60 = Rotl3(S34 + S59 + L62);
		L63 = Rotl(L60 + S60 + L62, S60 + L62);
		S61 = Rotl3(S35 + S60 + L63);
		L64 = Rotl(L61 + S61 + L63, S61 + L63);
		S62 = Rotl3(S36 + S61 + L64);
		L65 = Rotl(L62 + S62 + L64, S62 + L64);
		S63 = Rotl3(S37 + S62 + L65);
		L66 = Rotl(L63 + S63 + L65, S63 + L65);
		S64 = Rotl3(S38 + S63 + L66);
		L67 = Rotl(L64 + S64 + L66, S64 + L66);
		S65 = Rotl3(S39 + S64 + L67);
		L68 = Rotl(L65 + S65 + L67, S65 + L67);
		S66 = Rotl3(S40 + S65 + L68);
		L69 = Rotl(L66 + S66 + L68, S66 + L68);
		S67 = Rotl3(S41 + S66 + L69);
		L70 = Rotl(L67 + S67 + L69, S67 + L69);
		S68 = Rotl3(S42 + S67 + L70);
		L71 = Rotl(L68 + S68 + L70, S68 + L70);
		S69 = Rotl3(S43 + S68 + L71);
		L72 = Rotl(L69 + S69 + L71, S69 + L71);
		S70 = Rotl3(S44 + S69 + L72);
		L73 = Rotl(L70 + S70 + L72, S70 + L72);
		S71 = Rotl3(S45 + S70 + L73);
		L74 = Rotl(L71 + S71 + L73, S71 + L73);
		S72 = Rotl3(S46 + S71 + L74);
		L75 = Rotl(L72 + S72 + L74, S72 + L74);
		S73 = Rotl3(S47 + S72 + L75);
		L76 = Rotl(L73 + S73 + L75, S73 + L75);
		S74 = Rotl3(S48 + S73 + L76);
		L77 = Rotl(L74 + S74 + L76, S74 + L76);
		S75 = Rotl3(S49 + S74 + L77);
		L78 = Rotl(L75 + S75 + L77, S75 + L77);
		S76 = Rotl3(S50 + S75 + L78);
		L79 = Rotl(L76 + S76 + L78, S76 + L78);
		S77 = Rotl3(S51 + S76 + L79);

		E00 = Plain(0) + S52;
		E01 = Plain(1) + S53;
		E02 = Rotl(E00 ^ E01, E01) + S54;
		E03 = Rotl(E01 ^ E02, E02) + S55;
		E04 = Rotl(E02 ^ E03, E03) + S56;
		E05 = Rotl(E03 ^ E04, E04) + S57;
		E06 = Rotl(E04 ^ E05, E05) + S58;
		E07 = Rotl(E05 ^ E06, E06) + S59;
		E08 = Rotl(E06 ^ E07, E07) + S60;
		E09 = Rotl(E07 ^ E08, E08) + S61;
		E10 = Rotl(E08 ^ E09, E09) + S62;
		E11 = Rotl(E09 ^ E10, E10) + S63;
		E12 = Rotl(E10 ^ E11, E11) + S64;
		E13 = Rotl(E11 ^ E12, E12) + S65;
		E14 = Rotl(E12 ^ E13, E13) + S66;
		E15 = Rotl(E13 ^ E14, E14) + S67;
		E16 = Rotl(E14 ^ E15, E15) + S68;
		E17 = Rotl(E15 ^ E16, E16) + S69;
		E18 = Rotl(E16 ^ E17, E17) + S70;
		E19 = Rotl(E17 ^ E18, E18) + S71;
		E20 = Rotl(E18 ^ E19, E19) + S72;
		E21 = Rotl(E19 ^ E20, E20) + S73;
		E22 = Rotl(E20 ^ E21, E21) + S74;
		E23 = Rotl(E21 ^ E22, E22) + S75;
		E24 = Rotl(E22 ^ E23, E23) + S76;
		E25 = Rotl(E23 ^ E24, E24) + S77;
		E26 = E24 ^ Cipher(0);
		E27 = E25 ^ Cipher(1);
		Miss = E27 & E26;
	}


More information about the Hardware mailing list