From: Richard Levitte Date: Thu, 14 May 2015 12:54:49 +0000 (+0200) Subject: Identify and move OpenSSL internal header files X-Git-Tag: OpenSSL_1_1_0-pre1~1143 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=685707979100dcb344f3d5f29940afcb1e7a92c2;p=oweals%2Fopenssl.git Identify and move OpenSSL internal header files There are header files in crypto/ that are used by the rest of OpenSSL. Move those to include/internal and adapt the affected source code, Makefiles and scripts. The header files that got moved are: crypto/constant_time_locl.h crypto/o_dir.h crypto/o_str.h Reviewed-by: Matt Caswell --- diff --git a/crypto/Makefile b/crypto/Makefile index 5270d75e19..de74a0fe25 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -43,8 +43,7 @@ LIBOBJ= cryptlib.o mem.o mem_dbg.o cversion.o ex_data.o cpt_err.o \ SRC= $(LIBSRC) -HEADER= cryptlib.h buildinf.h md32_common.h o_str.h o_dir.h \ - constant_time_locl.h +HEADER= cryptlib.h buildinf.h md32_common.h ALL= $(GENERAL) $(SRC) $(HEADER) diff --git a/crypto/constant_time_locl.h b/crypto/constant_time_locl.h deleted file mode 100644 index c786aea949..0000000000 --- a/crypto/constant_time_locl.h +++ /dev/null @@ -1,211 +0,0 @@ -/* crypto/constant_time_locl.h */ -/*- - * Utilities for constant-time cryptography. - * - * Author: Emilia Kasper (emilia@openssl.org) - * Based on previous work by Bodo Moeller, Emilia Kasper, Adam Langley - * (Google). - * ==================================================================== - * Copyright (c) 2014 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#ifndef HEADER_CONSTANT_TIME_LOCL_H -# define HEADER_CONSTANT_TIME_LOCL_H - -# include "e_os.h" /* For 'inline' */ - -#ifdef __cplusplus -extern "C" { -#endif - -/*- - * The boolean methods return a bitmask of all ones (0xff...f) for true - * and 0 for false. This is useful for choosing a value based on the result - * of a conditional in constant time. For example, - * - * if (a < b) { - * c = a; - * } else { - * c = b; - * } - * - * can be written as - * - * unsigned int lt = constant_time_lt(a, b); - * c = constant_time_select(lt, a, b); - */ - -/* - * Returns the given value with the MSB copied to all the other - * bits. Uses the fact that arithmetic shift shifts-in the sign bit. - * However, this is not ensured by the C standard so you may need to - * replace this with something else on odd CPUs. - */ -static inline unsigned int constant_time_msb(unsigned int a); - -/* - * Returns 0xff..f if a < b and 0 otherwise. - */ -static inline unsigned int constant_time_lt(unsigned int a, unsigned int b); -/* Convenience method for getting an 8-bit mask. */ -static inline unsigned char constant_time_lt_8(unsigned int a, - unsigned int b); - -/* - * Returns 0xff..f if a >= b and 0 otherwise. - */ -static inline unsigned int constant_time_ge(unsigned int a, unsigned int b); -/* Convenience method for getting an 8-bit mask. */ -static inline unsigned char constant_time_ge_8(unsigned int a, - unsigned int b); - -/* - * Returns 0xff..f if a == 0 and 0 otherwise. - */ -static inline unsigned int constant_time_is_zero(unsigned int a); -/* Convenience method for getting an 8-bit mask. */ -static inline unsigned char constant_time_is_zero_8(unsigned int a); - -/* - * Returns 0xff..f if a == b and 0 otherwise. - */ -static inline unsigned int constant_time_eq(unsigned int a, unsigned int b); -/* Convenience method for getting an 8-bit mask. */ -static inline unsigned char constant_time_eq_8(unsigned int a, - unsigned int b); -/* Signed integers. */ -static inline unsigned int constant_time_eq_int(int a, int b); -/* Convenience method for getting an 8-bit mask. */ -static inline unsigned char constant_time_eq_int_8(int a, int b); - -/*- - * Returns (mask & a) | (~mask & b). - * - * When |mask| is all 1s or all 0s (as returned by the methods above), - * the select methods return either |a| (if |mask| is nonzero) or |b| - * (if |mask| is zero). - */ -static inline unsigned int constant_time_select(unsigned int mask, - unsigned int a, - unsigned int b); -/* Convenience method for unsigned chars. */ -static inline unsigned char constant_time_select_8(unsigned char mask, - unsigned char a, - unsigned char b); -/* Convenience method for signed integers. */ -static inline int constant_time_select_int(unsigned int mask, int a, int b); - -static inline unsigned int constant_time_msb(unsigned int a) -{ - return 0 - (a >> (sizeof(a) * 8 - 1)); -} - -static inline unsigned int constant_time_lt(unsigned int a, unsigned int b) -{ - return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b))); -} - -static inline unsigned char constant_time_lt_8(unsigned int a, unsigned int b) -{ - return (unsigned char)(constant_time_lt(a, b)); -} - -static inline unsigned int constant_time_ge(unsigned int a, unsigned int b) -{ - return ~constant_time_lt(a, b); -} - -static inline unsigned char constant_time_ge_8(unsigned int a, unsigned int b) -{ - return (unsigned char)(constant_time_ge(a, b)); -} - -static inline unsigned int constant_time_is_zero(unsigned int a) -{ - return constant_time_msb(~a & (a - 1)); -} - -static inline unsigned char constant_time_is_zero_8(unsigned int a) -{ - return (unsigned char)(constant_time_is_zero(a)); -} - -static inline unsigned int constant_time_eq(unsigned int a, unsigned int b) -{ - return constant_time_is_zero(a ^ b); -} - -static inline unsigned char constant_time_eq_8(unsigned int a, unsigned int b) -{ - return (unsigned char)(constant_time_eq(a, b)); -} - -static inline unsigned int constant_time_eq_int(int a, int b) -{ - return constant_time_eq((unsigned)(a), (unsigned)(b)); -} - -static inline unsigned char constant_time_eq_int_8(int a, int b) -{ - return constant_time_eq_8((unsigned)(a), (unsigned)(b)); -} - -static inline unsigned int constant_time_select(unsigned int mask, - unsigned int a, - unsigned int b) -{ - return (mask & a) | (~mask & b); -} - -static inline unsigned char constant_time_select_8(unsigned char mask, - unsigned char a, - unsigned char b) -{ - return (unsigned char)(constant_time_select(mask, a, b)); -} - -static inline int constant_time_select_int(unsigned int mask, int a, int b) -{ - return (int)(constant_time_select(mask, (unsigned)(a), (unsigned)(b))); -} - -#ifdef __cplusplus -} -#endif - -#endif /* HEADER_CONSTANT_TIME_LOCL_H */ diff --git a/crypto/o_dir.c b/crypto/o_dir.c index 26242444c8..7bff74e0ec 100644 --- a/crypto/o_dir.c +++ b/crypto/o_dir.c @@ -70,7 +70,7 @@ #define LP_find_file OPENSSL_DIR_read #define LP_find_file_end OPENSSL_DIR_end -#include "o_dir.h" +#include "internal/o_dir.h" #define LPDIR_H #if defined OPENSSL_SYS_UNIX || defined DJGPP diff --git a/crypto/o_dir.h b/crypto/o_dir.h deleted file mode 100644 index d55431194e..0000000000 --- a/crypto/o_dir.h +++ /dev/null @@ -1,55 +0,0 @@ -/* crypto/o_dir.h -*- mode:C; c-file-style: "eay" -*- */ -/* - * Copied from Richard Levitte's (richard@levitte.org) LP library. All - * symbol names have been changed, with permission from the author. - */ - -/* $LP: LPlib/source/LPdir.h,v 1.1 2004/06/14 08:56:04 _cvs_levitte Exp $ */ -/* - * Copyright (c) 2004, Richard Levitte - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef O_DIR_H -# define O_DIR_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct OPENSSL_dir_context_st OPENSSL_DIR_CTX; - - /* - * returns NULL on error or end-of-directory. If it is end-of-directory, - * errno will be zero - */ -const char *OPENSSL_DIR_read(OPENSSL_DIR_CTX **ctx, const char *directory); - /* returns 1 on success, 0 on error */ -int OPENSSL_DIR_end(OPENSSL_DIR_CTX **ctx); - -#ifdef __cplusplus -} -#endif - -#endif /* LPDIR_H */ diff --git a/crypto/o_dir_test.c b/crypto/o_dir_test.c index 7cdbbbc403..733ffecf3a 100644 --- a/crypto/o_dir_test.c +++ b/crypto/o_dir_test.c @@ -36,7 +36,7 @@ #include #include #include "e_os2.h" -#include "o_dir.h" +#include "internal/o_dir.h" #if defined OPENSSL_SYS_UNIX || defined OPENSSL_SYS_WIN32 || defined OPENSSL_SYS_WINCE # define CURRDIR "." diff --git a/crypto/o_str.c b/crypto/o_str.c index 16fd4e4231..f2f9404db0 100644 --- a/crypto/o_str.c +++ b/crypto/o_str.c @@ -59,7 +59,7 @@ #include #include -#include "o_str.h" +#include "internal/o_str.h" #if !defined(OPENSSL_IMPLEMENTS_strncasecmp) && \ !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_WINCE) && \ diff --git a/crypto/o_str.h b/crypto/o_str.h deleted file mode 100644 index 5313528ed9..0000000000 --- a/crypto/o_str.h +++ /dev/null @@ -1,69 +0,0 @@ -/* crypto/o_str.h -*- mode:C; c-file-style: "eay" -*- */ -/* - * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project - * 2003. - */ -/* ==================================================================== - * Copyright (c) 2003 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * licensing@OpenSSL.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This product includes cryptographic software written by Eric Young - * (eay@cryptsoft.com). This product includes software written by Tim - * Hudson (tjh@cryptsoft.com). - * - */ - -#ifndef HEADER_O_STR_H -# define HEADER_O_STR_H - -# include /* to get size_t */ - -int OPENSSL_strcasecmp(const char *str1, const char *str2); -int OPENSSL_strncasecmp(const char *str1, const char *str2, size_t n); -int OPENSSL_memcmp(const void *p1, const void *p2, size_t n); - -#endif diff --git a/crypto/rsa/rsa_oaep.c b/crypto/rsa/rsa_oaep.c index d988d6c217..6edfb4145d 100644 --- a/crypto/rsa/rsa_oaep.c +++ b/crypto/rsa/rsa_oaep.c @@ -17,7 +17,7 @@ * one-wayness. For the RSA function, this is an equivalent notion. */ -#include "constant_time_locl.h" +#include "internal/constant_time_locl.h" #include #include "cryptlib.h" diff --git a/crypto/rsa/rsa_pk1.c b/crypto/rsa/rsa_pk1.c index 1bda998ca4..e32a1d5f8f 100644 --- a/crypto/rsa/rsa_pk1.c +++ b/crypto/rsa/rsa_pk1.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -#include "constant_time_locl.h" +#include "internal/constant_time_locl.h" #include #include "cryptlib.h" diff --git a/e_os.h b/e_os.h index 7f94bfcae6..4c1b4aa1de 100644 --- a/e_os.h +++ b/e_os.h @@ -605,7 +605,7 @@ extern int sys_nerr; # define strerror(errnum) \ (((errnum)<0 || (errnum)>=sys_nerr) ? NULL : sys_errlist[errnum]) /* Being signed SunOS 4.x memcpy breaks ASN1_OBJECT table lookup */ -# include "crypto/o_str.h" +# include "internal/o_str.h" # define memcmp OPENSSL_memcmp # endif @@ -624,7 +624,7 @@ extern int sys_nerr; # define strncasecmp _strnicmp # elif defined(OPENSSL_SYS_VMS) /* VMS below version 7.0 doesn't have strcasecmp() */ -# include "o_str.h" +# include "internal/o_str.h" # define strcasecmp OPENSSL_strcasecmp # define strncasecmp OPENSSL_strncasecmp # define OPENSSL_IMPLEMENTS_strncasecmp diff --git a/include/internal/constant_time_locl.h b/include/internal/constant_time_locl.h new file mode 100644 index 0000000000..c786aea949 --- /dev/null +++ b/include/internal/constant_time_locl.h @@ -0,0 +1,211 @@ +/* crypto/constant_time_locl.h */ +/*- + * Utilities for constant-time cryptography. + * + * Author: Emilia Kasper (emilia@openssl.org) + * Based on previous work by Bodo Moeller, Emilia Kasper, Adam Langley + * (Google). + * ==================================================================== + * Copyright (c) 2014 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_CONSTANT_TIME_LOCL_H +# define HEADER_CONSTANT_TIME_LOCL_H + +# include "e_os.h" /* For 'inline' */ + +#ifdef __cplusplus +extern "C" { +#endif + +/*- + * The boolean methods return a bitmask of all ones (0xff...f) for true + * and 0 for false. This is useful for choosing a value based on the result + * of a conditional in constant time. For example, + * + * if (a < b) { + * c = a; + * } else { + * c = b; + * } + * + * can be written as + * + * unsigned int lt = constant_time_lt(a, b); + * c = constant_time_select(lt, a, b); + */ + +/* + * Returns the given value with the MSB copied to all the other + * bits. Uses the fact that arithmetic shift shifts-in the sign bit. + * However, this is not ensured by the C standard so you may need to + * replace this with something else on odd CPUs. + */ +static inline unsigned int constant_time_msb(unsigned int a); + +/* + * Returns 0xff..f if a < b and 0 otherwise. + */ +static inline unsigned int constant_time_lt(unsigned int a, unsigned int b); +/* Convenience method for getting an 8-bit mask. */ +static inline unsigned char constant_time_lt_8(unsigned int a, + unsigned int b); + +/* + * Returns 0xff..f if a >= b and 0 otherwise. + */ +static inline unsigned int constant_time_ge(unsigned int a, unsigned int b); +/* Convenience method for getting an 8-bit mask. */ +static inline unsigned char constant_time_ge_8(unsigned int a, + unsigned int b); + +/* + * Returns 0xff..f if a == 0 and 0 otherwise. + */ +static inline unsigned int constant_time_is_zero(unsigned int a); +/* Convenience method for getting an 8-bit mask. */ +static inline unsigned char constant_time_is_zero_8(unsigned int a); + +/* + * Returns 0xff..f if a == b and 0 otherwise. + */ +static inline unsigned int constant_time_eq(unsigned int a, unsigned int b); +/* Convenience method for getting an 8-bit mask. */ +static inline unsigned char constant_time_eq_8(unsigned int a, + unsigned int b); +/* Signed integers. */ +static inline unsigned int constant_time_eq_int(int a, int b); +/* Convenience method for getting an 8-bit mask. */ +static inline unsigned char constant_time_eq_int_8(int a, int b); + +/*- + * Returns (mask & a) | (~mask & b). + * + * When |mask| is all 1s or all 0s (as returned by the methods above), + * the select methods return either |a| (if |mask| is nonzero) or |b| + * (if |mask| is zero). + */ +static inline unsigned int constant_time_select(unsigned int mask, + unsigned int a, + unsigned int b); +/* Convenience method for unsigned chars. */ +static inline unsigned char constant_time_select_8(unsigned char mask, + unsigned char a, + unsigned char b); +/* Convenience method for signed integers. */ +static inline int constant_time_select_int(unsigned int mask, int a, int b); + +static inline unsigned int constant_time_msb(unsigned int a) +{ + return 0 - (a >> (sizeof(a) * 8 - 1)); +} + +static inline unsigned int constant_time_lt(unsigned int a, unsigned int b) +{ + return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b))); +} + +static inline unsigned char constant_time_lt_8(unsigned int a, unsigned int b) +{ + return (unsigned char)(constant_time_lt(a, b)); +} + +static inline unsigned int constant_time_ge(unsigned int a, unsigned int b) +{ + return ~constant_time_lt(a, b); +} + +static inline unsigned char constant_time_ge_8(unsigned int a, unsigned int b) +{ + return (unsigned char)(constant_time_ge(a, b)); +} + +static inline unsigned int constant_time_is_zero(unsigned int a) +{ + return constant_time_msb(~a & (a - 1)); +} + +static inline unsigned char constant_time_is_zero_8(unsigned int a) +{ + return (unsigned char)(constant_time_is_zero(a)); +} + +static inline unsigned int constant_time_eq(unsigned int a, unsigned int b) +{ + return constant_time_is_zero(a ^ b); +} + +static inline unsigned char constant_time_eq_8(unsigned int a, unsigned int b) +{ + return (unsigned char)(constant_time_eq(a, b)); +} + +static inline unsigned int constant_time_eq_int(int a, int b) +{ + return constant_time_eq((unsigned)(a), (unsigned)(b)); +} + +static inline unsigned char constant_time_eq_int_8(int a, int b) +{ + return constant_time_eq_8((unsigned)(a), (unsigned)(b)); +} + +static inline unsigned int constant_time_select(unsigned int mask, + unsigned int a, + unsigned int b) +{ + return (mask & a) | (~mask & b); +} + +static inline unsigned char constant_time_select_8(unsigned char mask, + unsigned char a, + unsigned char b) +{ + return (unsigned char)(constant_time_select(mask, a, b)); +} + +static inline int constant_time_select_int(unsigned int mask, int a, int b) +{ + return (int)(constant_time_select(mask, (unsigned)(a), (unsigned)(b))); +} + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_CONSTANT_TIME_LOCL_H */ diff --git a/include/internal/o_dir.h b/include/internal/o_dir.h new file mode 100644 index 0000000000..d55431194e --- /dev/null +++ b/include/internal/o_dir.h @@ -0,0 +1,55 @@ +/* crypto/o_dir.h -*- mode:C; c-file-style: "eay" -*- */ +/* + * Copied from Richard Levitte's (richard@levitte.org) LP library. All + * symbol names have been changed, with permission from the author. + */ + +/* $LP: LPlib/source/LPdir.h,v 1.1 2004/06/14 08:56:04 _cvs_levitte Exp $ */ +/* + * Copyright (c) 2004, Richard Levitte + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef O_DIR_H +# define O_DIR_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OPENSSL_dir_context_st OPENSSL_DIR_CTX; + + /* + * returns NULL on error or end-of-directory. If it is end-of-directory, + * errno will be zero + */ +const char *OPENSSL_DIR_read(OPENSSL_DIR_CTX **ctx, const char *directory); + /* returns 1 on success, 0 on error */ +int OPENSSL_DIR_end(OPENSSL_DIR_CTX **ctx); + +#ifdef __cplusplus +} +#endif + +#endif /* LPDIR_H */ diff --git a/include/internal/o_str.h b/include/internal/o_str.h new file mode 100644 index 0000000000..5313528ed9 --- /dev/null +++ b/include/internal/o_str.h @@ -0,0 +1,69 @@ +/* crypto/o_str.h -*- mode:C; c-file-style: "eay" -*- */ +/* + * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project + * 2003. + */ +/* ==================================================================== + * Copyright (c) 2003 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_O_STR_H +# define HEADER_O_STR_H + +# include /* to get size_t */ + +int OPENSSL_strcasecmp(const char *str1, const char *str2); +int OPENSSL_strncasecmp(const char *str1, const char *str2, size_t n); +int OPENSSL_memcmp(const void *p1, const void *p2, size_t n); + +#endif diff --git a/ssl/Makefile b/ssl/Makefile index 18b17d27b5..7dc2e02897 100644 --- a/ssl/Makefile +++ b/ssl/Makefile @@ -5,7 +5,7 @@ DIR= ssl TOP= .. CC= cc -INCLUDES= -I../crypto -I$(TOP) -I../include +INCLUDES= -I$(TOP) -I../include CFLAG=-g MAKEFILE= Makefile AR= ar r diff --git a/ssl/record/ssl3_record.c b/ssl/record/ssl3_record.c index db6d4e792b..032812772f 100644 --- a/ssl/record/ssl3_record.c +++ b/ssl/record/ssl3_record.c @@ -110,7 +110,7 @@ */ #include "../ssl_locl.h" -#include "../../crypto/constant_time_locl.h" +#include "internal/constant_time_locl.h" #include #include "record_locl.h" diff --git a/ssl/s3_cbc.c b/ssl/s3_cbc.c index ac0c5f3ab8..f7997eaae3 100644 --- a/ssl/s3_cbc.c +++ b/ssl/s3_cbc.c @@ -53,7 +53,7 @@ * */ -#include "../crypto/constant_time_locl.h" +#include "internal/constant_time_locl.h" #include "ssl_locl.h" #include diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c index 04dbb7a735..4ee45eb57f 100644 --- a/ssl/s3_srvr.c +++ b/ssl/s3_srvr.c @@ -151,7 +151,7 @@ #include #include "ssl_locl.h" -#include "../crypto/constant_time_locl.h" +#include "internal/constant_time_locl.h" #include #include #include diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c index 38e7b822e5..d8b47e6209 100644 --- a/ssl/ssl_cert.c +++ b/ssl/ssl_cert.c @@ -123,7 +123,7 @@ # include #endif -#include "o_dir.h" +#include "internal/o_dir.h" #include #include #include diff --git a/test/constant_time_test.c b/test/constant_time_test.c index bdb270209e..ed3d7eaac4 100644 --- a/test/constant_time_test.c +++ b/test/constant_time_test.c @@ -44,7 +44,7 @@ * [including the GNU Public Licence.] */ -#include "../crypto/constant_time_locl.h" +#include "internal/constant_time_locl.h" #include #include diff --git a/util/mkdef.pl b/util/mkdef.pl index 6c4ce3fa3a..18bc1ab305 100755 --- a/util/mkdef.pl +++ b/util/mkdef.pl @@ -262,8 +262,8 @@ $ssl.=" include/openssl/srtp.h"; my $crypto ="include/openssl/crypto.h"; $crypto.=" crypto/cryptlib.h"; -$crypto.=" crypto/o_dir.h"; -$crypto.=" crypto/o_str.h"; +$crypto.=" include/internal/o_dir.h"; +$crypto.=" include/internal/o_str.h"; $crypto.=" include/openssl/des.h" ; # unless $no_des; $crypto.=" include/openssl/idea.h" ; # unless $no_idea; $crypto.=" include/openssl/rc4.h" ; # unless $no_rc4;