3 Copyright (C) 2011 Neil Cafferkey
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 /****i* prism2.device/UpdateMIC ********************************************
26 * UpdateMIC -- Include new data into a Michael MIC value.
29 * UpdateMIC(left, right, data, count)
31 * VOID UpdateMIC(ULONG *, ULONG *, ULONG *, ULONG);
34 * Register assignment relative to C implementation:
43 ****************************************************************************
51 /* Anchor stack arguments */
55 /* Push registers that should be preserved on to stack */
57 movem.
l d2-d7
/a2-a4
,-(sp
)
59 /* Apply transformation */
108 /* Store new left and right values */
113 /* Pop preserved registers off stack and return with original SP */
115 movem.
l (sp
)+,d2-d7
/a2-a4
122 /****i* prism2.device/TKIPKeyMix2 ******************************************
125 * TKIPKeyMix2 -- Apply phase 2 of the TKIP key-mixing function.
128 * TKIPKeyMix2(rc4_seed, ttak, tk, iv16)
130 * VOID TKIPKeyMix2(UBYTE *, UWORD *, UWORD *, UWORD);
133 * Register assignment relative to C implementation:
142 ****************************************************************************
150 /* Anchor stack arguments */
154 /* Push registers that should be preserved on to stack */
156 movem.
l d2-d7
/a2-a4
,-(sp
)
334 /* Pop preserved registers off stack and return with original SP */
336 movem.
l (sp
)+,d2-d7
/a2-a4
342 /****i* prism2.device/RC4Encrypt *******************************************
345 * RC4Encrypt -- Encrypt data using the RC4 cipher, and append CRC.
348 * RC4Encrypt(unit, data, size, buffer, seed)
350 * VOID RC4Encrypt(struct DevUnit *, UBYTE *, UWORD, UBYTE *, UBYTE *);
353 * The input data may overlap the output buffer as long as the output
354 * address is not higher than the input address.
357 * Register assignment relative to C implementation:
368 ****************************************************************************
376 /* Anchor stack arguments and make space for S table */
380 /* Push registers that should be preserved on to stack */
382 movem.
l d2-d7
/a2-a4
,-(sp
)
384 /* Initialise RC4 state */
386 move.
l #0x00010203,d2
409 move.
b (a2
,d3
:w
),(a0
)+
415 /* Encrypt data and calculate CRC */
457 /* Check if CRC has been encrypted */
463 /* Copy CRC complement to buffer, then go back and encrypt it */
477 /* Pop preserved registers off stack and return with original SP */
479 movem.
l (sp
)+,d2-d7
/a2-a4
485 /****i* prism2.device/RC4Decrypt *******************************************
488 * RC4Decrypt -- Decrypt data using the RC4 cipher, and check CRC.
491 * success = RC4Encrypt(unit, data, size, buffer, seed)
493 * BOOL RC4Decrypt(struct DevUnit *, UBYTE *, UWORD, UBYTE *, UBYTE *);
496 * The input data may overlap the output buffer as long as the output
497 * address is not higher than the input address.
499 * The output buffer must be at least as big as the input data.
502 * This implementation skips the CRC/ICV check in order to gain speed.
504 * Register assignment relative to C implementation:
513 ****************************************************************************
521 /* Anchor stack arguments and make space for S table */
525 /* Push registers that should be preserved on to stack */
527 movem.
l d2-d7
/a2-a4
,-(sp
)
529 /* Initialise RC4 state */
531 move.
l #0x00010203,d2
539 bcc.
b preinit_state2$
554 move.
b (a2
,d3
:w
),(a0
)+
560 /* Decrypt data and calculate CRC */
590 /* Assume a good CRC */
595 /* Pop preserved registers off stack and return with original SP */
597 movem.
l (sp
)+,d2-d7
/a2-a4
603 /****i* prism2.device/AESEncrypt *******************************************
606 * AESEncrypt -- Encrypt a block using the AES cipher.
609 * AESEncrypt(data, buffer, key)
611 * VOID AESEncrypt(UBYTE *, UBYTE *, UBYTE *);
614 * Register assignment relative to C implementation:
625 * a4: s3, key, buffer
628 ****************************************************************************
636 /* Anchor stack arguments */
640 /* Push registers that should be preserved on to stack */
642 movem.
l d2-d7
/a2-a4
,-(sp
)
644 /* Initialise AES state */
663 /* Save s values in address registers */
670 /* Apply first 9 rounds */
677 /* Initialise new state from key */
684 /* Inject s0-based data */
690 move.
l (0x300*4:w
,a5
,d7
:w
*4),d7
694 move.
l (0x200*4:w
,a5
,d6
:w
*4),d7
700 move.
l (0x100*4:w
,a5
,d7
:w
*4),d7
704 move.
l (a5
,d6
:w
*4),d7
707 /* Inject s1-based data */
713 move.
l (0x300*4:w
,a5
,d7
:w
*4),d7
717 move.
l (0x200*4:w
,a5
,d6
:w
*4),d7
723 move.
l (0x100*4:w
,a5
,d7
:w
*4),d7
727 move.
l (a5
,d6
:w
*4),d7
730 /* Inject s2-based data */
736 move.
l (0x300*4:w
,a5
,d7
:w
*4),d7
740 move.
l (0x200*4:w
,a5
,d6
:w
*4),d7
746 move.
l (0x100*4:w
:w
,a5
,d7
:w
*4),d7
750 move.
l (a5
,d6
:w
*4),d7
753 /* Inject s3-based data */
759 move.
l (0x300*4:w
,a5
,d7
:w
*4),d7
763 move.
l (0x200*4:w
,a5
,d6
:w
*4),d7
769 move.
l (0x100*4:w
,a5
,d7
:w
*4),d7
773 move.
l (a5
,d6
:w
*4),d7
776 /* Save state values in address registers */
785 /* Apply final round */
789 /* Initialise new state from key */
796 /* Inject s0-based data */
804 andi.l #0x000000ff,d7
811 andi.l #0x0000ff00,d7
819 andi.l #0x00ff0000,d7
826 andi.l #0xff000000,d7
829 /* Inject s1-based data */
837 andi.l #0x000000ff,d7
844 andi.l #0x0000ff00,d7
852 andi.l #0x00ff0000,d7
859 andi.l #0xff000000,d7
862 /* Inject s2-based data */
870 andi.l #0x000000ff,d7
877 andi.l #0x0000ff00,d7
885 andi.l #0x00ff0000,d7
892 andi.l #0xff000000,d7
895 /* Inject s3-based data */
903 andi.l #0x000000ff,d7
910 andi.l #0x0000ff00,d7
918 andi.l #0x00ff0000,d7
925 andi.l #0xff000000,d7
928 /* Write final state to buffer */
938 /* Pop preserved registers off stack and return with original SP */
940 movem.
l (sp
)+,d2-d7
/a2-a4