~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/fortcrypt/swfort/swfalg.c

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The contents of this file are subject to the Mozilla Public
 
3
 * License Version 1.1 (the "License"); you may not use this file
 
4
 * except in compliance with the License. You may obtain a copy of
 
5
 * the License at http://www.mozilla.org/MPL/
 
6
 * 
 
7
 * Software distributed under the License is distributed on an "AS
 
8
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
9
 * implied. See the License for the specific language governing
 
10
 * rights and limitations under the License.
 
11
 * 
 
12
 * The Original Code is the Netscape security libraries.
 
13
 * 
 
14
 * The Initial Developer of the Original Code is Netscape
 
15
 * Communications Corporation.  Portions created by Netscape are 
 
16
 * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 
17
 * Rights Reserved.
 
18
 * 
 
19
 * Contributor(s):
 
20
 * 
 
21
 * Alternatively, the contents of this file may be used under the
 
22
 * terms of the GNU General Public License Version 2 or later (the
 
23
 * "GPL"), in which case the provisions of the GPL are applicable 
 
24
 * instead of those above.  If you wish to allow use of your 
 
25
 * version of this file only under the terms of the GPL and not to
 
26
 * allow others to use your version of this file under the MPL,
 
27
 * indicate your decision by deleting the provisions above and
 
28
 * replace them with the notice and other provisions required by
 
29
 * the GPL.  If you do not delete the provisions above, a recipient
 
30
 * may use your version of this file under either the MPL or the
 
31
 * GPL.
 
32
 */
 
33
/*
 
34
 * Software implementation of FORTEZZA skipjack primatives
 
35
 */
 
36
#include "maci.h"
 
37
#include "seccomon.h"
 
38
#include "swforti.h" 
 
39
 
 
40
/*
 
41
 * Xor the IV into the plaintext buffer either just before encryption, or
 
42
 * just after decryption.
 
43
 */
 
44
static void
 
45
fort_XorIV(unsigned char *obuffer, unsigned char *buffer, unsigned char *iv) {
 
46
    int i;
 
47
#ifdef USE_INT32
 
48
    if ((buffer & 0x3) == 0) && ((iv & 0x3) == 0)) {
 
49
        int32 *ibuffer = (int32 *)buffer;
 
50
        int32 *iobuffer = (int32 *)obuffer;
 
51
        int32 *iiv = (int32 *)iv;
 
52
 
 
53
        iobuffer[0] = ibuffer[0] ^ iiv[0];
 
54
        iobuffer[1] = ibuffer[1] ^ iiv[1];
 
55
        return;
 
56
    }
 
57
#endif
 
58
 
 
59
    for (i=0; i < SKIPJACK_BLOCK_SIZE; i++) {
 
60
        obuffer[i] = buffer[i] ^ iv[i];
 
61
    }
 
62
}
 
63
 
 
64
 
 
65
/* the F-table for Skipjack */
 
