Moving xor_* functions into common header file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

'grep "static void xor_" crypto/*' shows that cbc.c, ctr.c, pcbc.c and
xcbc.c share similar xor_* functions. It seems a good idea to
encourage code reuse by putting them into a common header (iirc
Evgeniy  suggested it when reviewing one of my earlier mail). It will
also be useful to me when porting other eSTREAM ciphers. So I would
like to move them into include/crypto/xor_n.h and make them all
"static inline". Any objections?

For xor_byte and xor_quad, the implementation in ctr.c differs from
that in cbc.c and pcbc.c. In cbc.c and pcbc.c we have:

    static void xor_byte(u8 *a, const u8 *b, unsigned int bs)
    {
            do {
                    *a++ ^= *b++;
            } while (--bs);
    }

  static void xor_quad(u8 *dst, const u8 *src, unsigned int bs)
    {
            u32 *a = (u32 *)dst;
            u32 *b = (u32 *)src;

            do {
                    *a++ ^= *b++;
            } while ((bs -= 4));
    }

while in ctr.c it is:

    static void xor_byte(u8 *a, const u8 *b, unsigned int bs)
    {
            for (; bs; bs--)
                    *a++ ^= *b++;
    }

    static void xor_quad(u8 *dst, const u8 *src, unsigned int bs)
    {
            u32 *a = (u32 *)dst;
            u32 *b = (u32 *)src;

            for (; bs >= 4; bs -= 4)
                    *a++ ^= *b++;

            xor_byte((u8 *)a, (u8 *)b, bs);
    }

The former saves one check by assuming bs > 0. For cbc.c and pcbc.c,
we can assume bs > 0 since xor() uses the non-negative blocksize. For
ctr.c, we check bs == 0 as the call to xor_quad uses min(nbytes,
bsize). Given that we need both semantics, I would like to propose
renaming the former as xor_byte_quick() and xor_quad_block() in the
common header. Would that be fine?

Swee Heng
-
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux