Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Langley <agl@google.com>2015-01-29 02:52:57 +0300
committerAdam Langley <agl@google.com>2015-01-29 23:06:34 +0300
commit267253470a11846001374add822cff791ce38085 (patch)
treebf20daa6529d43a289fede99f73ac17a79c278f8 /tool/speed.cc
parenta87de9b39b5a9b1d6e9ed6d18167946397581df1 (diff)
Align pointers by hand.
This avoids having Windows be different and is also easier for testing because it's a simple matter to unalign the pointer if needed. Change-Id: I32cfa5834e3fe4f16304a25092b9c71946d4744d Reviewed-on: https://boringssl-review.googlesource.com/3131 Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'tool/speed.cc')
-rw-r--r--tool/speed.cc43
1 files changed, 18 insertions, 25 deletions
diff --git a/tool/speed.cc b/tool/speed.cc
index cfffcb05..11747b1a 100644
--- a/tool/speed.cc
+++ b/tool/speed.cc
@@ -169,26 +169,15 @@ struct free_functor {
}
};
-#if defined(OPENSSL_WINDOWS)
-uint8_t *AllocAligned(size_t size) {
- void *ptr = malloc(size);
- if (ptr == NULL) {
- abort();
- }
- return static_cast<uint8_t*>(ptr);
-}
-#else
-uint8_t *AllocAligned(size_t size) {
- void *ptr;
- if (posix_memalign(&ptr, 64, size)) {
- abort();
- }
- return static_cast<uint8_t*>(ptr);
+static uint8_t *align(uint8_t *in, unsigned alignment) {
+ return reinterpret_cast<uint8_t *>(
+ (reinterpret_cast<uintptr_t>(in) + alignment) & ~(alignment - 1));
}
-#endif
static bool SpeedAEADChunk(const EVP_AEAD *aead, const std::string &name,
size_t chunk_len, size_t ad_len) {
+ static const unsigned kAlignment = 16;
+
EVP_AEAD_CTX ctx;
const size_t key_len = EVP_AEAD_key_length(aead);
const size_t nonce_len = EVP_AEAD_nonce_length(aead);
@@ -198,14 +187,18 @@ static bool SpeedAEADChunk(const EVP_AEAD *aead, const std::string &name,
memset(key.get(), 0, key_len);
std::unique_ptr<uint8_t[]> nonce(new uint8_t[nonce_len]);
memset(nonce.get(), 0, nonce_len);
- std::unique_ptr<uint8_t, free_functor<uint8_t>> in(AllocAligned(chunk_len));
- memset(in.get(), 0, chunk_len);
- std::unique_ptr<uint8_t, free_functor<uint8_t>> out(
- AllocAligned(chunk_len + overhead_len));
- memset(out.get(), 0, chunk_len + overhead_len);
+ std::unique_ptr<uint8_t, free_functor<uint8_t>> in_storage(
+ new uint8_t[chunk_len + kAlignment]);
+ std::unique_ptr<uint8_t, free_functor<uint8_t>> out_storage(
+ new uint8_t[chunk_len + overhead_len + kAlignment]);
std::unique_ptr<uint8_t[]> ad(new uint8_t[ad_len]);
memset(ad.get(), 0, ad_len);
+ uint8_t *const in = align(in_storage.get(), kAlignment);
+ memset(in, 0, chunk_len);
+ uint8_t *const out = align(out_storage.get(), kAlignment);
+ memset(out, 0, chunk_len + overhead_len);
+
if (!EVP_AEAD_CTX_init(&ctx, aead, key.get(), key_len,
EVP_AEAD_DEFAULT_TAG_LENGTH, NULL)) {
fprintf(stderr, "Failed to create EVP_AEAD_CTX.\n");
@@ -214,13 +207,13 @@ static bool SpeedAEADChunk(const EVP_AEAD *aead, const std::string &name,
}
TimeResults results;
- if (!TimeFunction(&results, [chunk_len, overhead_len, nonce_len, ad_len, &in,
- &out, &ctx, &nonce, &ad]() -> bool {
+ if (!TimeFunction(&results, [chunk_len, overhead_len, nonce_len, ad_len, in,
+ out, &ctx, &nonce, &ad]() -> bool {
size_t out_len;
return EVP_AEAD_CTX_seal(
- &ctx, out.get(), &out_len, chunk_len + overhead_len, nonce.get(),
- nonce_len, in.get(), chunk_len, ad.get(), ad_len);
+ &ctx, out, &out_len, chunk_len + overhead_len, nonce.get(),
+ nonce_len, in, chunk_len, ad.get(), ad_len);
})) {
fprintf(stderr, "EVP_AEAD_CTX_seal failed.\n");
BIO_print_errors_fp(stderr);