66
unsigned char F[256] = { 
 
67
    0xa3, 0xd7, 0x09, 0x83, 0xf8, 0x48, 0xf6, 0xf4,
 
68
    0xb3, 0x21, 0x15, 0x78, 0x99, 0xb1, 0xaf, 0xf9,
 
69
    0xe7, 0x2d, 0x4d, 0x8a, 0xce, 0x4c, 0xca, 0x2e,
 
70
    0x52, 0x95, 0xd9, 0x1e, 0x4e, 0x38, 0x44, 0x28,
 
71
    0x0a, 0xdf, 0x02, 0xa0, 0x17, 0xf1, 0x60, 0x68,
 
72
    0x12, 0xb7, 0x7a, 0xc3, 0xe9, 0xfa, 0x3d, 0x53,
 
73
    0x96, 0x84, 0x6b, 0xba, 0xf2, 0x63, 0x9a, 0x19,
 
74
    0x7c, 0xae, 0xe5, 0xf5, 0xf7, 0x16, 0x6a, 0xa2,
 
75
    0x39, 0xb6, 0x7b, 0x0f, 0xc1, 0x93, 0x81, 0x1b,
 
76
    0xee, 0xb4, 0x1a, 0xea, 0xd0, 0x91, 0x2f, 0xb8,
 
77
    0x55, 0xb9, 0xda, 0x85, 0x3f, 0x41, 0xbf, 0xe0,
 
78
    0x5a, 0x58, 0x80, 0x5f, 0x66, 0x0b, 0xd8, 0x90,
 
79
    0x35, 0xd5, 0xc0, 0xa7, 0x33, 0x06, 0x65, 0x69,
 
80
    0x45, 0x00, 0x94, 0x56, 0x6d, 0x98, 0x9b, 0x76,
 
81
    0x97, 0xfc, 0xb2, 0xc2, 0xb0, 0xfe, 0xdb, 0x20,
 
82
    0xe1, 0xeb, 0xd6, 0xe4, 0xdd, 0x47, 0x4a, 0x1d,
 
83
    0x42, 0xed, 0x9e, 0x6e, 0x49, 0x3c, 0xcd, 0x43,
 
84
    0x27, 0xd2, 0x07, 0xd4, 0xde, 0xc7, 0x67, 0x18,
 
85
    0x89, 0xcb, 0x30, 0x1f, 0x8d, 0xc6, 0x8f, 0xaa,
 
86
    0xc8, 0x74, 0xdc, 0xc9, 0x5d, 0x5c, 0x31, 0xa4,
 
87
    0x70, 0x88, 0x61, 0x2c, 0x9f, 0x0d, 0x2b, 0x87,
 
88
    0x50, 0x82, 0x54, 0x64, 0x26, 0x7d, 0x03, 0x40,
 
89
    0x34, 0x4b, 0x1c, 0x73, 0xd1, 0xc4, 0xfd, 0x3b,
 
90
    0xcc, 0xfb, 0x7f, 0xab, 0xe6, 0x3e, 0x5b, 0xa5,
 
91
    0xad, 0x04, 0x23, 0x9c, 0x14, 0x51, 0x22, 0xf0,
 
92
    0x29, 0x79, 0x71, 0x7e, 0xff, 0x8c, 0x0e, 0xe2,
 
93
    0x0c, 0xef, 0xbc, 0x72, 0x75, 0x6f, 0x37, 0xa1,
 
94
    0xec, 0xd3, 0x8e, 0x62, 0x8b, 0x86, 0x10, 0xe8,
 
95
    0x08, 0x77, 0x11, 0xbe, 0x92, 0x4f, 0x24, 0xc5,
 
96
    0x32, 0x36, 0x9d, 0xcf, 0xf3, 0xa6, 0xbb, 0xac,
 
97
    0x5e, 0x6c, 0xa9, 0x13, 0x57, 0x25, 0xb5, 0xe3,
 
98
    0xbd, 0xa8, 0x3a, 0x01, 0x05, 0x59, 0x2a, 0x46
 
99
};
 
100
 
 
101
typedef unsigned char fort_keysched[32*4];
 
102
 
 
103
/* do the key schedule work once for efficency */
 
104
static void
 
105
fort_skipKeySchedule(FORTSkipjackKeyPtr key,fort_keysched keysched)
 
106
{
 
107
    unsigned char *keyptr = key;
 
108
    unsigned char *first = keyptr +sizeof(FORTSkipjackKey)-1;
 
109
    int i;
 
110
 
 
111
    keyptr = first;
 
112
 
 
113
    for (i=0; i < (32*4); i++) {
 
114
        keysched[i] = *keyptr--;
 
115
        if (keyptr < key) keyptr = first;
 
116
    }
 
117
    return;
 
118
}
 
119
 
 
120
static void
 
121
fort_clearShedule(fort_keysched keysched)
 
122
{
 
123
    PORT_Memset(keysched, 0, sizeof(keysched));
 
124
}
 
125
 
 
126
 
 
127
static unsigned int 
 
128
G(fort_keysched cv, int k, unsigned int wordIn)
 
129
{
 
130
    unsigned char g1, g2, g3, g4, g5, g6;
 
131
 
 
132
    g1 = (unsigned char) (wordIn >> 8) & 0xff;
 
133
    g2 = (unsigned char) wordIn & 0xff;
 
134
 
 
135
    g3 = F[g2^cv[4*k]]^g1;
 
136
    g4 = F[g3^cv[4*k+1]]^g2;
 
137
    g5 = F[g4^cv[4*k+2]]^g3;
 
138
    g6 = F[g5^cv[4*k+3]]^g4;
 
139
 
 
140
    return ((g5<<8)+g6);
 
141
}
 
