Root/target/linux/ubicom32/files/arch/ubicom32/crypto/sha1_ubicom32_asm.S

1/*
2 * arch/ubicom32/crypto/sha1_ubicom32_asm.S
3 * SHA1 hash support for Ubicom32 architecture V3.
4 *
5 * (C) Copyright 2009, Ubicom, Inc.
6 *
7 * This file is part of the Ubicom32 Linux Kernel Port.
8 *
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.
13 *
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.
18 *
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/>.
22 *
23 * Ubicom32 implementation derived from (with many thanks):
24 * arch/m68knommu
25 * arch/blackfin
26 * arch/parisc
27 */
28
29#define __ASM__
30#include <asm/ip5000.h>
31
32#ifndef RP
33#define RP A5
34#endif
35
36;*****************************************************************************************
37; The function prototype
38;*****************************************************************************************
39; void sha1_ip5k_init(void)
40; void sha1_ip5k_transform(u32_t *data_input)
41; void sha1_ip5k_output(u32_t *digest)
42
43;*****************************************************************************************
44; Inputs
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.
48;
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.
51;
52
53;*****************************************************************************************
54; Outputs
55;*****************************************************************************************
56; None
57
58;*****************************************************************************************
59; Hash Constants
60;*****************************************************************************************
61#define HASH_SHA1_IN0 0x67452301
62#define HASH_SHA1_IN1 0xefcdab89
63#define HASH_SHA1_IN2 0x98badcfe
64#define HASH_SHA1_IN3 0x10325476
65#define HASH_SHA1_IN4 0xc3d2e1f0
66
67#define HASH_SECURITY_BLOCK_CONTROL_INIT_NO_ENCYPTION 2
68#define HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1 ((1 << 5) | HASH_SECURITY_BLOCK_CONTROL_INIT_NO_ENCYPTION)
69
70;*****************************************************************************************
71; An: Address Registers
72;*****************************************************************************************
73#define an_digest a4
74#define an_data_input a4
75#define an_security_block a3
76
77;*****************************************************************************************
78; Hash related defines
79;*****************************************************************************************
80#define hash_control 0x00(an_security_block)
81#define hash_control_low 0x02(an_security_block)
82#define hash_status 0x04(an_security_block)
83
84#define hash_input_0 0x30(an_security_block)
85#define hash_input_1 0x34(an_security_block)
86#define hash_input_2 0x38(an_security_block)
87#define hash_input_3 0x3c(an_security_block)
88#define hash_input_4 0x40(an_security_block)
89
90#define hash_output_0 0x70(an_security_block)
91#define hash_output_0_low 0x72(an_security_block)
92#define hash_output_1 0x74(an_security_block)
93#define hash_output_1_low 0x76(an_security_block)
94#define hash_output_2 0x78(an_security_block)
95#define hash_output_2_low 0x7a(an_security_block)
96#define hash_output_3 0x7c(an_security_block)
97#define hash_output_3_low 0x7e(an_security_block)
98#define hash_output_4 0x80(an_security_block)
99#define hash_output_4_low 0x82(an_security_block)
100
101;*****************************************************************************************
102; Assembly macros
103;*****************************************************************************************
104    ; C compiler reserves RP (A5) for return address during subroutine call.
105    ; Use RP to return to caller
106.macro call_return_macro
107    calli RP, 0(RP)
108.endm
109
110;*****************************************************************************************
111; void sha1_ip5k_init(void)
112; initialize the output registers of the hash module
113
114    ;.section .text.sha1_ip5k_init,"ax",@progbits
115    .section .ocm_text,"ax",@progbits
116    .global _sha1_ip5k_init
117    .func sha1_ip5k_init, _sha1_ip5k_init
118
119_sha1_ip5k_init:
120    moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
121
122    movei hash_control, #%hi(HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1)
123    movei hash_control_low, #%lo(HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1)
124
125    movei hash_output_0, #%hi(HASH_SHA1_IN0)
126    movei hash_output_0_low, #%lo(HASH_SHA1_IN0)
127
128    movei hash_output_1, #%hi(HASH_SHA1_IN1)
129    movei hash_output_1_low, #%lo(HASH_SHA1_IN1)
130
131    movei hash_output_2, #%hi(HASH_SHA1_IN2)
132    movei hash_output_2_low, #%lo(HASH_SHA1_IN2)
133
134    movei hash_output_3, #%hi(HASH_SHA1_IN3)
135    movei hash_output_3_low, #%lo(HASH_SHA1_IN3)
136
137    movei hash_output_4, #%hi(HASH_SHA1_IN4)
138    movei hash_output_4_low, #%lo(HASH_SHA1_IN4)
139
140    call_return_macro
141    .endfunc
142
143;*****************************************************************************************
144; void sha1_ip5k_init_digest(u32_t *hash_input)
145; initialize the output registers of the hash module
146
147    ;.section .text.sha1_ip5k_init_digest,"ax",@progbits
148    .section .ocm_text,"ax",@progbits
149    .global _sha1_ip5k_init_digest
150    .func sha1_ip5k_init_digest, _sha1_ip5k_init_digest
151
152_sha1_ip5k_init_digest:
153    movea an_data_input, D0
154
155    moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
156
157    movei hash_control, #%hi(HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1)
158    movei hash_control_low, #%lo(HASH_SECURITY_BLOCK_CONTROL_INIT_SHA1)
159
160    move.4 hash_output_0, (an_data_input)4++
161    move.4 hash_output_1, (an_data_input)4++
162    move.4 hash_output_2, (an_data_input)4++
163    move.4 hash_output_3, (an_data_input)4++
164    move.4 hash_output_4, (an_data_input)4++
165
166    call_return_macro
167    .endfunc
168
169;*****************************************************************************************
170; void sha1_ip5k_transform(u32_t *data_input)
171; performs intermediate transformation step for the hash calculation
172
173    ;.section .text.sha1_ip5k_transform,"ax",@progbits
174    .section .ocm_text,"ax",@progbits
175    .global _sha1_ip5k_transform
176    .func sha1_ip5k_transform, _sha1_ip5k_transform
177
178_sha1_ip5k_transform:
179    movea an_data_input, D0
180
181    moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
182
183    ; Write the first 128bits (16 bytes)
184    move.4 hash_input_0, (an_data_input)4++
185    move.4 hash_input_1, (an_data_input)4++
186    move.4 hash_input_2, (an_data_input)4++
187    move.4 hash_input_3, (an_data_input)4++
188    move.4 hash_input_4, D0
189
190    move.4 hash_input_0, (an_data_input)4++
191    move.4 hash_input_1, (an_data_input)4++
192    move.4 hash_input_2, (an_data_input)4++
193    move.4 hash_input_3, (an_data_input)4++
194    move.4 hash_input_4, D0
195
196    move.4 hash_input_0, (an_data_input)4++
197    move.4 hash_input_1, (an_data_input)4++
198    move.4 hash_input_2, (an_data_input)4++
199    move.4 hash_input_3, (an_data_input)4++
200    move.4 hash_input_4, D0
201
202    move.4 hash_input_0, (an_data_input)4++
203    move.4 hash_input_1, (an_data_input)4++
204    move.4 hash_input_2, (an_data_input)4++
205    move.4 hash_input_3, (an_data_input)4++
206    move.4 hash_input_4, D0
207
208    pipe_flush 0
209
210sha1_ip5k_transform_wait:
211    ; wait for the module to calculate the output hash
212    btst hash_status, #0
213    jmpne.f sha1_ip5k_transform_wait
214
215    call_return_macro
216    .endfunc
217
218;*****************************************************************************************
219; void sha1_ip5k_output(u32_t *digest)
220; Return the hash of the input data
221
222    ;.section .text.sha1_ip5k_output,"ax",@progbits
223    .section .ocm_text,"ax",@progbits
224    .global _sha1_ip5k_output
225    .func sha1_ip5k_output, _sha1_ip5k_output
226
227_sha1_ip5k_output:
228    movea an_digest, D0
229
230    moveai an_security_block, #SECURITY_BASE_EFFECTIVE_ADDRESS
231
232    ; we have finished
233    move.4 0(an_digest), hash_output_0
234    move.4 4(an_digest), hash_output_1
235    move.4 8(an_digest), hash_output_2
236    move.4 12(an_digest), hash_output_3
237    move.4 16(an_digest), hash_output_4
238
239    call_return_macro
240    .endfunc
241
242;*****************************************************************************************
243;END ;End of program code
244;*****************************************************************************************
245

Archive Download this file



interactive