Skip to content

Commit aa4c06c

Browse files
committed
crypto: cleanup the internal constant declarations
1 parent 71784e2 commit aa4c06c

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

vlib/crypto/md5/md5.v

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ pub const size = 16
1515
// The blocksize of MD5 in bytes.
1616
pub const block_size = 64
1717

18-
const init0 = 0x67452301
18+
const init0 = u32(0x67452301)
1919
const init1 = u32(0xEFCDAB89)
2020
const init2 = u32(0x98BADCFE)
21-
const init3 = 0x10325476
21+
const init3 = u32(0x10325476)
2222

2323
// Digest represents the partial evaluation of a checksum.
2424
struct Digest {
@@ -110,9 +110,7 @@ pub fn (d &Digest) sum(b_in []u8) []u8 {
110110
mut d0 := d.clone()
111111
hash := d0.checksum()
112112
mut b_out := b_in.clone()
113-
for b in hash {
114-
b_out << b
115-
}
113+
b_out << hash
116114
return b_out
117115
}
118116

vlib/crypto/sha1/sha1.v

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ pub const size = 20
1616
pub const block_size = 64
1717

1818
const chunk = 64
19-
const init0 = 0x67452301
19+
const init0 = u32(0x67452301)
2020
const init1 = u32(0xEFCDAB89)
2121
const init2 = u32(0x98BADCFE)
22-
const init3 = 0x10325476
22+
const init3 = u32(0x10325476)
2323
const init4 = u32(0xC3D2E1F0)
2424

2525
// digest represents the partial evaluation of a checksum.
@@ -124,6 +124,7 @@ pub fn (d &Digest) sum(b_in []u8) []u8 {
124124
}
125125

126126
// checksum returns the current byte checksum of the `Digest`,
127+
@[direct_array_access]
127128
fn (mut d Digest) checksum() []u8 {
128129
mut len := d.len
129130
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.

vlib/crypto/sha1/sha1block_generic.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module sha1
88

99
import math.bits
1010

11-
const _k0 = 0x5A827999
12-
const _k1 = 0x6ED9EBA1
11+
const _k0 = u32(0x5A827999)
12+
const _k1 = u32(0x6ED9EBA1)
1313
const _k2 = u32(0x8F1BBCDC)
1414
const _k3 = u32(0xCA62C1D6)
1515

vlib/crypto/sha256/sha256.v

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ pub const size224 = 28
1717
pub const block_size = 64
1818

1919
const chunk = 64
20-
const init0 = 0x6A09E667
20+
const init0 = u32(0x6A09E667)
2121
const init1 = u32(0xBB67AE85)
22-
const init2 = 0x3C6EF372
22+
const init2 = u32(0x3C6EF372)
2323
const init3 = u32(0xA54FF53A)
24-
const init4 = 0x510E527F
24+
const init4 = u32(0x510E527F)
2525
const init5 = u32(0x9B05688C)
26-
const init6 = 0x1F83D9AB
27-
const init7 = 0x5BE0CD19
26+
const init6 = u32(0x1F83D9AB)
27+
const init7 = u32(0x5BE0CD19)
2828
const init0_224 = u32(0xC1059ED8)
29-
const init1_224 = 0x367CD507
30-
const init2_224 = 0x3070DD17
29+
const init1_224 = u32(0x367CD507)
30+
const init2_224 = u32(0x3070DD17)
3131
const init3_224 = u32(0xF70E5939)
3232
const init4_224 = u32(0xFFC00B31)
33-
const init5_224 = 0x68581511
34-
const init6_224 = 0x64F98FA7
33+
const init5_224 = u32(0x68581511)
34+
const init6_224 = u32(0x64F98FA7)
3535
const init7_224 = u32(0xBEFA4FA4)
3636

3737
// digest represents the partial evaluation of a checksum.
@@ -165,6 +165,7 @@ pub fn (d &Digest) sum(b_in []u8) []u8 {
165165

166166
// checksum returns the current byte checksum of the Digest,
167167
// it is an internal method and is not recommended because its results are not idempotent.
168+
@[direct_array_access]
168169
fn (mut d Digest) checksum() []u8 {
169170
mut len := d.len
170171
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.

0 commit comments

Comments
 (0)