Skip to content

Instantly share code, notes, and snippets.

@josephlr
Last active June 20, 2019 09:48
Show Gist options
  • Save josephlr/520bd9dae579408e3466b8abd36173dd to your computer and use it in GitHub Desktop.
Save josephlr/520bd9dae579408e3466b8abd36173dd to your computer and use it in GitHub Desktop.
BUILD file for Ring (x86_64 only, needs perlasm.bzl)
package(
default_visibility = ["//visibility:private"],
licenses = ["notice"], # ISC-style
)
## C Code
cc_library(
name = "base",
hdrs = ["include/GFp/base.h"],
includes = ["include"],
)
cc_library(
name = "memcmp",
srcs = ["crypto/mem.c"],
hdrs = ["include/GFp/mem.h"],
deps = [":base"],
)
cc_library(
name = "headers",
hdrs = [
"crypto/internal.h",
"include/GFp/type_check.h",
"include/GFp/aes.h",
],
deps = [":base"],
)
cc_library(
name = "fiat",
srcs = glob(["third_party/fiat/*.c"]),
hdrs = glob(["third_party/fiat/*.h"]),
deps = [":memcmp", ":headers"],
)
cc_library(
name = "constant_time_test",
srcs = ["crypto/constant_time_test.c"],
deps = [":headers"],
testonly = True
)
cc_library(
name = "limbs",
srcs = ["crypto/limbs/limbs." + ext for ext in ["h", "c", "inl"]],
deps = [":headers"],
)
cc_library(
name = "fipsmodule",
srcs = [
"crypto/fipsmodule/bn/internal.h",
"crypto/fipsmodule/bn/generic.c",
"crypto/fipsmodule/bn/montgomery.c",
"crypto/fipsmodule/bn/montgomery_inv.c",
"crypto/fipsmodule/ec/ecp_nistz.h",
"crypto/fipsmodule/ec/ecp_nistz256.h",
"crypto/fipsmodule/ec/ecp_nistz384.h",
"crypto/fipsmodule/ec/ecp_nistz256_table.inl",
"crypto/fipsmodule/ec/ecp_nistz384.inl",
"crypto/fipsmodule/ec/ecp_nistz.c",
"crypto/fipsmodule/ec/ecp_nistz256.c",
"crypto/fipsmodule/ec/gfp_p256.c",
"crypto/fipsmodule/ec/gfp_p384.c",
"crypto/fipsmodule/modes/internal.h",
"crypto/fipsmodule/modes/gcm.c",
],
deps = [":headers", ":limbs"],
)
## Architecture Specific C and assembly code
load(":perlasm.bzl", "perlasm", "perlasm_cc_library")
perlasm_utils = glob(["crypto/perlasm/*.pl"])
# These two sha512 asm files will generate sha256 code, if given the right name.
perlasm(
name = "sha256-x86_64",
src = "crypto/fipsmodule/sha/asm/sha512-x86_64.pl",
perlasm_utils = perlasm_utils,
)
perlasm(
name = "sha256-armv8",
src = "crypto/fipsmodule/sha/asm/sha512-armv8.pl",
perlasm_utils = perlasm_utils,
)
# TODO: implement arch for non x86_64 architectures
perlasm_cc_library(
name = "arch",
perlasm_srcs = [
"crypto/chacha/asm/chacha-x86_64.pl",
"crypto/fipsmodule/aes/asm/aes-x86_64.pl",
"crypto/fipsmodule/aes/asm/aesni-x86_64.pl",
"crypto/fipsmodule/aes/asm/vpaes-x86_64.pl",
"crypto/fipsmodule/bn/asm/x86_64-mont.pl",
"crypto/fipsmodule/bn/asm/x86_64-mont5.pl",
"crypto/fipsmodule/ec/asm/p256-x86_64-asm.pl",
"crypto/fipsmodule/modes/asm/aesni-gcm-x86_64.pl",
"crypto/fipsmodule/modes/asm/ghash-x86_64.pl",
"crypto/fipsmodule/sha/asm/sha512-x86_64.pl",
"crypto/poly1305/asm/poly1305-x86_64.pl",
],
perlasm_utils = perlasm_utils,
srcs = [
":sha256-x86_64",
"crypto/crypto.c",
"crypto/cpu-intel.c",
"include/GFp/cpu.h",
],
deps = [":headers"],
)
## Rust Code
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library", "rust_test")
crate_features = ["dev_urandom_fallback", "use_heap"]
rust_library(
name = "ring",
srcs = glob(["src/**/*.rs"]),
data = glob(["src/**/*.der"]),
deps = [
":arch",
":fiat",
":fipsmodule",
":limbs",
":memcmp",
"//cargo:lazy_static",
"//cargo:libc",
"//cargo:spin",
"//cargo:untrusted",
],
visibility = ["//visibility:public"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "unit_tests",
crate = ":ring",
data = [
"crypto/fipsmodule/ecdsa/ecdsa_verify_tests.txt",
] + glob(["src/**/*.der", "src/**/*.txt"]),
deps = [":constant_time_test"],
edition = "2018",
crate_features = crate_features,
)
## Rust Integration Tests
rust_test(
name = "aead_tests",
srcs = ["tests/aead_tests.rs"],
data = glob(["tests/aead_*.txt"]),
deps = [":ring"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "agreement_tests",
srcs = ["tests/agreement_tests.rs"],
data = glob(["tests/agreement_*.txt"]),
deps = [":ring"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "digest_tests",
srcs = ["tests/digest_tests.rs"],
data = glob(["third_party/NIST/SHAVS/*.rsp", "tests/digest_*.txt"]),
deps = [":ring"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "ecdsa_tests",
srcs = ["tests/ecdsa_tests.rs"],
data = glob(["tests/ecdsa_*." + ext for ext in ["der", "p8", "txt"]]),
deps = [":ring", "//cargo:untrusted"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "ed25519_tests",
srcs = ["tests/ed25519_tests.rs"],
data = glob(["tests/ed25519_*." + ext for ext in ["bin", "der", "p8", "txt"]]),
deps = [":ring", "//cargo:untrusted"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "hkdf_tests",
srcs = ["tests/hkdf_tests.rs"],
data = glob(["tests/hkdf_*.txt"]),
deps = [":ring"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "hmac_tests",
srcs = ["tests/hmac_tests.rs"],
data = glob(["tests/hmac_*.txt"]),
deps = [":ring"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "pbkdf2_tests",
srcs = ["tests/pbkdf2_tests.rs"],
data = glob(["tests/pbkdf2_*.txt"]),
deps = [":ring"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "quic_tests",
srcs = ["tests/quic_tests.rs"],
data = glob(["tests/quic_*.txt"]),
deps = [":ring"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "rand_tests",
srcs = ["tests/rand_tests.rs"],
deps = [":ring"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "rsa_tests",
srcs = ["tests/rsa_tests.rs"],
data = glob(["tests/rsa_*." + ext for ext in ["der", "p8", "txt"]]),
deps = [":ring", "//cargo:untrusted"],
edition = "2018",
crate_features = crate_features,
)
rust_test(
name = "signature_tests",
srcs = ["tests/signature_tests.rs"],
deps = [":ring"],
edition = "2018",
crate_features = crate_features,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment