OpenSolaris

Printable Version Enter a New Search
Bug ID 6717509
Synopsis Need to use bswap/bswapq for byte swap of 64-bit integer on x32/x64
State 10-Fix Delivered (Fix available in build)
Category:Subcategory solaris-crypto:algorithms
Keywords SFO | ef-reviewed
Responsible Engineer Daniel Anderson
Reported Against
Duplicate Of
Introduced In solaris_10
Commit to Fix snv_98
Fixed In snv_98
Release Fixed solaris_nevada(snv_98)
Related Bugs 5007142
Submit Date 20-June-2008
Last Update Date 10-September-2008
Description
Konstantin Ananyev found that replacing the following code in des3_crunch_block() (and des3_crunch_block()) -
                tmp = (((uint64_t)block[0] << 56) | ((uint64_t)block[1] << 48) |
                    ((uint64_t)block[2] << 40) | ((uint64_t)block[3] << 32) |
                    ((uint64_t)block[4] << 24) | ((uint64_t)block[5] << 16) |
                    ((uint64_t)block[6] << 8) | (uint64_t)block[7]);

                if (decrypt == B_TRUE)
                        tmp = des_crypt_impl(ksch->ksch_decrypt, tmp, 3);
                else
                        tmp = des_crypt_impl(ksch->ksch_encrypt, tmp, 3);

                out_block[0] = tmp >> 56;
                out_block[1] = tmp >> 48;
                out_block[2] = tmp >> 40;
                out_block[3] = tmp >> 32;
                out_block[4] = tmp >> 24;
                out_block[5] = tmp >> 16;
                out_block[6] = tmp >> 8;
                out_block[7] = (uint8_t)tmp;

with a bswapq (for X64) improved the performance upto 10% for udp over IPsec. This code is run for x32/x64 and for unaligned case on SPARC.

We can use the bswap instruction to do similar optimization on x32.

A code inspection found that similar code is found in
usr/src/common/crypto/aes/aes_cbc_crypt.c	(for ccm mode)
usr/src/common/crypto/des/des_cbc_crypt.c
usr/src/common/crypto/des/des_impl.c (the above example)
usr/src/common/crypto/sha2/sha2.c
usr/src/uts/common/crypto/io/aes.c
Work Around
N/A
Comments
N/A