142
 
 
143
static unsigned int 
 
144
G1(fort_keysched cv, int k, unsigned int wordIn)
 
145
{
 
146
    unsigned char g1, g2, g3, g4, g5, g6;
 
147
 
 
148
    g5 = (unsigned char) (wordIn >> 8) & 0xff;
 
149
    g6 = (unsigned char) wordIn & 0xff;
 
150
 
 
151
    g4 = F[g5^cv[4*k+3]]^g6;
 
152
    g3 = F[g4^cv[4*k+2]]^g5;
 
153
    g2 = F[g3^cv[4*k+1]]^g4;
 
154
    g1 = F[g2^cv[4*k]]^g3;
 
155
 
 
156
    return ((g1<<8)+g2);
 
157
}
 
158
 
 
159
static void 
 
160
ruleA(fort_keysched cv,int round,unsigned int *w)
 
161
{
 
162
    unsigned int w4;
 
163
    int i;
 
164
 
 
165
    for(i=0; i<8; i++) {
 
166
        int k = round*16+i;
 
167
        int counter = k+1;
 
168
 
 
169
        w4 = w[4];
 
170
        w[4] = w[3];
 
171
        w[3] = w[2];
 
172
        w[2] = G(cv,k,w[1]);
 
173
        w[1] = G(cv,k,w[1]) ^ w4 ^ counter;
 
174
    }
 
175
    return;
 
176
}
 
177
 
 
178
static void 
 
179
ruleB(fort_keysched cv,int round,unsigned int *w)
 
180
{
 
181
    unsigned int w4;
 
182
    int i;
 
183
 
 
184
    for(i=0; i<8; i++) {
 
185
        int k = round*16+i+8;
 
186
        int counter = k+1;
 
187
 
 
188
        w4 = w[4];
 
189
        w[4] = w[3];
 
190
        w[3] = w[1] ^ w[2] ^ counter; 
 
191
        w[2] = G(cv,k,w[1]);
 
192
        w[1] = w4;
 
193
    }
 
194
    return;
 
195
}
 
196
 
 
197
static void 
 
198
ruleA1(fort_keysched cv,int round,unsigned int *w)
 
199
{
 
200
    unsigned int w4;
 
201
    int i;
 
202
 
 
203
    for(i=7; i>=0; i--) {
 
204
        int k = round*16+i;
 
205
        int counter = k+1;
 
206
 
 
207
        w4 = w[4];
 
208
        w[4] = w[1] ^ w[2] ^ counter;
 
209
        w[1] = G1(cv,k,w[2]);
 
210
        w[2] = w[3];
 
211
        w[3] = w4;
 
212
    }
 
213
    return;
 
214
}
 
215
 
 
216
static void 
 
217
ruleB1(fort_keysched cv,int round,unsigned int *w)
 
218
{
 
219
    unsigned int w4;
 
220
    int i;
 
221
 
 
222
    for(i=7; i>=0; i--) {
 
223
        int k = round*16+i+8;
 
224
        int counter = k+1;
 
225
 
 
226
        w4 = w[4];
 
227
        w[4] = w[1];
 
228
        w[1] = G1(cv,k,w[2]);
 
229
        w[2] = G1(cv,k,w[2]) ^ w[3] ^ counter; 
 
230
        w[3] = w4;
 
231
    }
 
232
    return;
 
233
}
 
234
 
 
235
 
 
236
static void 
 
237
fort_doskipD(fort_keysched cv,unsigned char *cipherIn,
 
238
                                                 unsigned char *plainOut) {
 
239
  unsigned int w[5]; /* ignore w[0] so the code matches the doc */
 
240
 
 
241
  /* initial byte swap */
 
242
  w[1]=(cipherIn[7]<<8)+cipherIn[6];
 
243
  w[2]=(cipherIn[5]<<8)+cipherIn[4];
 
244
  w[3]=(cipherIn[3]<<8)+cipherIn[2];
 
245
  w[4]=(cipherIn[1]<<8)+cipherIn[0];
 
246
 
 
247
  ruleB1(cv,1,w);
 
248
  ruleA1(cv,1,w);
 
249
  ruleB1(cv,0,w);
 
250
  ruleA1(cv,0,w);
 
251
 
 
252
  /* final byte swap */
 
253
  plainOut[0] = w[4] & 0xff;
 
254
  plainOut[1] = (w[4] >> 8) & 0xff;
 
255
  plainOut[2] = w[3] & 0xff;
 
256
  plainOut[3] = (w[3] >> 8) & 0xff;
 
257
  plainOut[4] = w[2] & 0xff;
 
258
  plainOut[5] = (w[2] >> 8) & 0xff;
 
259
  plainOut[6] = w[1] & 0xff;
 
260
  plainOut[7] = (w[1] >> 8) & 0xff;
 
261
  return;
 
262
}
 
