aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-05-26 11:53:31 +0000
committerlloyd <[email protected]>2014-05-26 11:53:31 +0000
commit91c8a2cbae4486f4988eda6ae5b7cb2497285346 (patch)
tree82276370964f2fc55253f0572e7f383612ffe74c /src
parentb9cd85a383b5a522a25d4d798e66d2921e2e1398 (diff)
Erroring on strict-overflow is a little too strict, GCC 4.9 is smart
Diffstat (limited to 'src')
-rw-r--r--src/build-data/cc/gcc.txt35
-rw-r--r--src/lib/modes/cbc/cbc.cpp19
2 files changed, 25 insertions, 29 deletions
diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt
index 365ec87f9..2aff1bf6b 100644
--- a/src/build-data/cc/gcc.txt
+++ b/src/build-data/cc/gcc.txt
@@ -8,8 +8,8 @@ add_include_dir_option -I
add_lib_dir_option -L
add_lib_option -l
-lang_flags "-std=c++11 -D_REENTRANT -fstack-protector"
-maintainer_warning_flags "-Werror -Wno-error=old-style-cast -Wno-error=zero-as-null-pointer-constant -Wno-error=unused-parameter -Wno-error=unused-variable"
+lang_flags "-std=c++11 -D_REENTRANT -D_FORTIFY_SOURCE=2 -fstack-protector"
+maintainer_warning_flags "-Werror -Wno-error=old-style-cast -Wno-error=zero-as-null-pointer-constant -Wno-error=unused-parameter -Wno-error=unused-variable -Wno-error=strict-overflow"
warning_flags "-Wall -Wextra -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations -Wpointer-arith -Wcast-qual -Wold-style-cast -Wzero-as-null-pointer-constant"
lib_opt_flags "-O3"
@@ -26,28 +26,27 @@ makefile_style gmake
# The default works for GNU ld and several other Unix linkers
default -> "$(CXX) -shared -fPIC -Wl,-soname,$(SONAME)"
-# AIX doesn't seem to have soname support (weird...)
-aix -> "$(CXX) -shared -fPIC"
-
-# OpenBSD doesn't use soname
-openbsd -> "$(CXX) -shared -fPIC"
-
+# Darwin, HP-UX and Solaris linkers use different syntax
darwin -> "$(CXX) -dynamiclib -fPIC -install_name $(LIBDIR)/$(SONAME)"
hpux -> "$(CXX) -shared -fPIC -Wl,+h,$(SONAME)"
solaris -> "$(CXX) -shared -fPIC -Wl,-h,$(SONAME)"
+
+# AIX and OpenBSD don't use sonames at all
+aix -> "$(CXX) -shared -fPIC"
+openbsd -> "$(CXX) -shared -fPIC"
</so_link_flags>
<isa_flags>
-sse2 -> "-msse2"
-ssse3 -> "-mssse3"
-sse4.1 -> "-msse4.1"
-sse4.2 -> "-msse4.2"
-avx2 -> "-mavx2"
-bmi2 -> "-mbmi2"
-aesni -> "-maes"
-clmul -> "-mpclmul"
-rdrand -> "-mrdrnd"
-sha -> "-msha"
+sse2 -> "-msse2"
+ssse3 -> "-mssse3"
+sse4.1 -> "-msse4.1"
+sse4.2 -> "-msse4.2"
+avx2 -> "-mavx2"
+bmi2 -> "-mbmi2"
+aesni -> "-maes"
+clmul -> "-mpclmul"
+rdrand -> "-mrdrnd"
+sha -> "-msha"
altivec -> "-maltivec"
</isa_flags>
diff --git a/src/lib/modes/cbc/cbc.cpp b/src/lib/modes/cbc/cbc.cpp
index 3095875f5..5fe5c8b17 100644
--- a/src/lib/modes/cbc/cbc.cpp
+++ b/src/lib/modes/cbc/cbc.cpp
@@ -99,15 +99,15 @@ void CBC_Encryption::update(secure_vector<byte>& buffer, size_t offset)
BOTAN_ASSERT(sz % BS == 0, "CBC input is full blocks");
const size_t blocks = sz / BS;
+ const byte* prev_block = state_ptr();
+
if(blocks)
{
- xor_buf(&buf[0], state_ptr(), BS);
- cipher().encrypt(&buf[0]);
-
- for(size_t i = 1; i != blocks; ++i)
+ for(size_t i = 0; i != blocks; ++i)
{
- xor_buf(&buf[BS*i], &buf[BS*(i-1)], BS);
+ xor_buf(&buf[BS*i], prev_block, BS);
cipher().encrypt(&buf[BS*i]);
+ prev_block = &buf[BS*i];
}
state().assign(&buf[BS*(blocks-1)], &buf[BS*blocks]);
@@ -267,6 +267,7 @@ void CTS_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
if(sz % BS == 0)
{
// swap last two blocks
+
for(size_t i = 0; i != BS; ++i)
std::swap(buffer[buffer.size()-BS+i], buffer[buffer.size()-2*BS+i]);
@@ -283,21 +284,17 @@ void CTS_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
update(buffer, offset);
cipher().decrypt(&last[0]);
+
xor_buf(&last[0], &last[BS], final_bytes - BS);
for(size_t i = 0; i != final_bytes - BS; ++i)
- {
- last[i] ^= last[i + BS];
- last[i + BS] ^= last[i];
- last[i] ^= last[i + BS];
- }
+ std::swap(last[i], last[i + BS]);
cipher().decrypt(&last[0]);
xor_buf(&last[0], state_ptr(), BS);
buffer += last;
}
-
}
}