MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rc4_init

Function rc4_init

freebsd/crypto/rc4/rc4.c:60–79  ·  view source on GitHub ↗

* Initialize an RC4 state buffer using the supplied key, * which can have arbitrary length. */

Source from the content-addressed store, hash-verified

58 * which can have arbitrary length.
59 */
60void
61rc4_init(struct rc4_state *const state, const u_char *key, int keylen)
62{
63 u_char j;
64 int i, k;
65
66 /* Initialize state with identity permutation */
67 for (i = 0; i < 256; i++)
68 state->perm[i] = (u_char)i;
69 state->index1 = 0;
70 state->index2 = 0;
71
72 /* Randomize the permutation using key data */
73 for (j = i = k = 0; i < 256; i++) {
74 j += state->perm[i] + key[k];
75 swap_bytes(&state->perm[i], &state->perm[j]);
76 if (++k >= keylen)
77 k = 0;
78 }
79}
80
81/*
82 * Encrypt some data using the supplied RC4 state buffer.

Callers 5

ng_mppc_rcvmsgFunction · 0.85
ng_mppc_compressFunction · 0.85
ng_mppc_decompressFunction · 0.85
ng_mppc_reset_reqFunction · 0.85
ng_mppc_updatekeyFunction · 0.85

Calls 1

swap_bytesFunction · 0.85

Tested by

no test coverage detected