Skip to content

Commit 333a451

Browse files
committed
Merge pull request #79 from ebfe/rust-deprecated
Rust updates
2 parents 86f18ea + e32d0a8 commit 333a451

File tree

4 files changed

+56
-64
lines changed

4 files changed

+56
-64
lines changed

src/rust-crypto/bcrypt_pbkdf.rs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn bcrypt_hash(hpass: &[u8], hsalt: &[u8], output: &mut [u8, ..32]) {
2020
}
2121

2222
let mut buf = [0u32, ..8];
23-
read_u32v_be(buf, bytes!("OxychromaticBlowfishSwatDynamite"));
23+
read_u32v_be(buf, b"OxychromaticBlowfishSwatDynamite");
2424

2525
for i in range_step(0u, 8, 2) {
2626
for _ in range(0, 64) {
@@ -166,76 +166,76 @@ mod test {
166166
#[test]
167167
fn test_openbsd_vectors() {
168168
struct Test{
169-
password: &'static [u8],
170-
salt: &'static [u8],
169+
password: Vec<u8>,
170+
salt: Vec<u8>,
171171
rounds: uint,
172-
out: &'static [u8],
172+
out: Vec<u8>,
173173
}
174174

175175
let tests = vec!(
176176
Test{
177-
password: bytes!("password"),
178-
salt: bytes!("salt"),
177+
password: Vec::from_slice(b"password"),
178+
salt: Vec::from_slice(b"salt"),
179179
rounds: 4,
180-
out: bytes!(
180+
out: vec![
181181
0x5b, 0xbf, 0x0c, 0xc2, 0x93, 0x58, 0x7f, 0x1c, 0x36, 0x35, 0x55, 0x5c, 0x27, 0x79, 0x65, 0x98,
182-
0xd4, 0x7e, 0x57, 0x90, 0x71, 0xbf, 0x42, 0x7e, 0x9d, 0x8f, 0xbe, 0x84, 0x2a, 0xba, 0x34, 0xd9),
182+
0xd4, 0x7e, 0x57, 0x90, 0x71, 0xbf, 0x42, 0x7e, 0x9d, 0x8f, 0xbe, 0x84, 0x2a, 0xba, 0x34, 0xd9],
183183
}, Test{
184-
password: bytes!("password"),
185-
salt: bytes!{0},
184+
password: Vec::from_slice(b"password"),
185+
salt: vec![0],
186186
rounds: 4,
187-
out: bytes!(0xc1, 0x2b, 0x56, 0x62, 0x35, 0xee, 0xe0, 0x4c, 0x21, 0x25, 0x98, 0x97, 0x0a, 0x57, 0x9a, 0x67),
187+
out: vec![0xc1, 0x2b, 0x56, 0x62, 0x35, 0xee, 0xe0, 0x4c, 0x21, 0x25, 0x98, 0x97, 0x0a, 0x57, 0x9a, 0x67],
188188
}, Test{
189-
password: bytes!{0},
190-
salt: bytes!("salt"),
189+
password: vec![0],
190+
salt: Vec::from_slice(b"salt"),
191191
rounds: 4,
192-
out: bytes!(0x60, 0x51, 0xbe, 0x18, 0xc2, 0xf4, 0xf8, 0x2c, 0xbf, 0x0e, 0xfe, 0xe5, 0x47, 0x1b, 0x4b, 0xb9),
192+
out: vec![0x60, 0x51, 0xbe, 0x18, 0xc2, 0xf4, 0xf8, 0x2c, 0xbf, 0x0e, 0xfe, 0xe5, 0x47, 0x1b, 0x4b, 0xb9],
193193
}, Test{
194-
password: bytes!("password\x00"),
195-
salt: bytes!("salt\x00"),
194+
password: Vec::from_slice(b"password\x00"),
195+
salt: Vec::from_slice(b"salt\x00"),
196196
rounds: 4,
197-
out: bytes!(
197+
out: vec![
198198
0x74, 0x10, 0xe4, 0x4c, 0xf4, 0xfa, 0x07, 0xbf, 0xaa, 0xc8, 0xa9, 0x28, 0xb1, 0x72, 0x7f, 0xac,
199-
0x00, 0x13, 0x75, 0xe7, 0xbf, 0x73, 0x84, 0x37, 0x0f, 0x48, 0xef, 0xd1, 0x21, 0x74, 0x30, 0x50),
199+
0x00, 0x13, 0x75, 0xe7, 0xbf, 0x73, 0x84, 0x37, 0x0f, 0x48, 0xef, 0xd1, 0x21, 0x74, 0x30, 0x50],
200200
}, Test{
201-
password: bytes!("pass\x00wor"),
202-
salt: bytes!("sa\x00l"),
201+
password: Vec::from_slice(b"pass\x00wor"),
202+
salt: Vec::from_slice(b"sa\x00l"),
203203
rounds: 4,
204-
out: bytes!(0xc2, 0xbf, 0xfd, 0x9d, 0xb3, 0x8f, 0x65, 0x69, 0xef, 0xef, 0x43, 0x72, 0xf4, 0xde, 0x83, 0xc0),
204+
out: vec![0xc2, 0xbf, 0xfd, 0x9d, 0xb3, 0x8f, 0x65, 0x69, 0xef, 0xef, 0x43, 0x72, 0xf4, 0xde, 0x83, 0xc0],
205205
}, Test{
206-
password: bytes!("pass\x00word"),
207-
salt: bytes!("sa\x00lt"),
206+
password: Vec::from_slice(b"pass\x00word"),
207+
salt: Vec::from_slice(b"sa\x00lt"),
208208
rounds: 4,
209-
out: bytes!(0x4b, 0xa4, 0xac, 0x39, 0x25, 0xc0, 0xe8, 0xd7, 0xf0, 0xcd, 0xb6, 0xbb, 0x16, 0x84, 0xa5, 0x6f),
209+
out: vec![0x4b, 0xa4, 0xac, 0x39, 0x25, 0xc0, 0xe8, 0xd7, 0xf0, 0xcd, 0xb6, 0xbb, 0x16, 0x84, 0xa5, 0x6f],
210210
}, Test{
211-
password: bytes!("password"),
212-
salt: bytes!("salt"),
211+
password: Vec::from_slice(b"password"),
212+
salt: Vec::from_slice(b"salt"),
213213
rounds: 8,
214-
out: bytes!(
214+
out: vec![
215215
0xe1, 0x36, 0x7e, 0xc5, 0x15, 0x1a, 0x33, 0xfa, 0xac, 0x4c, 0xc1, 0xc1, 0x44, 0xcd, 0x23, 0xfa,
216216
0x15, 0xd5, 0x54, 0x84, 0x93, 0xec, 0xc9, 0x9b, 0x9b, 0x5d, 0x9c, 0x0d, 0x3b, 0x27, 0xbe, 0xc7,
217217
0x62, 0x27, 0xea, 0x66, 0x08, 0x8b, 0x84, 0x9b, 0x20, 0xab, 0x7a, 0xa4, 0x78, 0x01, 0x02, 0x46,
218-
0xe7, 0x4b, 0xba, 0x51, 0x72, 0x3f, 0xef, 0xa9, 0xf9, 0x47, 0x4d, 0x65, 0x08, 0x84, 0x5e, 0x8d),
218+
0xe7, 0x4b, 0xba, 0x51, 0x72, 0x3f, 0xef, 0xa9, 0xf9, 0x47, 0x4d, 0x65, 0x08, 0x84, 0x5e, 0x8d],
219219
}, Test{
220-
password: bytes!("password"),
221-
salt: bytes!("salt"),
220+
password: Vec::from_slice(b"password"),
221+
salt: Vec::from_slice(b"salt"),
222222
rounds: 42,
223-
out: bytes!(0x83, 0x3c, 0xf0, 0xdc, 0xf5, 0x6d, 0xb6, 0x56, 0x08, 0xe8, 0xf0, 0xdc, 0x0c, 0xe8, 0x82, 0xbd),
223+
out: vec![0x83, 0x3c, 0xf0, 0xdc, 0xf5, 0x6d, 0xb6, 0x56, 0x08, 0xe8, 0xf0, 0xdc, 0x0c, 0xe8, 0x82, 0xbd],
224224
}, Test{
225-
password: bytes!("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."),
226-
salt: bytes!("salis\x00"),
225+
password: Vec::from_slice(b"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."),
226+
salt: Vec::from_slice(b"salis\x00"),
227227
rounds: 8,
228-
out: bytes!(0x10, 0x97, 0x8b, 0x07, 0x25, 0x3d, 0xf5, 0x7f, 0x71, 0xa1, 0x62, 0xeb, 0x0e, 0x8a, 0xd3, 0x0a),
228+
out: vec![0x10, 0x97, 0x8b, 0x07, 0x25, 0x3d, 0xf5, 0x7f, 0x71, 0xa1, 0x62, 0xeb, 0x0e, 0x8a, 0xd3, 0x0a],
229229
}, Test{
230-
password: bytes!(0x0d, 0xb3, 0xac, 0x94, 0xb3, 0xee, 0x53, 0x28, 0x4f, 0x4a, 0x22, 0x89, 0x3b, 0x3c, 0x24, 0xae),
231-
salt: bytes!(0x3a, 0x62, 0xf0, 0xf0, 0xdb, 0xce, 0xf8, 0x23, 0xcf, 0xcc, 0x85, 0x48, 0x56, 0xea, 0x10, 0x28),
230+
password: vec![0x0d, 0xb3, 0xac, 0x94, 0xb3, 0xee, 0x53, 0x28, 0x4f, 0x4a, 0x22, 0x89, 0x3b, 0x3c, 0x24, 0xae],
231+
salt: vec![0x3a, 0x62, 0xf0, 0xf0, 0xdb, 0xce, 0xf8, 0x23, 0xcf, 0xcc, 0x85, 0x48, 0x56, 0xea, 0x10, 0x28],
232232
rounds: 8,
233-
out: bytes!(0x20, 0x44, 0x38, 0x17, 0x5e, 0xee, 0x7c, 0xe1, 0x36, 0xc9, 0x1b, 0x49, 0xa6, 0x79, 0x23, 0xff),
233+
out: vec![0x20, 0x44, 0x38, 0x17, 0x5e, 0xee, 0x7c, 0xe1, 0x36, 0xc9, 0x1b, 0x49, 0xa6, 0x79, 0x23, 0xff],
234234
}, Test{
235-
password: bytes!(0x0d, 0xb3, 0xac, 0x94, 0xb3, 0xee, 0x53, 0x28, 0x4f, 0x4a, 0x22, 0x89, 0x3b, 0x3c, 0x24, 0xae),
236-
salt: bytes!(0x3a, 0x62, 0xf0, 0xf0, 0xdb, 0xce, 0xf8, 0x23, 0xcf, 0xcc, 0x85, 0x48, 0x56, 0xea, 0x10, 0x28),
235+
password: vec![0x0d, 0xb3, 0xac, 0x94, 0xb3, 0xee, 0x53, 0x28, 0x4f, 0x4a, 0x22, 0x89, 0x3b, 0x3c, 0x24, 0xae],
236+
salt: vec![0x3a, 0x62, 0xf0, 0xf0, 0xdb, 0xce, 0xf8, 0x23, 0xcf, 0xcc, 0x85, 0x48, 0x56, 0xea, 0x10, 0x28],
237237
rounds: 8,
238-
out: bytes!(
238+
out: vec![
239239
0x20, 0x54, 0xb9, 0xff, 0xf3, 0x4e, 0x37, 0x21, 0x44, 0x03, 0x34, 0x74, 0x68, 0x28, 0xe9, 0xed,
240240
0x38, 0xde, 0x4b, 0x72, 0xe0, 0xa6, 0x9a, 0xdc, 0x17, 0x0a, 0x13, 0xb5, 0xe8, 0xd6, 0x46, 0x38,
241241
0x5e, 0xa4, 0x03, 0x4a, 0xe6, 0xd2, 0x66, 0x00, 0xee, 0x23, 0x32, 0xc5, 0xed, 0x40, 0xad, 0x55,
@@ -251,14 +251,14 @@ mod test {
251251
0x3f, 0x54, 0x8d, 0x5e, 0xeb, 0xa4, 0x21, 0x13, 0x97, 0xe2, 0xfb, 0x06, 0x2e, 0x52, 0x6e, 0x1d,
252252
0x68, 0xf4, 0x6a, 0x4c, 0xe2, 0x56, 0x18, 0x5b, 0x4b, 0xad, 0xc2, 0x68, 0x5f, 0xbe, 0x78, 0xe1,
253253
0xc7, 0x65, 0x7b, 0x59, 0xf8, 0x3a, 0xb9, 0xab, 0x80, 0xcf, 0x93, 0x18, 0xd6, 0xad, 0xd1, 0xf5,
254-
0x93, 0x3f, 0x12, 0xd6, 0xf3, 0x61, 0x82, 0xc8, 0xe8, 0x11, 0x5f, 0x68, 0x03, 0x0a, 0x12, 0x44),
254+
0x93, 0x3f, 0x12, 0xd6, 0xf3, 0x61, 0x82, 0xc8, 0xe8, 0x11, 0x5f, 0x68, 0x03, 0x0a, 0x12, 0x44],
255255
},
256256
);
257257

258258
for t in tests.iter() {
259259
let mut out = Vec::from_elem(t.out.len(), 0u8);
260-
bcrypt_pbkdf(t.password, t.salt, t.rounds, out.as_mut_slice());
261-
assert_eq!(out.as_slice(), t.out.as_slice());
260+
bcrypt_pbkdf(t.password.as_slice(), t.salt.as_slice(), t.rounds, out.as_mut_slice());
261+
assert_eq!(out, t.out);
262262
}
263263
}
264264
}

src/rust-crypto/chacha20.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ impl ChaCha20 {
3636
fn expand(key: &[u8], nonce: &[u8]) -> [u32, ..16] {
3737
let mut state = [0u32, ..16];
3838
let constant = match key.len() {
39-
16 => bytes!("expand 16-byte k"),
40-
32 => bytes!("expand 32-byte k"),
39+
16 => b"expand 16-byte k",
40+
32 => b"expand 32-byte k",
4141
_ => unreachable!(),
4242
};
4343

src/rust-crypto/cryptoutil.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use std;
12-
use std::num::{One, Zero, CheckedAdd};
12+
use std::num::{One, Zero, Int, CheckedAdd};
1313
use std::slice::bytes::{MutableByteVector, copy_memory};
1414

1515
use buffer::{ReadBuffer, WriteBuffer, BufferResult, BufferUnderflow, BufferOverflow};
@@ -19,48 +19,44 @@ use symmetriccipher::{SynchronousStreamCipher, SymmetricCipherError};
1919
/// format.
2020
pub fn write_u64_be(dst: &mut[u8], input: u64) {
2121
use std::mem::transmute;
22-
use std::mem::to_be64;
2322
assert!(dst.len() == 8);
2423
unsafe {
2524
let x: *mut u64 = transmute(dst.unsafe_mut_ref(0));
26-
*x = to_be64(input);
25+
*x = input.to_be();
2726
}
2827
}
2928

3029
/// Write a u32 into a vector, which must be 4 bytes long. The value is written in big-endian
3130
/// format.
3231
pub fn write_u32_be(dst: &mut[u8], input: u32) {
3332
use std::mem::transmute;
34-
use std::mem::to_be32;
3533
assert!(dst.len() == 4);
3634
unsafe {
3735
let x: *mut u32 = transmute(dst.unsafe_mut_ref(0));
38-
*x = to_be32(input);
36+
*x = input.to_be();
3937
}
4038
}
4139

4240
/// Write a u32 into a vector, which must be 4 bytes long. The value is written in little-endian
4341
/// format.
4442
pub fn write_u32_le(dst: &mut[u8], input: u32) {
4543
use std::mem::transmute;
46-
use std::mem::to_le32;
4744
assert!(dst.len() == 4);
4845
unsafe {
4946
let x: *mut u32 = transmute(dst.unsafe_mut_ref(0));
50-
*x = to_le32(input);
47+
*x = input.to_le();
5148
}
5249
}
5350

5451
/// Read a vector of bytes into a vector of u64s. The values are read in big-endian format.
5552
pub fn read_u64v_be(dst: &mut[u64], input: &[u8]) {
5653
use std::mem::transmute;
57-
use std::mem::to_be64;
5854
assert!(dst.len() * 8 == input.len());
5955
unsafe {
6056
let mut x: *mut u64 = transmute(dst.unsafe_mut_ref(0));
6157
let mut y: *u64 = transmute(input.unsafe_ref(0));
6258
for _ in range(0, dst.len()) {
63-
*x = to_be64(*y);
59+
*x = (*y).to_be();
6460
x = x.offset(1);
6561
y = y.offset(1);
6662
}
@@ -70,13 +66,12 @@ pub fn read_u64v_be(dst: &mut[u64], input: &[u8]) {
7066
/// Read a vector of bytes into a vector of u32s. The values are read in big-endian format.
7167
pub fn read_u32v_be(dst: &mut[u32], input: &[u8]) {
7268
use std::mem::transmute;
73-
use std::mem::to_be32;
7469
assert!(dst.len() * 4 == input.len());
7570
unsafe {
7671
let mut x: *mut u32 = transmute(dst.unsafe_mut_ref(0));
7772
let mut y: *u32 = transmute(input.unsafe_ref(0));
7873
for _ in range(0, dst.len()) {
79-
*x = to_be32(*y);
74+
*x = (*y).to_be();
8075
x = x.offset(1);
8176
y = y.offset(1);
8277
}
@@ -86,13 +81,12 @@ pub fn read_u32v_be(dst: &mut[u32], input: &[u8]) {
8681
/// Read a vector of bytes into a vector of u32s. The values are read in little-endian format.
8782
pub fn read_u32v_le(dst: &mut[u32], input: &[u8]) {
8883
use std::mem::transmute;
89-
use std::mem::to_le32;
9084
assert!(dst.len() * 4 == input.len());
9185
unsafe {
9286
let mut x: *mut u32 = transmute(dst.unsafe_mut_ref(0));
9387
let mut y: *u32 = transmute(input.unsafe_ref(0));
9488
for _ in range(0, dst.len()) {
95-
*x = to_le32(*y);
89+
*x = (*y).to_le();
9690
x = x.offset(1);
9791
y = y.offset(1);
9892
}
@@ -102,22 +96,20 @@ pub fn read_u32v_le(dst: &mut[u32], input: &[u8]) {
10296
/// Read the value of a vector of bytes as a u32 value in little-endian format.
10397
pub fn read_u32_le(input: &[u8]) -> u32 {
10498
use std::mem::transmute;
105-
use std::mem::to_le32;
10699
assert!(input.len() == 4);
107100
unsafe {
108101
let tmp: *u32 = transmute(input.unsafe_ref(0));
109-
return to_le32(*tmp);
102+
return (*tmp).to_le();
110103
}
111104
}
112105

113106
/// Read the value of a vector of bytes as a u32 value in big-endian format.
114107
pub fn read_u32_be(input: &[u8]) -> u32 {
115108
use std::mem::transmute;
116-
use std::mem::to_be32;
117109
assert!(input.len() == 4);
118110
unsafe {
119111
let tmp: *u32 = transmute(input.unsafe_ref(0));
120-
return to_be32(*tmp);
112+
return (*tmp).to_be();
121113
}
122114
}
123115

src/rust-crypto/poly1305.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ mod test {
335335
#[test]
336336
fn test_tls_vectors() {
337337
// from http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04
338-
let key = bytes!("this is 32-byte key for Poly1305");
338+
let key = b"this is 32-byte key for Poly1305";
339339
let msg = [0u8, ..32];
340340
let expected = [
341341
0x49, 0xec, 0x78, 0x09, 0x0e, 0x48, 0x1e, 0xc6,
@@ -345,7 +345,7 @@ mod test {
345345
poly1305(key, msg, mac.as_mut_slice());
346346
assert_eq!(mac.as_slice(), expected.as_slice());
347347

348-
let msg = bytes!("Hello world!");
348+
let msg = b"Hello world!";
349349
let expected= [
350350
0xa6, 0xf7, 0x45, 0x00, 0x8f, 0x81, 0xc9, 0x16,
351351
0xa2, 0x0d, 0xcc, 0x74, 0xee, 0xf2, 0xb2, 0xf0,

0 commit comments

Comments
 (0)