2 * arch/ubicom32/crypto/md5_ubicom32_asm.S
3 * MD5 (Message Digest 5) support for Ubicom32 v3 architecture
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
23 * Ubicom32 implementation derived from (with many thanks):
30 #include <asm/ip5000.h>
36 ;*****************************************************************************************
37 ; The function prototypes
38 ;*****************************************************************************************
39 ; void md5_ip5k_init(void)
40 ; void md5_ip5k_transform(u32_t *data_input)
41 ; void md5_get_digest(u32_t *digest)
43 ;*****************************************************************************************
45 ;*****************************************************************************************;
46 ; data_input is the pointer to the block of data over which the digest will be calculated.
47 ; It should be word aligned.
49 ; digest is the pointer to the block of data into which the digest (the output) will be written.
50 ; It should be word aligned.
53 ;*****************************************************************************************
55 ;*****************************************************************************************
58 ;*****************************************************************************************
59 ; An: Address Registers
60 ;*****************************************************************************************
62 #define an_data_input A3
63 #define an_security_block A4
65 ;*****************************************************************************************
67 ;*****************************************************************************************
68 #define HASH_MD5_IN0 0x01234567
69 #define HASH_MD5_IN1 0x89abcdef
70 #define HASH_MD5_IN2 0xfedcba98
71 #define HASH_MD5_IN3 0x76543210
73 #define HASH_SECURITY_BLOCK_CONTROL_INIT_NO_ENCYPTION 2
74 #define HASH_SECURITY_BLOCK_CONTROL_INIT_MD5 ((1 << 4) | HASH_SECURITY_BLOCK_CONTROL_INIT_NO_ENCYPTION)
76 ;*****************************************************************************************
77 ; Hash related defines
78 ;*****************************************************************************************
79 #define hash_control 0x00(an_security_block)
80 #define hash_control_low 0x02(an_security_block)
81 #define hash_status 0x04(an_security_block)
83 #define hash_input_0 0x30(an_security_block)
84 #define hash_input_1 0x34(an_security_block)
85 #define hash_input_2 0x38(an_security_block)
86 #define hash_input_3 0x3c(an_security_block)
87 #define hash_input_4 0x40(an_security_block)
89 #define hash_output_0 0x70(an_security_block)
90 #define hash_output_0_low 0x72(an_security_block)
91 #define hash_output_1 0x74(an_security_block)
92 #define hash_output_1_low 0x76(an_security_block)
93 #define hash_output_2 0x78(an_security_block)
94 #define hash_output_2_low 0x7a(an_security_block)
95 #define hash_output_3 0x7c(an_security_block)
96 #define hash_output_3_low 0x7e(an_security_block)
98 ;*****************************************************************************************
100 ;*****************************************************************************************
101 ; C compiler reserves RP (A5) for return address during subroutine call.
102 ; Use RP to return to caller
103 .macro call_return_macro
108 ;*****************************************************************************************
109 ; void md5_ip5k_init(void)
110 ; initialize the output registers of the hash module
112 ;.section .text.md5_ip5k_init,"ax",@progbits
114 .global _md5_ip5k_init
115 .func md5_ip5k_init, _md5_ip5k_init
118 moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
120 movei hash_control, #%hi(HASH_SECURITY_BLOCK_CONTROL_INIT_MD5)
121 movei hash_control_low, #%lo(HASH_SECURITY_BLOCK_CONTROL_INIT_MD5)
123 movei hash_output_0, #%hi(HASH_MD5_IN0)
124 movei hash_output_0_low, #%lo(HASH_MD5_IN0)
126 movei hash_output_1, #%hi(HASH_MD5_IN1)
127 movei hash_output_1_low, #%lo(HASH_MD5_IN1)
129 movei hash_output_2, #%hi(HASH_MD5_IN2)
130 movei hash_output_2_low, #%lo(HASH_MD5_IN2)
132 movei hash_output_3, #%hi(HASH_MD5_IN3)
133 movei hash_output_3_low, #%lo(HASH_MD5_IN3)
139 ;*****************************************************************************************
140 ; void md5_ip5k_init_digest(u32_t *hash_input)
141 ; initialize the output registers of the hash module
143 ;.section .text.md5_ip5k_init_digest,"ax",@progbits
145 .global _md5_ip5k_init_digest
146 .func md5_ip5k_init_digest, _md5_ip5k_init_digest
148 _md5_ip5k_init_digest:
149 movea an_data_input, D0
151 moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
153 movei hash_control, #%hi(HASH_SECURITY_BLOCK_CONTROL_INIT_MD5)
154 movei hash_control_low, #%lo(HASH_SECURITY_BLOCK_CONTROL_INIT_MD5)
156 move.4 hash_output_0, (an_data_input)4++
157 move.4 hash_output_1, (an_data_input)4++
158 move.4 hash_output_2, (an_data_input)4++
159 move.4 hash_output_3, (an_data_input)4++
164 ;*****************************************************************************************
165 ; void md5_ip5k_transform(u32_t *data_input)
166 ; performs intermediate transformation step for the hash calculation
168 ;.sect .text.md5_ip5k_transform,"ax",@progbits
170 .global _md5_ip5k_transform
171 .func md5_ip5k_transform, _md5_ip5k_transform
174 movea an_data_input, D0
176 moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
178 ; Write the first 128bits (16 bytes)
179 move.4 hash_input_0, (an_data_input)4++
180 move.4 hash_input_1, (an_data_input)4++
181 move.4 hash_input_2, (an_data_input)4++
182 move.4 hash_input_3, (an_data_input)4++
183 move.4 hash_input_4, D0
185 move.4 hash_input_0, (an_data_input)4++
186 move.4 hash_input_1, (an_data_input)4++
187 move.4 hash_input_2, (an_data_input)4++
188 move.4 hash_input_3, (an_data_input)4++
189 move.4 hash_input_4, D0
191 move.4 hash_input_0, (an_data_input)4++
192 move.4 hash_input_1, (an_data_input)4++
193 move.4 hash_input_2, (an_data_input)4++
194 move.4 hash_input_3, (an_data_input)4++
195 move.4 hash_input_4, D0
197 move.4 hash_input_0, (an_data_input)4++
198 move.4 hash_input_1, (an_data_input)4++
199 move.4 hash_input_2, (an_data_input)4++
200 move.4 hash_input_3, (an_data_input)4++
201 move.4 hash_input_4, D0
205 md5_ip5k_transform_wait:
206 ; wait for the module to calculate the output hash
208 jmpne.f md5_ip5k_transform_wait
213 ;*****************************************************************************************
214 ; void md5_ip5k_get_digest(u32_t *digest)
215 ; Return the hash of the input data
217 ;.sect .text.md5_get_digest,"ax",@progbits
219 .global _md5_ip5k_get_digest
220 .func md5_ip5k_get_digest, _md5_ip5k_get_digest
222 _md5_ip5k_get_digest:
225 moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
228 move.4 0(an_digest), hash_output_0
229 move.4 4(an_digest), hash_output_1
230 move.4 8(an_digest), hash_output_2
231 move.4 12(an_digest), hash_output_3