263
 
 
264
static void 
 
265
fort_doskipE(fort_keysched cv,unsigned char *cipherIn,
 
266
                                                 unsigned char *plainOut) {
 
267
  unsigned int w[5]; /* ignore w[0] so the code matches the doc */
 
268
 
 
269
  /* initial byte swap */
 
270
  w[1]=(cipherIn[7]<<8)+cipherIn[6];
 
271
  w[2]=(cipherIn[5]<<8)+cipherIn[4];
 
272
  w[3]=(cipherIn[3]<<8)+cipherIn[2];
 
273
  w[4]=(cipherIn[1]<<8)+cipherIn[0];
 
274
 
 
275
  ruleA(cv,0,w);
 
276
  ruleB(cv,0,w);
 
277
  ruleA(cv,1,w);
 
278
  ruleB(cv,1,w);
 
279
 
 
280
  /* final byte swap */
 
281
  plainOut[0] = w[4] & 0xff;
 
282
  plainOut[1] = (w[4] >> 8) & 0xff;
 
283
  plainOut[2] = w[3] & 0xff;
 
284
  plainOut[3] = (w[3] >> 8) & 0xff;
 
285
  plainOut[4] = w[2] & 0xff;
 
286
  plainOut[5] = (w[2] >> 8) & 0xff;
 
287
  plainOut[6] = w[1] & 0xff;
 
288
  plainOut[7] = (w[1] >> 8) & 0xff;
 
289
  return;
 
290
}
 
291
 
 
292
/* Checksums are calculated by encrypted a fixed string with the key, then
 
293
 * taking 16 bytes of the result from the block */
 
294
static int
 
295
fort_CalcKeyChecksum(FORTSkipjackKeyPtr key, unsigned char *sum) {
 
296
    unsigned char ckdata[8] = {
 
297
                 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
 
298
    unsigned char ckres[8];
 
299
    fort_keysched keysched;
 
300
 
 
301
 
 
302
    fort_skipKeySchedule(key,keysched);
 
303
 
 
304
    fort_doskipE(keysched,ckdata,ckres);
 
305
    fort_clearShedule(keysched);
 
306
    PORT_Memcpy(sum,&ckres[1],2);
 
307
    return CI_OK;
 
308
}
 
309
 
 
310
/* These function actually implements skipjack CBC Decrypt */
 
311
int
 
312
fort_skipjackDecrypt(FORTSkipjackKeyPtr key, unsigned char *iv, 
 
313
                unsigned long size, unsigned char *cipherIn, 
 
314
                                                unsigned char *plainOut) {
 
315
    unsigned char ivdata1[SKIPJACK_BLOCK_SIZE];
 
316
    unsigned char ivdata2[SKIPJACK_BLOCK_SIZE];
 
317
    unsigned char *lastiv, *nextiv, *tmpiv;
 
318
    fort_keysched keysched;
 
319
 
 
320
    /* do the key schedule work once for efficency */
 
321
    fort_skipKeySchedule(key,keysched);
 
322
 
 
323
    /* As we decrypt, we need to save the last block so that we can
 
324
     * Xor it out of decrypted text to get the real plain text. We actually
 
325
     * have to save it because cipherIn and plainOut may point to the same
 
326
     * buffer. */
 
327
    lastiv =ivdata1;
 
328
    nextiv = ivdata2;
 
329
    PORT_Memcpy(lastiv,iv,SKIPJACK_BLOCK_SIZE);
 
330
    while (size >= SKIPJACK_BLOCK_SIZE) {
 
331
        /* save the IV for the next block */
 
332
        PORT_Memcpy(nextiv,cipherIn,SKIPJACK_BLOCK_SIZE);
 
333
        fort_doskipD(keysched,cipherIn,plainOut);
 
334
        /* xor out the last IV */
 
335
        fort_XorIV(plainOut,plainOut,lastiv);
 
336
 
 
337
        /* swap the IV buffers */
 
338
        tmpiv = lastiv;
 
339
        lastiv = nextiv;
 
340
        nextiv =tmpiv;
 
341
 
 
342
        /* increment the loop pointers... be sure to get the input, output,
 
343
         * and size (decrement) each fortdoskipD operates on an entire block*/
 
344
        cipherIn += SKIPJACK_BLOCK_SIZE;
 
345
        plainOut += SKIPJACK_BLOCK_SIZE;
 
346
        size -= SKIPJACK_BLOCK_SIZE;
 
347
    }
 
348
    fort_clearShedule(keysched); /* don't leave the key lying around the stack*/
 
349
    if (size != 0) return CI_INV_SIZE;
 
350
    return CI_OK;
 
351
}
 
352
 
 
353
/* These function actually implements skipjack CBC Encrypt */
 
354
int
 
355
fort_skipjackEncrypt(FORTSkipjackKeyPtr key, unsigned char *iv, 
 
356
                unsigned long size, unsigned char *plainIn, 
 
357
                                                unsigned char *cipherOut) {
 
358
    unsigned char *tmpiv;
 
359
    fort_keysched keysched;
 
360
    unsigned char plain[SKIPJACK_BLOCK_SIZE];
 
361
 
 
362
    fort_skipKeySchedule(key,keysched);
 
363
    tmpiv = iv;
 
364
    while (size >= SKIPJACK_BLOCK_SIZE) {
 
365
        /* We Xor into a temp buffer because we don't want to modify plainIn,
 
366
         * doing so may make the caller very unhappy:). */
 
367
        fort_XorIV(plain,plainIn,tmpiv);
 
368
        fort_doskipE(keysched,plain,cipherOut);
 
369
        tmpiv = cipherOut;
 
370
        cipherOut += SKIPJACK_BLOCK_SIZE;
 
371
        plainIn += SKIPJACK_BLOCK_SIZE;
 
372
        size -= SKIPJACK_BLOCK_SIZE;
 
373
    }
 
374
    fort_clearShedule(keysched); /* don't leave the key lying around the stack*/
 
375
    if (size != 0) return CI_INV_SIZE;
 
376
    return CI_OK;
 
377
}
 
378
 
 
379
   
 
380
 
 
381
/*
 
382
 * unwrap is used for key generation and mixing
 
383
 */
 
384
int
 
385
fort_skipjackUnwrap(FORTSkipjackKeyPtr key,unsigned long len, 
 
386
                        unsigned char *cipherIn, unsigned char *plainOut) {
 
387
    unsigned char low[10];
 
388
    fort_keysched keysched;
 
389
    int i,ret;
 
390
 
 
391
    /* unwrap can only unwrap 80 bit symetric keys and 160 private keys 
 
392
     * sometimes these values have checksums. When they do, we should verify
 
393
     * those checksums. */
 
394
    switch (len) {
 
395
    case 20:    /* private key */
 
396
    case 24:   /* private key with checksum */
 
397
        ret = fort_skipjackUnwrap(key,len/2,cipherIn,plainOut);
 
398
        if (ret != CI_OK) return ret;
 
399
        ret = fort_skipjackUnwrap(key,len/2,&cipherIn[len/2],low);
 
400
 
 
401
        /* unmunge the low word */
 
402
        for (i=0; i < 10; i++) {
 
403
            low[i] = low[i] ^ plainOut[i];
 
404
        }
 
405
 
 
406
        /* the unwrap will fail above because the checkword is on
 
407
         * low, not low ^ high.
 
408
         */
 
409
        if (ret == CI_CHECKWORD_FAIL) {
 
410
            unsigned char checksum[2];
 
411
 
 
412
            ret = fort_CalcKeyChecksum(low,checksum);
 
413
            if (ret != CI_OK) return ret;
 
414
            if (PORT_Memcmp(checksum,&cipherIn[len-2],2) != 0) {
 
415
                return CI_CHECKWORD_FAIL;
 
416
            }
 
417
        }
 
418
        if (ret != CI_OK) return ret;
 
419
 
 
420
        /* re-order the low word */
 
421
        PORT_Memcpy(&plainOut[10],&low[8],2);
 
422
        PORT_Memcpy(&plainOut[12],&low[0],8);
 
423
        return CI_OK;
 
424
    case 10: /* 80 bit skipjack key */
 
425
    case 12: /* 80 bit skipjack key with checksum */
 
426
        fort_skipKeySchedule(key,keysched);
 
427
        fort_doskipD(keysched,cipherIn,plainOut);
 
428
        plainOut[8] = cipherIn[8] ^ plainOut[0];
 
429
        plainOut[9] = cipherIn[9] ^ plainOut[1];
 
430
        fort_doskipD(keysched,plainOut,plainOut);
 
431
        fort_clearShedule(keysched); 
 
432
        /* if we have a checkum, verify it */
 
433
        if (len == 12) {
 
434
            unsigned char checksum[2];
 
435
 
 
436
            ret = fort_CalcKeyChecksum(plainOut,checksum);
 
437
            if (ret != CI_OK) return ret;
 
438
            if (PORT_Memcmp(checksum,&cipherIn[10],2) != 0) {
 
439
                return CI_CHECKWORD_FAIL;
 
440
            }
 
441
        }
 
442
        return CI_OK;
 
443
    default:
 
444
        break;
 
445
    }
 
446
    return CI_INV_SIZE;
 
447
}
 
448
 
 
449
/*
 
450
 * unwrap is used for key generation and mixing
 
451
 */
 
452
int
 
453
fort_skipjackWrap(FORTSkipjackKeyPtr key,unsigned long len, 
 
454
                        unsigned char *plainIn, unsigned char *cipherOut) {
 
455
    unsigned char low[10];
 
456
    unsigned char checksum[2];
 
457
    fort_keysched keysched;
 
458
    int i,ret;
 
459
 
 
460
 
 
461
    /* NOTE: length refers to the target in the case of wrap */
 
462
    /* Wrap can only Wrap 80 bit symetric keys and 160 private keys 
 
463
     * sometimes these values have checksums. When they do, we should verify
 
464
     * those checksums. */
 
465
    switch (len) {
 
466
    case 20:    /* private key */
 
467
    case 24:   /* private key with checksum */
 
468
        /* re-order the low word */
 
469
        PORT_Memcpy(&low[8],&plainIn[10],2);
 
470
        PORT_Memcpy(&low[0],&plainIn[12],8);
 
471
        if (len == 24) {
 
472
            ret = fort_CalcKeyChecksum(low,checksum);
 
473
            if (ret != CI_OK) return ret;
 
474
        }
 
475
        /* munge the low word */
 
476
        for (i=0; i < 10; i++) {
 
477
            low[i] = low[i] ^ plainIn[i];
 
478
        }
 
479
        ret = fort_skipjackWrap(key,len/2,plainIn,cipherOut);
 
480
        ret = fort_skipjackWrap(key,len/2,low,&cipherOut[len/2]);
 
481
        if (len == 24) {
 
482
            PORT_Memcpy(&cipherOut[len - 2], checksum, sizeof(checksum));
 
483
        }
 
484
 
 
485
        return CI_OK;
 
486
    case 10: /* 80 bit skipjack key */
 
487
    case 12: /* 80 bit skipjack key with checksum */
 
488
 
 
489
        fort_skipKeySchedule(key,keysched);
 
490
        fort_doskipE(keysched,plainIn,cipherOut);
 
491
        cipherOut[8] = plainIn[8] ^ cipherOut[0];
 
492
        cipherOut[9] = plainIn[9] ^ cipherOut[1];
 
493
        fort_doskipE(keysched,cipherOut,cipherOut);
 
494
        fort_clearShedule(keysched); 
 
495
        /* if we need a checkum, get it */
 
496
        if (len == 12) {
 
497
            ret = fort_CalcKeyChecksum(plainIn,&cipherOut[10]);
 
498
            if (ret != CI_OK) return ret;
 
499
        }
 
500
        return CI_OK;
 
501
    default:
 
502
        break;
 
503
    }
 
504
    return CI_INV_SIZE;
 
505
}
 
506