* Encrypt some data using the supplied RC4 state buffer. * The input and output buffers may be the same buffer. * Since RC4 is a stream cypher, this function is used * for both encryption and decryption. */
| 85 | * for both encryption and decryption. |
| 86 | */ |
| 87 | void |
| 88 | rc4_crypt(struct rc4_state *const state, |
| 89 | const u_char *inbuf, u_char *outbuf, int buflen) |
| 90 | { |
| 91 | int i; |
| 92 | u_char j; |
| 93 | |
| 94 | for (i = 0; i < buflen; i++) { |
| 95 | |
| 96 | /* Update modification indicies */ |
| 97 | state->index1++; |
| 98 | state->index2 += state->perm[state->index1]; |
| 99 | |
| 100 | /* Modify permutation */ |
| 101 | swap_bytes(&state->perm[state->index1], |
| 102 | &state->perm[state->index2]); |
| 103 | |
| 104 | /* Encrypt/decrypt next byte */ |
| 105 | j = state->perm[state->index1] + state->perm[state->index2]; |
| 106 | outbuf[i] = inbuf[i] ^ state->perm[j]; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | static int |
| 111 | rc4_modevent(module_t mod, int type, void *unused) |
no test coverage detected