Spritz (RC4) for different N

Hello everybody,

I try to run the algorithm injection (successor RC4) with N = 8 (or different N). Property here already the appropriate functions with mod extended.
Would anyone know what I have to pay attention. and how would I have to change the functions Absorb, AbsorbByte and AbsorbNibble?

Thanks in advance for your assistance.

https://people.csail.mit.edu/rivest/pubs/RS14.pdf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  void Spritz::spritz_absorb_stop(State *state)
{
	unsigned char mod1 = getN();

	if (state->a == getN() / 2) {
		spritz_shuffle(state);
	}
	state->a++;
	state->a = state->a % mod1;
}

void Spritz::spritz_absorb_nibble(State *state, const unsigned char x)
{
	
	unsigned char y;
	unsigned char mod1 = getN();

	if (state->a == getN() / 2) {
		spritz_shuffle(state);
	}
	y = getN() / 2 + x;
	y = y % mod1;

	std::swap( state->s[state->a], state->s[y] );

	

	state->a++;
	state->a = state->a % mod1;
	
}

void Spritz::spritz_absorb_byte(State *state, const unsigned char b)
{

	if ( getN() == 4 )
	{
		unsigned char low  = ( b & 1 );
		unsigned char high = ( b >> 1 );
		spritz_absorb_nibble(state, low  );
		spritz_absorb_nibble(state, high );
	}
	else if ( getN() == 6 )
	{
		assert(false);
		spritz_absorb_nibble(state, ( b % m_D ));
		spritz_absorb_nibble(state, 
			( static_cast<unsigned char>( static_cast<float>(b) / static_cast<float>(m_D) ) ) );
	}
	else if ( getN() == 8 )
	{
		spritz_absorb_nibble(state, ( b & 3 ));
		spritz_absorb_nibble(state, ( b >> 2 ));
	}
	else
		assert(false);
}

void Spritz::spritz_absorb(State *state, const unsigned char *msg, size_t length)
{
	size_t v;

	for (v = 0; v < length; v++) {
		spritz_absorb_byte(state, msg[v]);
	}
}
Topic archived. No new replies allowed.