01: package org.bouncycastle.crypto.engines;
02:
03: public class VMPCKSA3Engine extends VMPCEngine {
04: public String getAlgorithmName() {
05: return "VMPC-KSA3";
06: }
07:
08: protected void initKey(byte[] keyBytes, byte[] ivBytes) {
09: s = 0;
10: P = new byte[256];
11: for (int i = 0; i < 256; i++) {
12: P[i] = (byte) i;
13: }
14:
15: for (int m = 0; m < 768; m++) {
16: s = P[(s + P[m & 0xff] + keyBytes[m % keyBytes.length]) & 0xff];
17: byte temp = P[m & 0xff];
18: P[m & 0xff] = P[s & 0xff];
19: P[s & 0xff] = temp;
20: }
21:
22: for (int m = 0; m < 768; m++) {
23: s = P[(s + P[m & 0xff] + ivBytes[m % ivBytes.length]) & 0xff];
24: byte temp = P[m & 0xff];
25: P[m & 0xff] = P[s & 0xff];
26: P[s & 0xff] = temp;
27: }
28:
29: for (int m = 0; m < 768; m++) {
30: s = P[(s + P[m & 0xff] + keyBytes[m % keyBytes.length]) & 0xff];
31: byte temp = P[m & 0xff];
32: P[m & 0xff] = P[s & 0xff];
33: P[s & 0xff] = temp;
34: }
35:
36: n = 0;
37: }
38: }
|