annotate gsm-fw/comlib/cl_md5.c @ 848:8227a33397de

gtamodem-gsm flashImage links with cst included!
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sat, 25 Apr 2015 22:36:40 +0000
parents d36f647c2432
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
664
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 +-----------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 | Project : COMLIB
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 | Modul : cl_md5.c
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 +-----------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 | Copyright 2002 Texas Instruments Berlin, AG
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 | All rights reserved.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 |
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 | This file is confidential and a trade secret of Texas
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 | Instruments Berlin, AG
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 | The receipt of or possession of this file does not convey
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 | any rights to reproduce or disclose its contents or to
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 | manufacture, use, or sell anything it may describe, in
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 | whole, or in part, without the specific written consent of
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 | Texas Instruments Berlin, AG.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 +-----------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 | Purpose : Definitions of common library functions: MD5 algorithm
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 +-----------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 * Version 1.0
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 /**********************************************************************************/
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 NOTE:
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 /**********************************************************************************/
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 #ifndef CL_MD5_C
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 #define CL_MD5_C
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 #include "typedefs.h"
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 #include <string.h>
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 #include "vsi.h" /* to get a lot of macros */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 #include "cl_md5.h"
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 #include "stdio.h"
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 /*==== FUNCTIONS ==================================================*/
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 * Constants for MD5 routine.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 #define S11 7
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 #define S12 12
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 #define S13 17
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 #define S14 22
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 #define S21 5
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 #define S22 9
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 #define S23 14
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 #define S24 20
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 #define S31 4
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 #define S32 11
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 #define S33 16
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 #define S34 23
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 #define S41 6
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 #define S42 10
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 #define S43 15
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 #define S44 21
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 * F, G, H and I are basic MD5 functions.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 #define H(x, y, z) ((x) ^ (y) ^ (z))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 #define I(x, y, z) ((y) ^ ((x) | (~z)))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 * ROTATE_LEFT rotates x left n bits.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 * Rotation is separate from addition to prevent recomputation.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 #define FF(a, b, c, d, x, s, ac) { \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 (a) += F ((b), (c), (d)) + (x) + (UINT)(ac); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 (a) = ROTATE_LEFT ((a), (s)); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 (a) += (b); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 #define GG(a, b, c, d, x, s, ac) { \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 (a) += G ((b), (c), (d)) + (x) + (UINT)(ac); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 (a) = ROTATE_LEFT ((a), (s)); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 (a) += (b); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 #define HH(a, b, c, d, x, s, ac) { \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 (a) += H ((b), (c), (d)) + (x) + (UINT)(ac); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 (a) = ROTATE_LEFT ((a), (s)); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 (a) += (b); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 #define II(a, b, c, d, x, s, ac) { \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 (a) += I ((b), (c), (d)) + (x) + (UINT)(ac); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 (a) = ROTATE_LEFT ((a), (s)); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 (a) += (b); \
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 * 1. Append the length in bits
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 * 2. Process message
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 * 3. Store state in digest
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 #define PROCESS_MSG() {\
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 memcpy(&context.buffer[56], bits, 8);\
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 cl_md5_transform(context.state, context.buffer);\
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 cl_md5_enc (digest, context.state, 16);\
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 #ifdef _SIMULATION_
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 | Function : MDPrint
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 | Description : Prints a message digest in hexadecimal.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 |
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 | Parameters : UBYTE digest[16]
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 GLOBAL void MDPrint (UBYTE *digest, UINT len)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 UINT i;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 for (i = 0; i < len; i+=8)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 TRACE_EVENT_P8 ("0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, ",
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 digest[i], digest[i+1], digest[i+2], digest[i+3],
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 digest[i+4], digest[i+5], digest[i+6], digest[i+7]);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 #endif
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 | Function : cl_md5_enc
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 | Description : Encodes input (UINT) into output (UBYTE). Assumes len
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 | is a multiple of 4.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 |
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 | Parameters : UBYTE *output
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 | UINT *input
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 | UINT len
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 void cl_md5_enc (UBYTE *output, UINT *input, UINT len)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 UINT i, j;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 for (i = 0, j = 0; j < len; i++, j += 4) {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 output[j] = (UBYTE)(input[i] & 0xff);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 output[j+1] = (UBYTE)((input[i] >> 8) & 0xff);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 output[j+2] = (UBYTE)((input[i] >> 16) & 0xff);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 output[j+3] = (UBYTE)((input[i] >> 24) & 0xff);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 | Function : cl_md5_dec
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 | Description : Decodes input (UBYTE) into output (UINT). Assumes len
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 | is a multiple of 4.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 |
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 | Parameters : UINT *output
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 | UBYTE *input
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 | UINT len
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 void cl_md5_dec (UINT *output, UBYTE *input, UINT len)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 UINT i, j;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 for (i = 0, j = 0; j < len; i++, j += 4)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175 output[i] = ((UINT)input[j]) | (((UINT)input[j+1]) << 8) |
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 (((UINT)input[j+2]) << 16) | (((UINT)input[j+3]) << 24);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
182 | Function : cl_md5_transform
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
183 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184 | Description : MD5 basic transformation. Transforms state based on block.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
185 | For more information see RFC 1321 "MD5 Message-Digest Algorithm".
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
186 | This routine is derived from the RSA Data Security, Inc. MD5
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
187 | Message-Digest Algorithm.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
188 |
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
189 | Parameters : UINT state[4]
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
190 | UBYTE block[64]
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
191 |
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
192 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
193 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
194 void cl_md5_transform (UINT state[4], UBYTE block[64])
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196 UINT a = state[0], b = state[1], c = state[2], d = state[3], x[16];
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 cl_md5_dec (x, block, 64);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 /* Round 1 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201 FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202 FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204 FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
207 FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208 FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
209 FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210 FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211 FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
213 FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
214 FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215 FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216 FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218 /* Round 2 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
220 GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
221 GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
222 GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
223 GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
224 GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
225 GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
226 GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
227 GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
228 GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
229 GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
230
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
231 GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
232 GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
233 GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
234 GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
235 GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
236
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
237 /* Round 3 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
238 HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
239 HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
240 HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
241 HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
242 HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
243 HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
244 HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
245 HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
246 HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
247 HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
248 HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
249 HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
250 HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
251 HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
252 HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
253 HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
254
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
255 /* Round 4 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
256 II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
257 II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
258 II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
259 II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
260 II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
261 II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
262 II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
263 II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
264 II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
265 II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
266 II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
267 II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
268 II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
269 II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
270 II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
271 II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
272
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
273 state[0] += a;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
274 state[1] += b;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
275 state[2] += c;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
276 state[3] += d;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
277
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
278 /* Zeroize sensitive information.*/
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
279 memset((UBYTE *)x, 0, sizeof (x));
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
280 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
281
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
282 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
283 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
284 | Function : cl_md5
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
285 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
286 | Description : Digests a string and prints the result. For more information see
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
287 | RFC 1321 "MD5 Message-Digest Algorithm".
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
288 |
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
289 | Parameters : UBYTE *input - input challenge string
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
290 | UINT len - length of input string
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
291 | UBYTE *digest - output digest message
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
292 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
293 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
294 GLOBAL void cl_md5 (UBYTE *input, UINT len, UBYTE *digest)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
295 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
296 MD5_CTX context;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
297 UBYTE bits[8];
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
298 UINT ind;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
299 int chk_len;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
300 TRACE_EVENT("cl_md5");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
301
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
302 if(len==0)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
303 len = strlen ((char *)input);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
304
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
305 #ifdef _SIMULATION_
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
306 TRACE_EVENT("Input Message");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
307 MDPrint (input, len);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
308 #endif
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
309
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
310 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
311 * MD5 initialization. Begins an MD5 operation, writing a new context.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
312 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
313 context.count[0] = context.count[1] = 0;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
314 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
315 * Load magic initialization constants according to RFC 1321
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
316 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
317 context.state[0] = 0x67452301; /* word A */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
318 context.state[1] = 0xefcdab89; /* word B */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
319 context.state[2] = 0x98badcfe; /* word C */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
320 context.state[3] = 0x10325476; /* word D */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
321 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
322 * Update number of bits (64-bit representation of message length)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
323 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
324 if ((context.count[0] += ((UINT)len << 3)) < ((UINT)len << 3))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
325 context.count[1]++;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
326 context.count[1] += ((UINT)len >> 29);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
327 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
328 * Save number of bits
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
329 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
330 cl_md5_enc (bits, context.count, 8);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
331
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
332 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
333 * Step 1. Append Padding Bits
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
334 * The message is extended so that its length is congruent to 56 bytes
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
335 * (448 bits), modulo 64 (512). Extending is always performed, even if the
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
336 * length is already congruent to 56 bytes, modulo 64.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
337 *
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
338 * Extending is performed as follows, a single "1" bit is append to the
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
339 * message, and then "0" bits are appended so that the legth in bits of the
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
340 * message becomes congruent to 56, modulo 64. In all, at least one byte and
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
341 * at most 64 bytes are appended.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
342 *
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
343 * Step 2. Append Length.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
344 * A 64-bit representation of the message length before the padding is
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
345 * appended to the result of previous step.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
346 *
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
347 * Step 3. Process Message in 16-word blocks
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
348 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
349 if(len < 56)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
350 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
351 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
352 * copy message
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
353 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
354 memcpy(&context.buffer[0], &input[0], len);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
355 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
356 * Append length to 56 bytes
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
357 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
358 context.buffer[len] = 0x80; /* append a single "1" bit */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
359 memset(&context.buffer[len+1], 0, 55-len); /* append "0" bits */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
360 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
361 * Append length in bits and process message
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
362 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
363 PROCESS_MSG();
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
364 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
365 else if(len >= 56 && len < 64)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
366 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
367 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
368 * copy message
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
369 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
370 memcpy(&context.buffer[0], &input[0], len);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
371 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
372 * Append length to 64 bytes
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
373 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
374 context.buffer[len] = 0x80;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
375 memset(&context.buffer[len+1], 0, 63-len);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
376 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
377 * Process message
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
378 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
379 cl_md5_transform (context.state, context.buffer);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
380 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
381 * Append length to 56 bytes
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
382 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
383 memset(&context.buffer[0], 0, 56);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
384 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
385 * Append the length in bits and process message
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
386 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
387 PROCESS_MSG();
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
388 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
389 else if(len >= 64)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
390 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
391 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
392 * Copy first 64 bytes
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
393 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
394 memcpy(&context.buffer[0], &input[0], 64);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
395 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
396 * Process message
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
397 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
398 cl_md5_transform (context.state, context.buffer);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
399 if(len >= 120)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
400 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
401 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
402 * Process message in 64-byte blocks
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
403 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
404 for (ind = 64; ind + 63 < len; ind += 64)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
405 cl_md5_transform (context.state, &input[ind]);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
406 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
407 else
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
408 ind = 64;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
409 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
410 * Copy the rest
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
411 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
412 memcpy(&context.buffer[0], &input[ind], len-ind);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
413 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
414 * Append length to 56 bytes
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
415 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
416 /*lint -e661 -e662 -e669 possible access or creation of bount ptr or data overrun*/
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
417 context.buffer[len-ind] = 0x80;
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
418 chk_len=55-(len-ind);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
419 if(chk_len >=0)
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
420 memset(&context.buffer[len-ind+1], 0, chk_len);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
421 /*lint +e661 +e662 +e669 possible access or creation of bount ptr or data overun*/
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
422 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
423 * Append the length in bits and process message
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
424 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
425 PROCESS_MSG();
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
426 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
427
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
428 #ifdef _SIMULATION_
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
429 TRACE_EVENT("Digest Message");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
430 MDPrint (digest, 16);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
431 #endif
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
432 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
433
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
434
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
435 #ifdef _SIMULATION_
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
436 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
437 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
438 | Function : MDTestSuite
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
439 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
440 | Description : Digests a reference suite of strings and prints the results.
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
441 |
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
442 | Parameters : void
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
443 +------------------------------------------------------------------------------
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
444 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
445 GLOBAL void cl_md5TestSuite ()
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
446 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
447 UBYTE digest[16];
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
448 UBYTE test_digest0[16] = {0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04,
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
449 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e};
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
450 UBYTE test_digest1[16] = {0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8,
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
451 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61};
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
452 UBYTE test_digest3[16] = {0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0,
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
453 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72};
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
454 UBYTE test_digest14[16] = {0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d,
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
455 0x52, 0x5a, 0x2f, 0x31, 0xaa, 0xf1, 0x61, 0xd0};
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
456 UBYTE test_digest26[16] = {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00,
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
457 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b};
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
458 UBYTE test_digest62[16] = {0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5,
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
459 0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0x9d, 0x9f};
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
460 UBYTE test_digest80[16] = {0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55,
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
461 0xac, 0x49, 0xda, 0x2e, 0x21, 0x07, 0xb6, 0x7a};
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
462 UBYTE test_digest160[16] = {0x26, 0x8c, 0x79, 0x19, 0x18, 0x9d, 0x85, 0xe2,
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
463 0x76, 0xd7, 0x4b, 0x8c, 0x60, 0xb2, 0xf8, 0x4f};
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
464
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
465 TRACE_EVENT("MD5 test suite:");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
466
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
467 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
468 * Test 1. Lenght := 0
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
469 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
470 cl_md5("", 0, digest);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
471 if(memcmp(digest, test_digest0, 16))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
472 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
473 TRACE_EVENT("CHAP MD5: Test 1 failed!!");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
474 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
475 else
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
476 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
477 TRACE_EVENT("CHAP MD5: Test 1 passed.");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
478 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
479
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
480 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
481 * Test 2. Lenght := 1
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
482 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
483 cl_md5("a", 0, digest);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
484 if(memcmp(digest, test_digest1, 16))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
485 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
486 TRACE_EVENT("CHAP MD5: Test 2 failed!!");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
487 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
488 else
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
489 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
490 TRACE_EVENT("CHAP MD5: Test 2 passed.");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
491 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
492
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
493 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
494 * Test 3. Lenght := 3
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
495 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
496 cl_md5("abc", 0, digest);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
497 if(memcmp(digest, test_digest3, 16))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
498 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
499 TRACE_EVENT("CHAP MD5: Test 3 failed!!");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
500 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
501 else
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
502 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
503 TRACE_EVENT("CHAP MD5: Test 3 passed.");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
504 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
505
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
506 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
507 * Test 4. Lenght := 14
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
508 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
509 cl_md5("message digest", 0, digest);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
510 if(memcmp(digest, test_digest14, 16))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
511 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
512 TRACE_EVENT("CHAP MD5: Test 4 failed!!");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
513 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
514 else
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
515 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
516 TRACE_EVENT("CHAP MD5: Test 4 passed.");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
517 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
518
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
519 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
520 * Test 5. Lenght := 26
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
521 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
522 cl_md5("abcdefghijklmnopqrstuvwxyz", 0, digest);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
523 if(memcmp(digest, test_digest26, 16))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
524 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
525 TRACE_EVENT("CHAP MD5: Test5 failed!!");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
526 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
527 else
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
528 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
529 TRACE_EVENT("CHAP MD5: Test 5 passed.");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
530 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
531
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
532 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
533 * Test 6. Lenght := 62
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
534 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
535 cl_md5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 0, digest);/*62*/
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
536 if(memcmp(digest, test_digest62, 16))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
537 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
538 TRACE_EVENT("CHAP MD5: Test 6 failed!!");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
539 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
540 else
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
541 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
542 TRACE_EVENT("CHAP MD5: Test 6 passed.");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
543 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
544
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
545 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
546 * Test 7. Lenght := 80
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
547 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
548 cl_md5("12345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, digest);/*80*/
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
549 if(memcmp(digest, test_digest80, 16))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
550 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
551 TRACE_EVENT("CHAP MD5: Test 7 failed!!");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
552 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
553 else
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
554 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
555 TRACE_EVENT("CHAP MD5: Test 7 passed.");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
556 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
557
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
558 /*
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
559 * Test 8. Lenght := 160
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
560 */
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
561 cl_md5("12345678901234567890123456789012345678901234567890123456789012345678901234567890\
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
562 12345678901234567890123456789012345678901234567890123456789012345678901234567890", 0, digest);
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
563 if(memcmp(digest, test_digest160, 16))
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
564 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
565 TRACE_EVENT("CHAP MD5: Test 8 failed!!");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
566 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
567 else
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
568 {
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
569 TRACE_EVENT("CHAP MD5: Test 8 passed.");
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
570 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
571
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
572 }
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
573 #endif/*_SIMULATION_*/
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
574
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
575
d36f647c2432 gsm-fw/comlib: initial import of TI's source
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
576 #endif /* CL_MD5_C */