/
cryptographic.py
124 lines (95 loc) · 2.52 KB
/
cryptographic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Implements various cryptographic hashing algorithms.
"""
import hashlib
from refinery.units.crypto.hash import HashUnit
class md4(HashUnit):
"""
Returns the MD4 hash of the input data.
"""
def _algorithm(self, data):
from Cryptodome.Hash import MD4
return MD4.new(data)
class md2(HashUnit):
"""
Returns the MD2 hash of the input data.
"""
def _algorithm(self, data):
from Cryptodome.Hash import MD2
return MD2.new(data)
class md5(HashUnit):
"""
Returns the MD5 hash of the input data.
"""
def _algorithm(self, data):
return hashlib.md5(data)
class sha1(HashUnit):
"""
Returns the SHA1 hash of the input data.
"""
def _algorithm(self, data):
return hashlib.sha1(data)
class sha224(HashUnit):
"""
Returns the SHA224 hash of the input data.
"""
def _algorithm(self, data):
return hashlib.sha224(data)
class sha256(HashUnit):
"""
Returns the SHA256 hash of the input data.
"""
def _algorithm(self, data):
return hashlib.sha256(data)
class sha384(HashUnit):
"""
Returns the SHA384 hash of the input data.
"""
def _algorithm(self, data):
return hashlib.sha384(data)
class sha512(HashUnit):
"""
Returns the SHA512 hash of the input data.
"""
def _algorithm(self, data):
return hashlib.sha512(data)
class blk224(HashUnit):
"""
Returns the BLK224 hash of the input data.
"""
def _algorithm(self, data):
return hashlib.blake2b(data, digest_size=28)
class blk256(HashUnit):
"""
Returns the BLK256 hash of the input data.
"""
def _algorithm(self, data):
return hashlib.blake2b(data, digest_size=32)
class blk384(HashUnit):
"""
Returns the BLK384 hash of the input data.
"""
def _algorithm(self, data):
return hashlib.blake2b(data, digest_size=48)
class blk512(HashUnit):
"""
Returns the BLK512 hash of the input data.
"""
def _algorithm(self, data):
return hashlib.blake2b(data, digest_size=64)
class ripemd160(HashUnit):
"""
Returns the RIPEMD-160 hash of the input data.
"""
def _algorithm(self, data):
from Cryptodome.Hash import RIPEMD160
return RIPEMD160.new(data)
class ripemd128(HashUnit):
"""
Returns the RIPEMD-128 hash of the input data.
"""
def _algorithm(self, data):
from refinery.lib.ripemd128 import ripemd128
return ripemd128(data)