Skip to content

Commit

Permalink
Merge #342
Browse files Browse the repository at this point in the history
342: Update libsodium to 1.0.18 r=dnaq a=kurnevsky

Alignment patch is no longer needed with this update.

Co-authored-by: Evgeny Kurnevsky <[email protected]>
  • Loading branch information
bors[bot] and kurnevsky committed Jun 12, 2019
2 parents 4b30e8a + 99560a1 commit 46cdc31
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 44 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 0.2.2 (???)
# 0.2.3 (???)

* Update libsodium to 1.0.18 (#342)

# 0.2.2 (May 16, 2019)

* Bundle libsodium .a .lib for win & cygwin (#332)
* Add `AsRef<[u8]>` for newtypes (#323)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ cargo build
See https://download.libsodium.org/doc/installation.

```
export SODIUM_LIB_DIR=/home/user/libsodium-1.0.17/release/lib/
export SODIUM_LIB_DIR=/home/user/libsodium-1.0.18/release/lib/
export SODIUM_SHARED=1
cargo build
```
Expand Down
2 changes: 1 addition & 1 deletion libsodium-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern crate pkg_config;

use std::env;

static VERSION: &'static str = "1.0.17";
static VERSION: &'static str = "1.0.18";

fn main() {
println!("cargo:rerun-if-env-changed=SODIUM_LIB_DIR");
Expand Down
Binary file removed libsodium-sys/libsodium-1.0.17.tar.gz
Binary file not shown.
Binary file added libsodium-sys/libsodium-1.0.18.tar.gz
Binary file not shown.
Binary file modified libsodium-sys/mingw/win32/libsodium.a
Binary file not shown.
Binary file modified libsodium-sys/mingw/win64/libsodium.a
Binary file not shown.
Binary file modified libsodium-sys/msvc/Win32/Debug/v140/libsodium.lib
Binary file not shown.
Binary file modified libsodium-sys/msvc/Win32/Release/v140/libsodium.lib
Binary file not shown.
Binary file modified libsodium-sys/msvc/x64/Debug/v140/libsodium.lib
Binary file not shown.
Binary file modified libsodium-sys/msvc/x64/Release/v140/libsodium.lib
Binary file not shown.
22 changes: 0 additions & 22 deletions libsodium-sys/src/alignment_fix.patch

This file was deleted.

11 changes: 2 additions & 9 deletions libsodium-sys/src/gen.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# call this script manually to regen bindings from a new version of libsodium
# make sure that you have up-to-date bindgen (at least 0.48.0 to avoid problems with alignments)

# a whitelist regex to generate entities
REGEX="(SODIUM|sodium|crypto|randombytes)_.*"

bindgen PATH_TO/libsodium-1.0.17/src/libsodium/include/sodium.h -o sodium_bindings.rs \
bindgen PATH_TO/libsodium-1.0.18/src/libsodium/include/sodium.h -o sodium_bindings.rs \
--ctypes-prefix=libc --use-core \
--generate=functions,types,vars \
--whitelist-function=$REGEX \
--whitelist-type=$REGEX \
--whitelist-var=$REGEX

# bindgen fails to compute the alignment in some cases:
# - the alignment of crypto_onetimeauth_poly1305_state should be 16
# see https://github.com/jedisct1/libsodium/blob/1.0.17/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h#L19
# - the alignment of crypto_generichash_blake2b_state should be 64
# see https://github.com/jedisct1/libsodium/blob/1.0.17/src/libsodium/include/sodium/crypto_generichash_blake2b.h#L23
# the patch below fixes this
git apply alignment_fix.patch
158 changes: 150 additions & 8 deletions libsodium-sys/src/sodium_bindings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* automatically generated by rust-bindgen */

pub const SODIUM_VERSION_STRING: &'static [u8; 7usize] = b"1.0.17\0";
pub const SODIUM_VERSION_STRING: &'static [u8; 7usize] = b"1.0.18\0";
pub const SODIUM_LIBRARY_VERSION_MAJOR: u32 = 10;
pub const SODIUM_LIBRARY_VERSION_MINOR: u32 = 2;
pub const SODIUM_LIBRARY_VERSION_MINOR: u32 = 3;
pub const crypto_aead_aes256gcm_KEYBYTES: u32 = 32;
pub const crypto_aead_aes256gcm_NSECBYTES: u32 = 0;
pub const crypto_aead_aes256gcm_NPUBBYTES: u32 = 12;
Expand Down Expand Up @@ -234,10 +234,17 @@ pub const crypto_box_curve25519xchacha20poly1305_MACBYTES: u32 = 16;
pub const crypto_box_curve25519xchacha20poly1305_SEALBYTES: u32 = 48;
pub const crypto_core_ed25519_BYTES: u32 = 32;
pub const crypto_core_ed25519_UNIFORMBYTES: u32 = 32;
pub const crypto_core_ed25519_HASHBYTES: u32 = 64;
pub const crypto_core_ed25519_SCALARBYTES: u32 = 32;
pub const crypto_core_ed25519_NONREDUCEDSCALARBYTES: u32 = 64;
pub const crypto_core_ristretto255_BYTES: u32 = 32;
pub const crypto_core_ristretto255_HASHBYTES: u32 = 64;
pub const crypto_core_ristretto255_SCALARBYTES: u32 = 32;
pub const crypto_core_ristretto255_NONREDUCEDSCALARBYTES: u32 = 64;
pub const crypto_scalarmult_ed25519_BYTES: u32 = 32;
pub const crypto_scalarmult_ed25519_SCALARBYTES: u32 = 32;
pub const crypto_scalarmult_ristretto255_BYTES: u32 = 32;
pub const crypto_scalarmult_ristretto255_SCALARBYTES: u32 = 32;
pub const crypto_secretbox_xchacha20poly1305_KEYBYTES: u32 = 32;
pub const crypto_secretbox_xchacha20poly1305_NONCEBYTES: u32 = 24;
pub const crypto_secretbox_xchacha20poly1305_MACBYTES: u32 = 16;
Expand Down Expand Up @@ -302,6 +309,7 @@ extern "C" {
pub fn crypto_aead_aes256gcm_messagebytes_max() -> usize;
}
#[repr(C)]
#[repr(align(16))]
#[derive(Copy, Clone)]
pub struct crypto_aead_aes256gcm_state_ {
pub opaque: [libc::c_uchar; 512usize],
Expand All @@ -315,7 +323,7 @@ fn bindgen_test_layout_crypto_aead_aes256gcm_state_() {
);
assert_eq!(
::core::mem::align_of::<crypto_aead_aes256gcm_state_>(),
1usize,
16usize,
concat!("Alignment of ", stringify!(crypto_aead_aes256gcm_state_))
);
assert_eq!(
Expand Down Expand Up @@ -1489,7 +1497,8 @@ extern "C" {
c: *const libc::c_uchar,
) -> libc::c_int;
}
#[repr(C, align(64))]
#[repr(C)]
#[repr(align(64))]
#[derive(Copy, Clone)]
pub struct crypto_generichash_blake2b_state {
pub opaque: [libc::c_uchar; 384usize],
Expand All @@ -1501,6 +1510,14 @@ fn bindgen_test_layout_crypto_generichash_blake2b_state() {
384usize,
concat!("Size of: ", stringify!(crypto_generichash_blake2b_state))
);
assert_eq!(
::core::mem::align_of::<crypto_generichash_blake2b_state>(),
64usize,
concat!(
"Alignment of ",
stringify!(crypto_generichash_blake2b_state)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<crypto_generichash_blake2b_state>())).opaque as *const _
Expand Down Expand Up @@ -1763,7 +1780,8 @@ extern "C" {
client_pk: *const libc::c_uchar,
) -> libc::c_int;
}
#[repr(C, align(16))]
#[repr(C)]
#[repr(align(16))]
#[derive(Copy, Clone)]
pub struct crypto_onetimeauth_poly1305_state {
pub opaque: [libc::c_uchar; 256usize],
Expand All @@ -1775,6 +1793,14 @@ fn bindgen_test_layout_crypto_onetimeauth_poly1305_state() {
256usize,
concat!("Size of: ", stringify!(crypto_onetimeauth_poly1305_state))
);
assert_eq!(
::core::mem::align_of::<crypto_onetimeauth_poly1305_state>(),
16usize,
concat!(
"Alignment of ",
stringify!(crypto_onetimeauth_poly1305_state)
)
);
assert_eq!(
unsafe {
&(*(::core::ptr::null::<crypto_onetimeauth_poly1305_state>())).opaque as *const _
Expand Down Expand Up @@ -3044,11 +3070,9 @@ extern "C" {
pub fn randombytes_implementation_name() -> *const libc::c_char;
}
extern "C" {
#[link_name = "\u{1}randombytes_salsa20_implementation"]
pub static mut randombytes_salsa20_implementation: randombytes_implementation;
pub static mut randombytes_internal_implementation: randombytes_implementation;
}
extern "C" {
#[link_name = "\u{1}randombytes_sysrandom_implementation"]
pub static mut randombytes_sysrandom_implementation: randombytes_implementation;
}
extern "C" {
Expand Down Expand Up @@ -3386,6 +3410,9 @@ extern "C" {
extern "C" {
pub fn crypto_core_ed25519_uniformbytes() -> usize;
}
extern "C" {
pub fn crypto_core_ed25519_hashbytes() -> usize;
}
extern "C" {
pub fn crypto_core_ed25519_scalarbytes() -> usize;
}
Expand Down Expand Up @@ -3415,6 +3442,15 @@ extern "C" {
r: *const libc::c_uchar,
) -> libc::c_int;
}
extern "C" {
pub fn crypto_core_ed25519_from_hash(
p: *mut libc::c_uchar,
h: *const libc::c_uchar,
) -> libc::c_int;
}
extern "C" {
pub fn crypto_core_ed25519_random(p: *mut libc::c_uchar);
}
extern "C" {
pub fn crypto_core_ed25519_scalar_random(r: *mut libc::c_uchar);
}
Expand Down Expand Up @@ -3444,9 +3480,96 @@ extern "C" {
y: *const libc::c_uchar,
);
}
extern "C" {
pub fn crypto_core_ed25519_scalar_mul(
z: *mut libc::c_uchar,
x: *const libc::c_uchar,
y: *const libc::c_uchar,
);
}
extern "C" {
pub fn crypto_core_ed25519_scalar_reduce(r: *mut libc::c_uchar, s: *const libc::c_uchar);
}
extern "C" {
pub fn crypto_core_ristretto255_bytes() -> usize;
}
extern "C" {
pub fn crypto_core_ristretto255_hashbytes() -> usize;
}
extern "C" {
pub fn crypto_core_ristretto255_scalarbytes() -> usize;
}
extern "C" {
pub fn crypto_core_ristretto255_nonreducedscalarbytes() -> usize;
}
extern "C" {
pub fn crypto_core_ristretto255_is_valid_point(p: *const libc::c_uchar) -> libc::c_int;
}
extern "C" {
pub fn crypto_core_ristretto255_add(
r: *mut libc::c_uchar,
p: *const libc::c_uchar,
q: *const libc::c_uchar,
) -> libc::c_int;
}
extern "C" {
pub fn crypto_core_ristretto255_sub(
r: *mut libc::c_uchar,
p: *const libc::c_uchar,
q: *const libc::c_uchar,
) -> libc::c_int;
}
extern "C" {
pub fn crypto_core_ristretto255_from_hash(
p: *mut libc::c_uchar,
r: *const libc::c_uchar,
) -> libc::c_int;
}
extern "C" {
pub fn crypto_core_ristretto255_random(p: *mut libc::c_uchar);
}
extern "C" {
pub fn crypto_core_ristretto255_scalar_random(r: *mut libc::c_uchar);
}
extern "C" {
pub fn crypto_core_ristretto255_scalar_invert(
recip: *mut libc::c_uchar,
s: *const libc::c_uchar,
) -> libc::c_int;
}
extern "C" {
pub fn crypto_core_ristretto255_scalar_negate(neg: *mut libc::c_uchar, s: *const libc::c_uchar);
}
extern "C" {
pub fn crypto_core_ristretto255_scalar_complement(
comp: *mut libc::c_uchar,
s: *const libc::c_uchar,
);
}
extern "C" {
pub fn crypto_core_ristretto255_scalar_add(
z: *mut libc::c_uchar,
x: *const libc::c_uchar,
y: *const libc::c_uchar,
);
}
extern "C" {
pub fn crypto_core_ristretto255_scalar_sub(
z: *mut libc::c_uchar,
x: *const libc::c_uchar,
y: *const libc::c_uchar,
);
}
extern "C" {
pub fn crypto_core_ristretto255_scalar_mul(
z: *mut libc::c_uchar,
x: *const libc::c_uchar,
y: *const libc::c_uchar,
);
}
extern "C" {
pub fn crypto_core_ristretto255_scalar_reduce(r: *mut libc::c_uchar, s: *const libc::c_uchar);
}
extern "C" {
pub fn crypto_scalarmult_ed25519_bytes() -> usize;
}
Expand Down Expand Up @@ -3479,6 +3602,25 @@ extern "C" {
n: *const libc::c_uchar,
) -> libc::c_int;
}
extern "C" {
pub fn crypto_scalarmult_ristretto255_bytes() -> usize;
}
extern "C" {
pub fn crypto_scalarmult_ristretto255_scalarbytes() -> usize;
}
extern "C" {
pub fn crypto_scalarmult_ristretto255(
q: *mut libc::c_uchar,
n: *const libc::c_uchar,
p: *const libc::c_uchar,
) -> libc::c_int;
}
extern "C" {
pub fn crypto_scalarmult_ristretto255_base(
q: *mut libc::c_uchar,
n: *const libc::c_uchar,
) -> libc::c_int;
}
extern "C" {
pub fn crypto_secretbox_xchacha20poly1305_keybytes() -> usize;
}
Expand Down
3 changes: 2 additions & 1 deletion libsodium-sys/tests/crypto/crypto_generichash_blake2b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use libsodium_sys::*;

#[test]
fn test_crypto_generichash_blake2b_state_alignment() {
// this asserts the alignment applied in alignment_fix.patch (see gen.sh)
// this asserts the alignment applied that was broken with old
// versions of bindgen
assert_eq!(64, std::mem::align_of::<crypto_generichash_blake2b_state>());
}

Expand Down
3 changes: 2 additions & 1 deletion libsodium-sys/tests/crypto/crypto_onetimeauth_poly1305.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use libsodium_sys::*;

#[test]
fn test_crypto_onetimeauth_poly1305_state_alignment() {
// this asserts the alignment applied in alignment_fix.patch (see gen.sh)
// this asserts the alignment applied that was broken with old
// versions of bindgen
assert_eq!(
16,
std::mem::align_of::<crypto_onetimeauth_poly1305_state>()
Expand Down

0 comments on commit 46cdc31

Please sign in to comment.