2
* Copyright (C) 2006 Vincent Hanquez <tab@snarc.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published
6
* by the Free Software Foundation; version 2 only.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* SHA implementation low level operation
19
typedef unsigned long long u64;
22
static inline unsigned int rol32(unsigned int word, unsigned int shift)
24
return (word << shift) | (word >> (32 - shift));
27
static inline unsigned int ror32(unsigned int word, unsigned int shift)
29
return (word >> shift) | (word << (32 - shift));
32
static inline u64 rol64(u64 word, unsigned int shift)
34
return (word << shift) | (word >> (64 - shift));
37
static inline u64 ror64(u64 word, unsigned int shift)
39
return (word >> shift) | (word << (64 - shift));
42
#if (defined(__i386__) || defined(__x86_64__)) && !defined(NO_INLINE_ASM)
43
static inline unsigned int swap32(unsigned int a)
45
asm ("bswap %0" : "=r" (a) : "0" (a));
49
static inline unsigned int swap32(unsigned int a)
51
return (a << 24) | ((a & 0xff00) << 8) | ((a >> 8) & 0xff00) | (a >> 24);
55
#if defined(__x86_64__) && !defined(NO_INLINE_ASM)
56
static inline u64 swap64(u64 a)
58
asm ("bswap %0" : "=r" (a) : "0" (a));
62
static inline u64 swap64(u64 a)
64
return ((u64) swap32((unsigned int) (a >> 32))) |
65
(((u64) swap32((unsigned int) a)) << 32);
69
/* big endian to cpu */
71
#if LITTLE_ENDIAN == BYTE_ORDER
72
#define be32_to_cpu(a) swap32(a)
73
#define cpu_to_be32(a) swap32(a)
74
#define be64_to_cpu(a) swap64(a)
75
#define cpu_to_be64(a) swap64(a)
76
#elif BIG_ENDIAN == BYTE_ORDER
77
#define be32_to_cpu(a) (a)
78
#define cpu_to_be32(a) (a)
79
#define be64_to_cpu(a) (a)
80
#define cpu_to_be64(a) (a)
82
#error "endian not supported"
85
#endif /* !SHA_OP_H */