]> granicus.if.org Git - openssl/commitdiff
xts128.c: minor optimization and clarified prototype.
authorAndy Polyakov <appro@openssl.org>
Wed, 20 Apr 2011 08:13:58 +0000 (08:13 +0000)
committerAndy Polyakov <appro@openssl.org>
Wed, 20 Apr 2011 08:13:58 +0000 (08:13 +0000)
crypto/modes/modes.h
crypto/modes/xts128.c

index feacfb77ed724128d0515ebea9b4fd30ca6f2016..5cf1935db022e7ef149f27d6eec7a65f31f569c4 100644 (file)
@@ -121,5 +121,5 @@ size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
 
 typedef struct xts128_context XTS128_CONTEXT;
 
-int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char *iv,
+int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
        const unsigned char *inp, unsigned char *out, size_t len, int enc);
index aaa44e05f04a40123d52a49c32063a553f72ecef..6859ab65d522e9d93861d1e4c82d34660bca3161 100644 (file)
@@ -58,7 +58,7 @@
 #endif
 #include <assert.h>
 
-int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char *iv,
+int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
        const unsigned char *inp, unsigned char *out,
        size_t len, int enc)
 {
@@ -84,9 +84,14 @@ int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char *iv,
                scratch.u[1] = ((u64*)inp)[1]^tweak.u[1];
 #endif
                (*ctx->block1)(scratch.c,scratch.c,ctx->key1);
+#if defined(STRICT_ALIGNMENT)
                scratch.u[0] ^= tweak.u[0];
                scratch.u[1] ^= tweak.u[1];
                memcpy(out,scratch.c,16);
+#else
+               ((u64*)out)[0] = scratch.u[0]^tweak.u[0];
+               ((u64*)out)[1] = scratch.u[1]^tweak.u[1];
+#endif
                inp += 16;
                out += 16;
                len -= 16;
@@ -166,9 +171,14 @@ int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char *iv,
                scratch.u[0] ^= tweak.u[0];
                scratch.u[1] ^= tweak.u[1];
                (*ctx->block1)(scratch.c,scratch.c,ctx->key1);
+#if defined(STRICT_ALIGNMENT)
                scratch.u[0] ^= tweak.u[0];
                scratch.u[1] ^= tweak.u[1];
                memcpy (out,scratch.c,16);
+#else
+               ((u64*)out)[0] = scratch.u[0]^tweak.u[0];
+               ((u64*)out)[1] = scratch.u[1]^tweak.u[1];
+#endif
        }
 
        return 0;