diff options
| author | cvs2svn <admin@example.com> | 2010-10-01 22:54:20 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 2010-10-01 22:54:20 +0000 |
| commit | 4e3116ba582489ffb124277aa36dfb5a1570558c (patch) | |
| tree | 75985dcb1495258d2f93d846c0e2d85abd778661 /src/lib/libcrypto | |
| parent | 75291ae343a87368ad49c13ac02f85a88159417f (diff) | |
| download | openbsd-openssh_1_0_0_a.tar.gz openbsd-openssh_1_0_0_a.tar.bz2 openbsd-openssh_1_0_0_a.zip | |
This commit was manufactured by cvs2git to create tag 'openssh_1_0_0_a'.openssh_1_0_0_a
Diffstat (limited to '')
163 files changed, 13814 insertions, 26498 deletions
diff --git a/src/lib/libcrypto/LPdir_nyi.c b/src/lib/libcrypto/LPdir_nyi.c new file mode 100644 index 0000000000..6c1a50e6a8 --- /dev/null +++ b/src/lib/libcrypto/LPdir_nyi.c | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | /* $LP: LPlib/source/LPdir_win.c,v 1.1 2004/06/14 10:07:56 _cvs_levitte Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2004, Richard Levitte <richard@levitte.org> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 25 | * SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | |||
| 28 | #ifndef LPDIR_H | ||
| 29 | #include "LPdir.h" | ||
| 30 | #endif | ||
| 31 | |||
| 32 | struct LP_dir_context_st { void *dummy; }; | ||
| 33 | const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory) | ||
| 34 | { | ||
| 35 | errno = EINVAL; | ||
| 36 | return 0; | ||
| 37 | } | ||
| 38 | int LP_find_file_end(LP_DIR_CTX **ctx) | ||
| 39 | { | ||
| 40 | errno = EINVAL; | ||
| 41 | return 0; | ||
| 42 | } | ||
diff --git a/src/lib/libcrypto/LPdir_unix.c b/src/lib/libcrypto/LPdir_unix.c new file mode 100644 index 0000000000..b004cd99e8 --- /dev/null +++ b/src/lib/libcrypto/LPdir_unix.c | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | /* $LP: LPlib/source/LPdir_unix.c,v 1.11 2004/09/23 22:07:22 _cvs_levitte Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2004, Richard Levitte <richard@levitte.org> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 16 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 18 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 19 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 21 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <stddef.h> | ||
| 29 | #include <stdlib.h> | ||
| 30 | #include <limits.h> | ||
| 31 | #include <string.h> | ||
| 32 | #include <sys/types.h> | ||
| 33 | #include <dirent.h> | ||
| 34 | #include <errno.h> | ||
| 35 | #ifndef LPDIR_H | ||
| 36 | #include "LPdir.h" | ||
| 37 | #endif | ||
| 38 | |||
| 39 | /* The POSIXly macro for the maximum number of characters in a file path | ||
| 40 | is NAME_MAX. However, some operating systems use PATH_MAX instead. | ||
| 41 | Therefore, it seems natural to first check for PATH_MAX and use that, | ||
| 42 | and if it doesn't exist, use NAME_MAX. */ | ||
| 43 | #if defined(PATH_MAX) | ||
| 44 | # define LP_ENTRY_SIZE PATH_MAX | ||
| 45 | #elif defined(NAME_MAX) | ||
| 46 | # define LP_ENTRY_SIZE NAME_MAX | ||
| 47 | #endif | ||
| 48 | |||
| 49 | /* Of course, there's the possibility that neither PATH_MAX nor NAME_MAX | ||
| 50 | exist. It's also possible that NAME_MAX exists but is define to a | ||
| 51 | very small value (HP-UX offers 14), so we need to check if we got a | ||
| 52 | result, and if it meets a minimum standard, and create or change it | ||
| 53 | if not. */ | ||
| 54 | #if !defined(LP_ENTRY_SIZE) || LP_ENTRY_SIZE<255 | ||
| 55 | # undef LP_ENTRY_SIZE | ||
| 56 | # define LP_ENTRY_SIZE 255 | ||
| 57 | #endif | ||
| 58 | |||
| 59 | struct LP_dir_context_st | ||
| 60 | { | ||
| 61 | DIR *dir; | ||
| 62 | char entry_name[LP_ENTRY_SIZE+1]; | ||
| 63 | }; | ||
| 64 | |||
| 65 | const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory) | ||
| 66 | { | ||
| 67 | struct dirent *direntry = NULL; | ||
| 68 | |||
| 69 | if (ctx == NULL || directory == NULL) | ||
| 70 | { | ||
| 71 | errno = EINVAL; | ||
| 72 | return 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | errno = 0; | ||
| 76 | if (*ctx == NULL) | ||
| 77 | { | ||
| 78 | *ctx = (LP_DIR_CTX *)malloc(sizeof(LP_DIR_CTX)); | ||
| 79 | if (*ctx == NULL) | ||
| 80 | { | ||
| 81 | errno = ENOMEM; | ||
| 82 | return 0; | ||
| 83 | } | ||
| 84 | memset(*ctx, '\0', sizeof(LP_DIR_CTX)); | ||
| 85 | |||
| 86 | (*ctx)->dir = opendir(directory); | ||
| 87 | if ((*ctx)->dir == NULL) | ||
| 88 | { | ||
| 89 | int save_errno = errno; /* Probably not needed, but I'm paranoid */ | ||
| 90 | free(*ctx); | ||
| 91 | *ctx = NULL; | ||
| 92 | errno = save_errno; | ||
| 93 | return 0; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | direntry = readdir((*ctx)->dir); | ||
| 98 | if (direntry == NULL) | ||
| 99 | { | ||
| 100 | return 0; | ||
| 101 | } | ||
| 102 | |||
| 103 | strncpy((*ctx)->entry_name, direntry->d_name, sizeof((*ctx)->entry_name) - 1); | ||
| 104 | (*ctx)->entry_name[sizeof((*ctx)->entry_name) - 1] = '\0'; | ||
| 105 | return (*ctx)->entry_name; | ||
| 106 | } | ||
| 107 | |||
| 108 | int LP_find_file_end(LP_DIR_CTX **ctx) | ||
| 109 | { | ||
| 110 | if (ctx != NULL && *ctx != NULL) | ||
| 111 | { | ||
| 112 | int ret = closedir((*ctx)->dir); | ||
| 113 | |||
| 114 | free(*ctx); | ||
| 115 | switch (ret) | ||
| 116 | { | ||
| 117 | case 0: | ||
| 118 | return 1; | ||
| 119 | case -1: | ||
| 120 | return 0; | ||
| 121 | default: | ||
| 122 | break; | ||
| 123 | } | ||
| 124 | } | ||
| 125 | errno = EINVAL; | ||
| 126 | return 0; | ||
| 127 | } | ||
diff --git a/src/lib/libcrypto/LPdir_vms.c b/src/lib/libcrypto/LPdir_vms.c new file mode 100644 index 0000000000..85b427a623 --- /dev/null +++ b/src/lib/libcrypto/LPdir_vms.c | |||
| @@ -0,0 +1,199 @@ | |||
| 1 | /* $LP: LPlib/source/LPdir_vms.c,v 1.20 2004/08/26 13:36:05 _cvs_levitte Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2004, Richard Levitte <richard@levitte.org> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 16 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 18 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 19 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 21 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <stddef.h> | ||
| 29 | #include <stdlib.h> | ||
| 30 | #include <string.h> | ||
| 31 | #include <errno.h> | ||
| 32 | #include <descrip.h> | ||
| 33 | #include <namdef.h> | ||
| 34 | #include <rmsdef.h> | ||
| 35 | #include <libfildef.h> | ||
| 36 | #include <lib$routines.h> | ||
| 37 | #include <strdef.h> | ||
| 38 | #include <str$routines.h> | ||
| 39 | #include <stsdef.h> | ||
| 40 | #ifndef LPDIR_H | ||
| 41 | #include "LPdir.h" | ||
| 42 | #endif | ||
| 43 | |||
| 44 | /* Because some compiler options hide this macor */ | ||
| 45 | #ifndef EVMSERR | ||
| 46 | #define EVMSERR 65535 /* error for non-translatable VMS errors */ | ||
| 47 | #endif | ||
| 48 | |||
| 49 | struct LP_dir_context_st | ||
| 50 | { | ||
| 51 | unsigned long VMS_context; | ||
| 52 | #ifdef NAML$C_MAXRSS | ||
| 53 | char filespec[NAML$C_MAXRSS+1]; | ||
| 54 | char result[NAML$C_MAXRSS+1]; | ||
| 55 | #else | ||
| 56 | char filespec[256]; | ||
| 57 | char result[256]; | ||
| 58 | #endif | ||
| 59 | struct dsc$descriptor_d filespec_dsc; | ||
| 60 | struct dsc$descriptor_d result_dsc; | ||
| 61 | }; | ||
| 62 | |||
| 63 | const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory) | ||
| 64 | { | ||
| 65 | int status; | ||
| 66 | char *p, *r; | ||
| 67 | size_t l; | ||
| 68 | unsigned long flags = 0; | ||
| 69 | #ifdef NAML$C_MAXRSS | ||
| 70 | flags |= LIB$M_FIL_LONG_NAMES; | ||
| 71 | #endif | ||
| 72 | |||
| 73 | if (ctx == NULL || directory == NULL) | ||
| 74 | { | ||
| 75 | errno = EINVAL; | ||
| 76 | return 0; | ||
| 77 | } | ||
| 78 | |||
| 79 | errno = 0; | ||
| 80 | if (*ctx == NULL) | ||
| 81 | { | ||
| 82 | size_t filespeclen = strlen(directory); | ||
| 83 | char *filespec = NULL; | ||
| 84 | |||
| 85 | /* MUST be a VMS directory specification! Let's estimate if it is. */ | ||
| 86 | if (directory[filespeclen-1] != ']' | ||
| 87 | && directory[filespeclen-1] != '>' | ||
| 88 | && directory[filespeclen-1] != ':') | ||
| 89 | { | ||
| 90 | errno = EINVAL; | ||
| 91 | return 0; | ||
| 92 | } | ||
| 93 | |||
| 94 | filespeclen += 4; /* "*.*;" */ | ||
| 95 | |||
| 96 | if (filespeclen > | ||
| 97 | #ifdef NAML$C_MAXRSS | ||
| 98 | NAML$C_MAXRSS | ||
| 99 | #else | ||
| 100 | 255 | ||
| 101 | #endif | ||
| 102 | ) | ||
| 103 | { | ||
| 104 | errno = ENAMETOOLONG; | ||
| 105 | return 0; | ||
| 106 | } | ||
| 107 | |||
| 108 | *ctx = (LP_DIR_CTX *)malloc(sizeof(LP_DIR_CTX)); | ||
| 109 | if (*ctx == NULL) | ||
| 110 | { | ||
| 111 | errno = ENOMEM; | ||
| 112 | return 0; | ||
| 113 | } | ||
| 114 | memset(*ctx, '\0', sizeof(LP_DIR_CTX)); | ||
| 115 | |||
| 116 | strcpy((*ctx)->filespec,directory); | ||
| 117 | strcat((*ctx)->filespec,"*.*;"); | ||
| 118 | (*ctx)->filespec_dsc.dsc$w_length = filespeclen; | ||
| 119 | (*ctx)->filespec_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | ||
| 120 | (*ctx)->filespec_dsc.dsc$b_class = DSC$K_CLASS_S; | ||
| 121 | (*ctx)->filespec_dsc.dsc$a_pointer = (*ctx)->filespec; | ||
| 122 | (*ctx)->result_dsc.dsc$w_length = 0; | ||
| 123 | (*ctx)->result_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | ||
| 124 | (*ctx)->result_dsc.dsc$b_class = DSC$K_CLASS_D; | ||
| 125 | (*ctx)->result_dsc.dsc$a_pointer = 0; | ||
| 126 | } | ||
| 127 | |||
| 128 | (*ctx)->result_dsc.dsc$w_length = 0; | ||
| 129 | (*ctx)->result_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | ||
| 130 | (*ctx)->result_dsc.dsc$b_class = DSC$K_CLASS_D; | ||
| 131 | (*ctx)->result_dsc.dsc$a_pointer = 0; | ||
| 132 | |||
| 133 | status = lib$find_file(&(*ctx)->filespec_dsc, &(*ctx)->result_dsc, | ||
| 134 | &(*ctx)->VMS_context, 0, 0, 0, &flags); | ||
| 135 | |||
| 136 | if (status == RMS$_NMF) | ||
| 137 | { | ||
| 138 | errno = 0; | ||
| 139 | vaxc$errno = status; | ||
| 140 | return NULL; | ||
| 141 | } | ||
| 142 | |||
| 143 | if(!$VMS_STATUS_SUCCESS(status)) | ||
| 144 | { | ||
| 145 | errno = EVMSERR; | ||
| 146 | vaxc$errno = status; | ||
| 147 | return NULL; | ||
| 148 | } | ||
| 149 | |||
| 150 | /* Quick, cheap and dirty way to discard any device and directory, | ||
| 151 | since we only want file names */ | ||
| 152 | l = (*ctx)->result_dsc.dsc$w_length; | ||
| 153 | p = (*ctx)->result_dsc.dsc$a_pointer; | ||
| 154 | r = p; | ||
| 155 | for (; *p; p++) | ||
| 156 | { | ||
| 157 | if (*p == '^' && p[1] != '\0') /* Take care of ODS-5 escapes */ | ||
| 158 | { | ||
| 159 | p++; | ||
| 160 | } | ||
| 161 | else if (*p == ':' || *p == '>' || *p == ']') | ||
| 162 | { | ||
| 163 | l -= p + 1 - r; | ||
| 164 | r = p + 1; | ||
| 165 | } | ||
| 166 | else if (*p == ';') | ||
| 167 | { | ||
| 168 | l = p - r; | ||
| 169 | break; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | strncpy((*ctx)->result, r, l); | ||
| 174 | (*ctx)->result[l] = '\0'; | ||
| 175 | str$free1_dx(&(*ctx)->result_dsc); | ||
| 176 | |||
| 177 | return (*ctx)->result; | ||
| 178 | } | ||
| 179 | |||
| 180 | int LP_find_file_end(LP_DIR_CTX **ctx) | ||
| 181 | { | ||
| 182 | if (ctx != NULL && *ctx != NULL) | ||
| 183 | { | ||
| 184 | int status = lib$find_file_end(&(*ctx)->VMS_context); | ||
| 185 | |||
| 186 | free(*ctx); | ||
| 187 | |||
| 188 | if(!$VMS_STATUS_SUCCESS(status)) | ||
| 189 | { | ||
| 190 | errno = EVMSERR; | ||
| 191 | vaxc$errno = status; | ||
| 192 | return 0; | ||
| 193 | } | ||
| 194 | return 1; | ||
| 195 | } | ||
| 196 | errno = EINVAL; | ||
| 197 | return 0; | ||
| 198 | } | ||
| 199 | |||
diff --git a/src/lib/libcrypto/LPdir_win.c b/src/lib/libcrypto/LPdir_win.c new file mode 100644 index 0000000000..702dbc730f --- /dev/null +++ b/src/lib/libcrypto/LPdir_win.c | |||
| @@ -0,0 +1,153 @@ | |||
| 1 | /* $LP: LPlib/source/LPdir_win.c,v 1.10 2004/08/26 13:36:05 _cvs_levitte Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2004, Richard Levitte <richard@levitte.org> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 16 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 18 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 19 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 21 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | #include <windows.h> | ||
| 28 | #include <tchar.h> | ||
| 29 | #ifndef LPDIR_H | ||
| 30 | #include "LPdir.h" | ||
| 31 | #endif | ||
| 32 | |||
| 33 | /* We're most likely overcautious here, but let's reserve for | ||
| 34 | broken WinCE headers and explicitly opt for UNICODE call. | ||
| 35 | Keep in mind that our WinCE builds are compiled with -DUNICODE | ||
| 36 | [as well as -D_UNICODE]. */ | ||
| 37 | #if defined(LP_SYS_WINCE) && !defined(FindFirstFile) | ||
| 38 | # define FindFirstFile FindFirstFileW | ||
| 39 | #endif | ||
| 40 | #if defined(LP_SYS_WINCE) && !defined(FindFirstFile) | ||
| 41 | # define FindNextFile FindNextFileW | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #ifndef NAME_MAX | ||
| 45 | #define NAME_MAX 255 | ||
| 46 | #endif | ||
| 47 | |||
| 48 | struct LP_dir_context_st | ||
| 49 | { | ||
| 50 | WIN32_FIND_DATA ctx; | ||
| 51 | HANDLE handle; | ||
| 52 | char entry_name[NAME_MAX+1]; | ||
| 53 | }; | ||
| 54 | |||
| 55 | const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory) | ||
| 56 | { | ||
| 57 | if (ctx == NULL || directory == NULL) | ||
| 58 | { | ||
| 59 | errno = EINVAL; | ||
| 60 | return 0; | ||
| 61 | } | ||
| 62 | |||
| 63 | errno = 0; | ||
| 64 | if (*ctx == NULL) | ||
| 65 | { | ||
| 66 | *ctx = (LP_DIR_CTX *)malloc(sizeof(LP_DIR_CTX)); | ||
| 67 | if (*ctx == NULL) | ||
| 68 | { | ||
| 69 | errno = ENOMEM; | ||
| 70 | return 0; | ||
| 71 | } | ||
| 72 | memset(*ctx, '\0', sizeof(LP_DIR_CTX)); | ||
| 73 | |||
| 74 | if (sizeof(TCHAR) != sizeof(char)) | ||
| 75 | { | ||
| 76 | TCHAR *wdir = NULL; | ||
| 77 | /* len_0 denotes string length *with* trailing 0 */ | ||
| 78 | size_t index = 0,len_0 = strlen(directory) + 1; | ||
| 79 | |||
| 80 | wdir = (TCHAR *)malloc(len_0 * sizeof(TCHAR)); | ||
| 81 | if (wdir == NULL) | ||
| 82 | { | ||
| 83 | free(*ctx); | ||
| 84 | *ctx = NULL; | ||
| 85 | errno = ENOMEM; | ||
| 86 | return 0; | ||
| 87 | } | ||
| 88 | |||
| 89 | #ifdef LP_MULTIBYTE_AVAILABLE | ||
| 90 | if (!MultiByteToWideChar(CP_ACP, 0, directory, len_0, (WCHAR *)wdir, len_0)) | ||
| 91 | #endif | ||
| 92 | for (index = 0; index < len_0; index++) | ||
| 93 | wdir[index] = (TCHAR)directory[index]; | ||
| 94 | |||
| 95 | (*ctx)->handle = FindFirstFile(wdir, &(*ctx)->ctx); | ||
| 96 | |||
| 97 | free(wdir); | ||
| 98 | } | ||
| 99 | else | ||
| 100 | (*ctx)->handle = FindFirstFile((TCHAR *)directory, &(*ctx)->ctx); | ||
| 101 | |||
| 102 | if ((*ctx)->handle == INVALID_HANDLE_VALUE) | ||
| 103 | { | ||
| 104 | free(*ctx); | ||
| 105 | *ctx = NULL; | ||
| 106 | errno = EINVAL; | ||
| 107 | return 0; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | else | ||
| 111 | { | ||
| 112 | if (FindNextFile((*ctx)->handle, &(*ctx)->ctx) == FALSE) | ||
| 113 | { | ||
| 114 | return 0; | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | if (sizeof(TCHAR) != sizeof(char)) | ||
| 119 | { | ||
| 120 | TCHAR *wdir = (*ctx)->ctx.cFileName; | ||
| 121 | size_t index, len_0 = 0; | ||
| 122 | |||
| 123 | while (wdir[len_0] && len_0 < (sizeof((*ctx)->entry_name) - 1)) len_0++; | ||
| 124 | len_0++; | ||
| 125 | |||
| 126 | #ifdef LP_MULTIBYTE_AVAILABLE | ||
| 127 | if (!WideCharToMultiByte(CP_ACP, 0, (WCHAR *)wdir, len_0, (*ctx)->entry_name, | ||
| 128 | sizeof((*ctx)->entry_name), NULL, 0)) | ||
| 129 | #endif | ||
| 130 | for (index = 0; index < len_0; index++) | ||
| 131 | (*ctx)->entry_name[index] = (char)wdir[index]; | ||
| 132 | } | ||
| 133 | else | ||
| 134 | strncpy((*ctx)->entry_name, (const char *)(*ctx)->ctx.cFileName, | ||
| 135 | sizeof((*ctx)->entry_name)-1); | ||
| 136 | |||
| 137 | (*ctx)->entry_name[sizeof((*ctx)->entry_name)-1] = '\0'; | ||
| 138 | |||
| 139 | return (*ctx)->entry_name; | ||
| 140 | } | ||
| 141 | |||
| 142 | int LP_find_file_end(LP_DIR_CTX **ctx) | ||
| 143 | { | ||
| 144 | if (ctx != NULL && *ctx != NULL) | ||
| 145 | { | ||
| 146 | FindClose((*ctx)->handle); | ||
| 147 | free(*ctx); | ||
| 148 | *ctx = NULL; | ||
| 149 | return 1; | ||
| 150 | } | ||
| 151 | errno = EINVAL; | ||
| 152 | return 0; | ||
| 153 | } | ||
diff --git a/src/lib/libcrypto/LPdir_win32.c b/src/lib/libcrypto/LPdir_win32.c new file mode 100644 index 0000000000..e39872da52 --- /dev/null +++ b/src/lib/libcrypto/LPdir_win32.c | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | /* $LP: LPlib/source/LPdir_win32.c,v 1.3 2004/08/26 13:36:05 _cvs_levitte Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2004, Richard Levitte <richard@levitte.org> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 16 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 18 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 19 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 21 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | |||
| 28 | #define LP_SYS_WIN32 | ||
| 29 | #define LP_MULTIBYTE_AVAILABLE | ||
| 30 | #include "LPdir_win.c" | ||
diff --git a/src/lib/libcrypto/LPdir_wince.c b/src/lib/libcrypto/LPdir_wince.c new file mode 100644 index 0000000000..ab0e1e6f4f --- /dev/null +++ b/src/lib/libcrypto/LPdir_wince.c | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /* $LP: LPlib/source/LPdir_wince.c,v 1.3 2004/08/26 13:36:05 _cvs_levitte Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2004, Richard Levitte <richard@levitte.org> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 16 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 18 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 19 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 21 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | |||
| 28 | #define LP_SYS_WINCE | ||
| 29 | /* We might want to define LP_MULTIBYTE_AVAILABLE here. It's currently | ||
| 30 | under investigation what the exact conditions would be */ | ||
| 31 | #include "LPdir_win.c" | ||
diff --git a/src/lib/libcrypto/asn1/a_hdr.c b/src/lib/libcrypto/asn1/a_hdr.c deleted file mode 100644 index d1c2a7b9e3..0000000000 --- a/src/lib/libcrypto/asn1/a_hdr.c +++ /dev/null | |||
| @@ -1,119 +0,0 @@ | |||
| 1 | /* crypto/asn1/a_hdr.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1_mac.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | |||
| 64 | int i2d_ASN1_HEADER(ASN1_HEADER *a, unsigned char **pp) | ||
| 65 | { | ||
| 66 | M_ASN1_I2D_vars(a); | ||
| 67 | |||
| 68 | M_ASN1_I2D_len(a->header, i2d_ASN1_OCTET_STRING); | ||
| 69 | M_ASN1_I2D_len(a->data, a->meth->i2d); | ||
| 70 | |||
| 71 | M_ASN1_I2D_seq_total(); | ||
| 72 | |||
| 73 | M_ASN1_I2D_put(a->header, i2d_ASN1_OCTET_STRING); | ||
| 74 | M_ASN1_I2D_put(a->data, a->meth->i2d); | ||
| 75 | |||
| 76 | M_ASN1_I2D_finish(); | ||
| 77 | } | ||
| 78 | |||
| 79 | ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a, const unsigned char **pp, | ||
| 80 | long length) | ||
| 81 | { | ||
| 82 | M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new); | ||
| 83 | |||
| 84 | M_ASN1_D2I_Init(); | ||
| 85 | M_ASN1_D2I_start_sequence(); | ||
| 86 | M_ASN1_D2I_get_x(ASN1_OCTET_STRING,ret->header,d2i_ASN1_OCTET_STRING); | ||
| 87 | if (ret->meth != NULL) | ||
| 88 | { | ||
| 89 | M_ASN1_D2I_get_x(void,ret->data,ret->meth->d2i); | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | if (a != NULL) (*a)=ret; | ||
| 94 | return(ret); | ||
| 95 | } | ||
| 96 | M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER); | ||
| 97 | } | ||
| 98 | |||
| 99 | ASN1_HEADER *ASN1_HEADER_new(void) | ||
| 100 | { | ||
| 101 | ASN1_HEADER *ret=NULL; | ||
| 102 | ASN1_CTX c; | ||
| 103 | |||
| 104 | M_ASN1_New_Malloc(ret,ASN1_HEADER); | ||
| 105 | M_ASN1_New(ret->header,M_ASN1_OCTET_STRING_new); | ||
| 106 | ret->meth=NULL; | ||
| 107 | ret->data=NULL; | ||
| 108 | return(ret); | ||
| 109 | M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW); | ||
| 110 | } | ||
| 111 | |||
| 112 | void ASN1_HEADER_free(ASN1_HEADER *a) | ||
| 113 | { | ||
| 114 | if (a == NULL) return; | ||
| 115 | M_ASN1_OCTET_STRING_free(a->header); | ||
| 116 | if (a->meth != NULL) | ||
| 117 | a->meth->destroy(a->data); | ||
| 118 | OPENSSL_free(a); | ||
| 119 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_meth.c b/src/lib/libcrypto/asn1/a_meth.c deleted file mode 100644 index 50bea917e3..0000000000 --- a/src/lib/libcrypto/asn1/a_meth.c +++ /dev/null | |||
| @@ -1,84 +0,0 @@ | |||
| 1 | /* crypto/asn1/a_meth.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/buffer.h> | ||
| 62 | #include <openssl/asn1.h> | ||
| 63 | |||
| 64 | static ASN1_METHOD ia5string_meth={ | ||
| 65 | (I2D_OF(void)) i2d_ASN1_IA5STRING, | ||
| 66 | (D2I_OF(void)) d2i_ASN1_IA5STRING, | ||
| 67 | (void *(*)(void))ASN1_STRING_new, | ||
| 68 | (void (*)(void *))ASN1_STRING_free}; | ||
| 69 | |||
| 70 | static ASN1_METHOD bit_string_meth={ | ||
| 71 | (I2D_OF(void)) i2d_ASN1_BIT_STRING, | ||
| 72 | (D2I_OF(void)) d2i_ASN1_BIT_STRING, | ||
| 73 | (void *(*)(void))ASN1_STRING_new, | ||
| 74 | (void (*)(void *))ASN1_STRING_free}; | ||
| 75 | |||
| 76 | ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void) | ||
| 77 | { | ||
| 78 | return(&ia5string_meth); | ||
| 79 | } | ||
| 80 | |||
| 81 | ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void) | ||
| 82 | { | ||
| 83 | return(&bit_string_meth); | ||
| 84 | } | ||
diff --git a/src/lib/libcrypto/asn1/p8_key.c b/src/lib/libcrypto/asn1/p8_key.c deleted file mode 100644 index 3a31248e14..0000000000 --- a/src/lib/libcrypto/asn1/p8_key.c +++ /dev/null | |||
| @@ -1,131 +0,0 @@ | |||
| 1 | /* crypto/asn1/p8_key.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/asn1_mac.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | |||
| 64 | int i2d_X509_KEY(X509 *a, unsigned char **pp) | ||
| 65 | { | ||
| 66 | M_ASN1_I2D_vars(a); | ||
| 67 | |||
| 68 | M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF); | ||
| 69 | M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR); | ||
| 70 | M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING); | ||
| 71 | |||
| 72 | M_ASN1_I2D_seq_total(); | ||
| 73 | |||
| 74 | M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF); | ||
| 75 | M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR); | ||
| 76 | M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING); | ||
| 77 | |||
| 78 | M_ASN1_I2D_finish(); | ||
| 79 | } | ||
| 80 | |||
| 81 | X509 *d2i_X509_KEY(X509 **a, unsigned char **pp, long length) | ||
| 82 | { | ||
| 83 | M_ASN1_D2I_vars(a,X509 *,X509_new); | ||
| 84 | |||
| 85 | M_ASN1_D2I_Init(); | ||
| 86 | M_ASN1_D2I_start_sequence(); | ||
| 87 | M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF); | ||
| 88 | M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); | ||
| 89 | M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); | ||
| 90 | M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509); | ||
| 91 | } | ||
| 92 | |||
| 93 | X509 *X509_KEY_new(void) | ||
| 94 | { | ||
| 95 | X509_KEY *ret=NULL; | ||
| 96 | |||
| 97 | M_ASN1_New_OPENSSL_malloc(ret,X509_KEY); | ||
| 98 | ret->references=1; | ||
| 99 | ret->type=NID | ||
| 100 | M_ASN1_New(ret->cert_info,X509_CINF_new); | ||
| 101 | M_ASN1_New(ret->sig_alg,X509_ALGOR_new); | ||
| 102 | M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); | ||
| 103 | return(ret); | ||
| 104 | M_ASN1_New_Error(ASN1_F_X509_NEW); | ||
| 105 | } | ||
| 106 | |||
| 107 | void X509_KEY_free(X509 *a) | ||
| 108 | { | ||
| 109 | int i; | ||
| 110 | |||
| 111 | if (a == NULL) return; | ||
| 112 | |||
| 113 | i=CRYPTO_add_lock(&a->references,-1,CRYPTO_LOCK_X509_KEY); | ||
| 114 | #ifdef REF_PRINT | ||
| 115 | REF_PRINT("X509_KEY",a); | ||
| 116 | #endif | ||
| 117 | if (i > 0) return; | ||
| 118 | #ifdef REF_CHECK | ||
| 119 | if (i < 0) | ||
| 120 | { | ||
| 121 | fprintf(stderr,"X509_KEY_free, bad reference count\n"); | ||
| 122 | abort(); | ||
| 123 | } | ||
| 124 | #endif | ||
| 125 | |||
| 126 | X509_CINF_free(a->cert_info); | ||
| 127 | X509_ALGOR_free(a->sig_alg); | ||
| 128 | ASN1_BIT_STRING_free(a->signature); | ||
| 129 | OPENSSL_free(a); | ||
| 130 | } | ||
| 131 | |||
diff --git a/src/lib/libcrypto/bio/bio_lcl.h b/src/lib/libcrypto/bio/bio_lcl.h new file mode 100644 index 0000000000..e7f7ec8d8b --- /dev/null +++ b/src/lib/libcrypto/bio/bio_lcl.h | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | #include <openssl/bio.h> | ||
| 2 | |||
| 3 | #if BIO_FLAGS_UPLINK==0 | ||
| 4 | /* Shortcut UPLINK calls on most platforms... */ | ||
| 5 | #define UP_stdin stdin | ||
| 6 | #define UP_stdout stdout | ||
| 7 | #define UP_stderr stderr | ||
| 8 | #define UP_fprintf fprintf | ||
| 9 | #define UP_fgets fgets | ||
| 10 | #define UP_fread fread | ||
| 11 | #define UP_fwrite fwrite | ||
| 12 | #undef UP_fsetmod | ||
| 13 | #define UP_feof feof | ||
| 14 | #define UP_fclose fclose | ||
| 15 | |||
| 16 | #define UP_fopen fopen | ||
| 17 | #define UP_fseek fseek | ||
| 18 | #define UP_ftell ftell | ||
| 19 | #define UP_fflush fflush | ||
| 20 | #define UP_ferror ferror | ||
| 21 | #ifdef _WIN32 | ||
| 22 | #define UP_fileno _fileno | ||
| 23 | #define UP_open _open | ||
| 24 | #define UP_read _read | ||
| 25 | #define UP_write _write | ||
| 26 | #define UP_lseek _lseek | ||
| 27 | #define UP_close _close | ||
| 28 | #else | ||
| 29 | #define UP_fileno fileno | ||
| 30 | #define UP_open open | ||
| 31 | #define UP_read read | ||
| 32 | #define UP_write write | ||
| 33 | #define UP_lseek lseek | ||
| 34 | #define UP_close close | ||
| 35 | #endif | ||
| 36 | #endif | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.s b/src/lib/libcrypto/bn/asm/alpha.s deleted file mode 100644 index 555ff0b92d..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.s +++ /dev/null | |||
| @@ -1,3199 +0,0 @@ | |||
| 1 | # DEC Alpha assember | ||
| 2 | # The bn_div_words is actually gcc output but the other parts are hand done. | ||
| 3 | # Thanks to tzeruch@ceddec.com for sending me the gcc output for | ||
| 4 | # bn_div_words. | ||
| 5 | # I've gone back and re-done most of routines. | ||
| 6 | # The key thing to remeber for the 164 CPU is that while a | ||
| 7 | # multiply operation takes 8 cycles, another one can only be issued | ||
| 8 | # after 4 cycles have elapsed. I've done modification to help | ||
| 9 | # improve this. Also, normally, a ld instruction will not be available | ||
| 10 | # for about 3 cycles. | ||
| 11 | .file 1 "bn_asm.c" | ||
| 12 | .set noat | ||
| 13 | gcc2_compiled.: | ||
| 14 | __gnu_compiled_c: | ||
| 15 | .text | ||
| 16 | .align 3 | ||
| 17 | .globl bn_mul_add_words | ||
| 18 | .ent bn_mul_add_words | ||
| 19 | bn_mul_add_words: | ||
| 20 | bn_mul_add_words..ng: | ||
| 21 | .frame $30,0,$26,0 | ||
| 22 | .prologue 0 | ||
| 23 | .align 5 | ||
| 24 | subq $18,4,$18 | ||
| 25 | bis $31,$31,$0 | ||
| 26 | blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code | ||
| 27 | ldq $20,0($17) # 1 1 | ||
| 28 | ldq $1,0($16) # 1 1 | ||
| 29 | .align 3 | ||
| 30 | $42: | ||
| 31 | mulq $20,$19,$5 # 1 2 1 ###### | ||
| 32 | ldq $21,8($17) # 2 1 | ||
| 33 | ldq $2,8($16) # 2 1 | ||
| 34 | umulh $20,$19,$20 # 1 2 ###### | ||
| 35 | ldq $27,16($17) # 3 1 | ||
| 36 | ldq $3,16($16) # 3 1 | ||
| 37 | mulq $21,$19,$6 # 2 2 1 ###### | ||
| 38 | ldq $28,24($17) # 4 1 | ||
| 39 | addq $1,$5,$1 # 1 2 2 | ||
| 40 | ldq $4,24($16) # 4 1 | ||
| 41 | umulh $21,$19,$21 # 2 2 ###### | ||
| 42 | cmpult $1,$5,$22 # 1 2 3 1 | ||
| 43 | addq $20,$22,$20 # 1 3 1 | ||
| 44 | addq $1,$0,$1 # 1 2 3 1 | ||
| 45 | mulq $27,$19,$7 # 3 2 1 ###### | ||
| 46 | cmpult $1,$0,$0 # 1 2 3 2 | ||
| 47 | addq $2,$6,$2 # 2 2 2 | ||
| 48 | addq $20,$0,$0 # 1 3 2 | ||
| 49 | cmpult $2,$6,$23 # 2 2 3 1 | ||
| 50 | addq $21,$23,$21 # 2 3 1 | ||
| 51 | umulh $27,$19,$27 # 3 2 ###### | ||
| 52 | addq $2,$0,$2 # 2 2 3 1 | ||
| 53 | cmpult $2,$0,$0 # 2 2 3 2 | ||
| 54 | subq $18,4,$18 | ||
| 55 | mulq $28,$19,$8 # 4 2 1 ###### | ||
| 56 | addq $21,$0,$0 # 2 3 2 | ||
| 57 | addq $3,$7,$3 # 3 2 2 | ||
| 58 | addq $16,32,$16 | ||
| 59 | cmpult $3,$7,$24 # 3 2 3 1 | ||
| 60 | stq $1,-32($16) # 1 2 4 | ||
| 61 | umulh $28,$19,$28 # 4 2 ###### | ||
| 62 | addq $27,$24,$27 # 3 3 1 | ||
| 63 | addq $3,$0,$3 # 3 2 3 1 | ||
| 64 | stq $2,-24($16) # 2 2 4 | ||
| 65 | cmpult $3,$0,$0 # 3 2 3 2 | ||
| 66 | stq $3,-16($16) # 3 2 4 | ||
| 67 | addq $4,$8,$4 # 4 2 2 | ||
| 68 | addq $27,$0,$0 # 3 3 2 | ||
| 69 | cmpult $4,$8,$25 # 4 2 3 1 | ||
| 70 | addq $17,32,$17 | ||
| 71 | addq $28,$25,$28 # 4 3 1 | ||
| 72 | addq $4,$0,$4 # 4 2 3 1 | ||
| 73 | cmpult $4,$0,$0 # 4 2 3 2 | ||
| 74 | stq $4,-8($16) # 4 2 4 | ||
| 75 | addq $28,$0,$0 # 4 3 2 | ||
| 76 | blt $18,$43 | ||
| 77 | |||
| 78 | ldq $20,0($17) # 1 1 | ||
| 79 | ldq $1,0($16) # 1 1 | ||
| 80 | |||
| 81 | br $42 | ||
| 82 | |||
| 83 | .align 4 | ||
| 84 | $45: | ||
| 85 | ldq $20,0($17) # 4 1 | ||
| 86 | ldq $1,0($16) # 4 1 | ||
| 87 | mulq $20,$19,$5 # 4 2 1 | ||
| 88 | subq $18,1,$18 | ||
| 89 | addq $16,8,$16 | ||
| 90 | addq $17,8,$17 | ||
| 91 | umulh $20,$19,$20 # 4 2 | ||
| 92 | addq $1,$5,$1 # 4 2 2 | ||
| 93 | cmpult $1,$5,$22 # 4 2 3 1 | ||
| 94 | addq $20,$22,$20 # 4 3 1 | ||
| 95 | addq $1,$0,$1 # 4 2 3 1 | ||
| 96 | cmpult $1,$0,$0 # 4 2 3 2 | ||
| 97 | addq $20,$0,$0 # 4 3 2 | ||
| 98 | stq $1,-8($16) # 4 2 4 | ||
| 99 | bgt $18,$45 | ||
| 100 | ret $31,($26),1 # else exit | ||
| 101 | |||
| 102 | .align 4 | ||
| 103 | $43: | ||
| 104 | addq $18,4,$18 | ||
| 105 | bgt $18,$45 # goto tail code | ||
| 106 | ret $31,($26),1 # else exit | ||
| 107 | |||
| 108 | .end bn_mul_add_words | ||
| 109 | .align 3 | ||
| 110 | .globl bn_mul_words | ||
| 111 | .ent bn_mul_words | ||
| 112 | bn_mul_words: | ||
| 113 | bn_mul_words..ng: | ||
| 114 | .frame $30,0,$26,0 | ||
| 115 | .prologue 0 | ||
| 116 | .align 5 | ||
| 117 | subq $18,4,$18 | ||
| 118 | bis $31,$31,$0 | ||
| 119 | blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code | ||
| 120 | ldq $20,0($17) # 1 1 | ||
| 121 | .align 3 | ||
| 122 | $142: | ||
| 123 | |||
| 124 | mulq $20,$19,$5 # 1 2 1 ##### | ||
| 125 | ldq $21,8($17) # 2 1 | ||
| 126 | ldq $27,16($17) # 3 1 | ||
| 127 | umulh $20,$19,$20 # 1 2 ##### | ||
| 128 | ldq $28,24($17) # 4 1 | ||
| 129 | mulq $21,$19,$6 # 2 2 1 ##### | ||
| 130 | addq $5,$0,$5 # 1 2 3 1 | ||
| 131 | subq $18,4,$18 | ||
| 132 | cmpult $5,$0,$0 # 1 2 3 2 | ||
| 133 | umulh $21,$19,$21 # 2 2 ##### | ||
| 134 | addq $20,$0,$0 # 1 3 2 | ||
| 135 | addq $17,32,$17 | ||
| 136 | addq $6,$0,$6 # 2 2 3 1 | ||
| 137 | mulq $27,$19,$7 # 3 2 1 ##### | ||
| 138 | cmpult $6,$0,$0 # 2 2 3 2 | ||
| 139 | addq $21,$0,$0 # 2 3 2 | ||
| 140 | addq $16,32,$16 | ||
| 141 | umulh $27,$19,$27 # 3 2 ##### | ||
| 142 | stq $5,-32($16) # 1 2 4 | ||
| 143 | mulq $28,$19,$8 # 4 2 1 ##### | ||
| 144 | addq $7,$0,$7 # 3 2 3 1 | ||
| 145 | stq $6,-24($16) # 2 2 4 | ||
| 146 | cmpult $7,$0,$0 # 3 2 3 2 | ||
| 147 | umulh $28,$19,$28 # 4 2 ##### | ||
| 148 | addq $27,$0,$0 # 3 3 2 | ||
| 149 | stq $7,-16($16) # 3 2 4 | ||
| 150 | addq $8,$0,$8 # 4 2 3 1 | ||
| 151 | cmpult $8,$0,$0 # 4 2 3 2 | ||
| 152 | |||
| 153 | addq $28,$0,$0 # 4 3 2 | ||
| 154 | |||
| 155 | stq $8,-8($16) # 4 2 4 | ||
| 156 | |||
| 157 | blt $18,$143 | ||
| 158 | |||
| 159 | ldq $20,0($17) # 1 1 | ||
| 160 | |||
| 161 | br $142 | ||
| 162 | |||
| 163 | .align 4 | ||
| 164 | $145: | ||
| 165 | ldq $20,0($17) # 4 1 | ||
| 166 | mulq $20,$19,$5 # 4 2 1 | ||
| 167 | subq $18,1,$18 | ||
| 168 | umulh $20,$19,$20 # 4 2 | ||
| 169 | addq $5,$0,$5 # 4 2 3 1 | ||
| 170 | addq $16,8,$16 | ||
| 171 | cmpult $5,$0,$0 # 4 2 3 2 | ||
| 172 | addq $17,8,$17 | ||
| 173 | addq $20,$0,$0 # 4 3 2 | ||
| 174 | stq $5,-8($16) # 4 2 4 | ||
| 175 | |||
| 176 | bgt $18,$145 | ||
| 177 | ret $31,($26),1 # else exit | ||
| 178 | |||
| 179 | .align 4 | ||
| 180 | $143: | ||
| 181 | addq $18,4,$18 | ||
| 182 | bgt $18,$145 # goto tail code | ||
| 183 | ret $31,($26),1 # else exit | ||
| 184 | |||
| 185 | .end bn_mul_words | ||
| 186 | .align 3 | ||
| 187 | .globl bn_sqr_words | ||
| 188 | .ent bn_sqr_words | ||
| 189 | bn_sqr_words: | ||
| 190 | bn_sqr_words..ng: | ||
| 191 | .frame $30,0,$26,0 | ||
| 192 | .prologue 0 | ||
| 193 | |||
| 194 | subq $18,4,$18 | ||
| 195 | blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code | ||
| 196 | ldq $20,0($17) # 1 1 | ||
| 197 | .align 3 | ||
| 198 | $542: | ||
| 199 | mulq $20,$20,$5 ###### | ||
| 200 | ldq $21,8($17) # 1 1 | ||
| 201 | subq $18,4 | ||
| 202 | umulh $20,$20,$1 ###### | ||
| 203 | ldq $27,16($17) # 1 1 | ||
| 204 | mulq $21,$21,$6 ###### | ||
| 205 | ldq $28,24($17) # 1 1 | ||
| 206 | stq $5,0($16) # r[0] | ||
| 207 | umulh $21,$21,$2 ###### | ||
| 208 | stq $1,8($16) # r[1] | ||
| 209 | mulq $27,$27,$7 ###### | ||
| 210 | stq $6,16($16) # r[0] | ||
| 211 | umulh $27,$27,$3 ###### | ||
| 212 | stq $2,24($16) # r[1] | ||
| 213 | mulq $28,$28,$8 ###### | ||
| 214 | stq $7,32($16) # r[0] | ||
| 215 | umulh $28,$28,$4 ###### | ||
| 216 | stq $3,40($16) # r[1] | ||
| 217 | |||
| 218 | addq $16,64,$16 | ||
| 219 | addq $17,32,$17 | ||
| 220 | stq $8,-16($16) # r[0] | ||
| 221 | stq $4,-8($16) # r[1] | ||
| 222 | |||
| 223 | blt $18,$543 | ||
| 224 | ldq $20,0($17) # 1 1 | ||
| 225 | br $542 | ||
| 226 | |||
| 227 | $442: | ||
| 228 | ldq $20,0($17) # a[0] | ||
| 229 | mulq $20,$20,$5 # a[0]*w low part r2 | ||
| 230 | addq $16,16,$16 | ||
| 231 | addq $17,8,$17 | ||
| 232 | subq $18,1,$18 | ||
| 233 | umulh $20,$20,$1 # a[0]*w high part r3 | ||
| 234 | stq $5,-16($16) # r[0] | ||
| 235 | stq $1,-8($16) # r[1] | ||
| 236 | |||
| 237 | bgt $18,$442 | ||
| 238 | ret $31,($26),1 # else exit | ||
| 239 | |||
| 240 | .align 4 | ||
| 241 | $543: | ||
| 242 | addq $18,4,$18 | ||
| 243 | bgt $18,$442 # goto tail code | ||
| 244 | ret $31,($26),1 # else exit | ||
| 245 | .end bn_sqr_words | ||
| 246 | |||
| 247 | .align 3 | ||
| 248 | .globl bn_add_words | ||
| 249 | .ent bn_add_words | ||
| 250 | bn_add_words: | ||
| 251 | bn_add_words..ng: | ||
| 252 | .frame $30,0,$26,0 | ||
| 253 | .prologue 0 | ||
| 254 | |||
| 255 | subq $19,4,$19 | ||
| 256 | bis $31,$31,$0 # carry = 0 | ||
| 257 | blt $19,$900 | ||
| 258 | ldq $5,0($17) # a[0] | ||
| 259 | ldq $1,0($18) # b[1] | ||
| 260 | .align 3 | ||
| 261 | $901: | ||
| 262 | addq $1,$5,$1 # r=a+b; | ||
| 263 | ldq $6,8($17) # a[1] | ||
| 264 | cmpult $1,$5,$22 # did we overflow? | ||
| 265 | ldq $2,8($18) # b[1] | ||
| 266 | addq $1,$0,$1 # c+= overflow | ||
| 267 | ldq $7,16($17) # a[2] | ||
| 268 | cmpult $1,$0,$0 # overflow? | ||
| 269 | ldq $3,16($18) # b[2] | ||
| 270 | addq $0,$22,$0 | ||
| 271 | ldq $8,24($17) # a[3] | ||
| 272 | addq $2,$6,$2 # r=a+b; | ||
| 273 | ldq $4,24($18) # b[3] | ||
| 274 | cmpult $2,$6,$23 # did we overflow? | ||
| 275 | addq $3,$7,$3 # r=a+b; | ||
| 276 | addq $2,$0,$2 # c+= overflow | ||
| 277 | cmpult $3,$7,$24 # did we overflow? | ||
| 278 | cmpult $2,$0,$0 # overflow? | ||
| 279 | addq $4,$8,$4 # r=a+b; | ||
| 280 | addq $0,$23,$0 | ||
| 281 | cmpult $4,$8,$25 # did we overflow? | ||
| 282 | addq $3,$0,$3 # c+= overflow | ||
| 283 | stq $1,0($16) # r[0]=c | ||
| 284 | cmpult $3,$0,$0 # overflow? | ||
| 285 | stq $2,8($16) # r[1]=c | ||
| 286 | addq $0,$24,$0 | ||
| 287 | stq $3,16($16) # r[2]=c | ||
| 288 | addq $4,$0,$4 # c+= overflow | ||
| 289 | subq $19,4,$19 # loop-- | ||
| 290 | cmpult $4,$0,$0 # overflow? | ||
| 291 | addq $17,32,$17 # a++ | ||
| 292 | addq $0,$25,$0 | ||
| 293 | stq $4,24($16) # r[3]=c | ||
| 294 | addq $18,32,$18 # b++ | ||
| 295 | addq $16,32,$16 # r++ | ||
| 296 | |||
| 297 | blt $19,$900 | ||
| 298 | ldq $5,0($17) # a[0] | ||
| 299 | ldq $1,0($18) # b[1] | ||
| 300 | br $901 | ||
| 301 | .align 4 | ||
| 302 | $945: | ||
| 303 | ldq $5,0($17) # a[0] | ||
| 304 | ldq $1,0($18) # b[1] | ||
| 305 | addq $1,$5,$1 # r=a+b; | ||
| 306 | subq $19,1,$19 # loop-- | ||
| 307 | addq $1,$0,$1 # c+= overflow | ||
| 308 | addq $17,8,$17 # a++ | ||
| 309 | cmpult $1,$5,$22 # did we overflow? | ||
| 310 | cmpult $1,$0,$0 # overflow? | ||
| 311 | addq $18,8,$18 # b++ | ||
| 312 | stq $1,0($16) # r[0]=c | ||
| 313 | addq $0,$22,$0 | ||
| 314 | addq $16,8,$16 # r++ | ||
| 315 | |||
| 316 | bgt $19,$945 | ||
| 317 | ret $31,($26),1 # else exit | ||
| 318 | |||
| 319 | $900: | ||
| 320 | addq $19,4,$19 | ||
| 321 | bgt $19,$945 # goto tail code | ||
| 322 | ret $31,($26),1 # else exit | ||
| 323 | .end bn_add_words | ||
| 324 | |||
| 325 | # | ||
| 326 | # What follows was taken directly from the C compiler with a few | ||
| 327 | # hacks to redo the lables. | ||
| 328 | # | ||
| 329 | .text | ||
| 330 | .align 3 | ||
| 331 | .globl bn_div_words | ||
| 332 | .ent bn_div_words | ||
| 333 | bn_div_words: | ||
| 334 | ldgp $29,0($27) | ||
| 335 | bn_div_words..ng: | ||
| 336 | lda $30,-48($30) | ||
| 337 | .frame $30,48,$26,0 | ||
| 338 | stq $26,0($30) | ||
| 339 | stq $9,8($30) | ||
| 340 | stq $10,16($30) | ||
| 341 | stq $11,24($30) | ||
| 342 | stq $12,32($30) | ||
| 343 | stq $13,40($30) | ||
| 344 | .mask 0x4003e00,-48 | ||
| 345 | .prologue 1 | ||
| 346 | bis $16,$16,$9 | ||
| 347 | bis $17,$17,$10 | ||
| 348 | bis $18,$18,$11 | ||
| 349 | bis $31,$31,$13 | ||
| 350 | bis $31,2,$12 | ||
| 351 | bne $11,$119 | ||
| 352 | lda $0,-1 | ||
| 353 | br $31,$136 | ||
| 354 | .align 4 | ||
| 355 | $119: | ||
| 356 | bis $11,$11,$16 | ||
| 357 | jsr $26,BN_num_bits_word | ||
| 358 | ldgp $29,0($26) | ||
| 359 | subq $0,64,$1 | ||
| 360 | beq $1,$120 | ||
| 361 | bis $31,1,$1 | ||
| 362 | sll $1,$0,$1 | ||
| 363 | cmpule $9,$1,$1 | ||
| 364 | bne $1,$120 | ||
| 365 | # lda $16,_IO_stderr_ | ||
| 366 | # lda $17,$C32 | ||
| 367 | # bis $0,$0,$18 | ||
| 368 | # jsr $26,fprintf | ||
| 369 | # ldgp $29,0($26) | ||
| 370 | jsr $26,abort | ||
| 371 | ldgp $29,0($26) | ||
| 372 | .align 4 | ||
| 373 | $120: | ||
| 374 | bis $31,64,$3 | ||
| 375 | cmpult $9,$11,$2 | ||
| 376 | subq $3,$0,$1 | ||
| 377 | addl $1,$31,$0 | ||
| 378 | subq $9,$11,$1 | ||
| 379 | cmoveq $2,$1,$9 | ||
| 380 | beq $0,$122 | ||
| 381 | zapnot $0,15,$2 | ||
| 382 | subq $3,$0,$1 | ||
| 383 | sll $11,$2,$11 | ||
| 384 | sll $9,$2,$3 | ||
| 385 | srl $10,$1,$1 | ||
| 386 | sll $10,$2,$10 | ||
| 387 | bis $3,$1,$9 | ||
| 388 | $122: | ||
| 389 | srl $11,32,$5 | ||
| 390 | zapnot $11,15,$6 | ||
| 391 | lda $7,-1 | ||
| 392 | .align 5 | ||
| 393 | $123: | ||
| 394 | srl $9,32,$1 | ||
| 395 | subq $1,$5,$1 | ||
| 396 | bne $1,$126 | ||
| 397 | zapnot $7,15,$27 | ||
| 398 | br $31,$127 | ||
| 399 | .align 4 | ||
| 400 | $126: | ||
| 401 | bis $9,$9,$24 | ||
| 402 | bis $5,$5,$25 | ||
| 403 | divqu $24,$25,$27 | ||
| 404 | $127: | ||
| 405 | srl $10,32,$4 | ||
| 406 | .align 5 | ||
| 407 | $128: | ||
| 408 | mulq $27,$5,$1 | ||
| 409 | subq $9,$1,$3 | ||
| 410 | zapnot $3,240,$1 | ||
| 411 | bne $1,$129 | ||
| 412 | mulq $6,$27,$2 | ||
| 413 | sll $3,32,$1 | ||
| 414 | addq $1,$4,$1 | ||
| 415 | cmpule $2,$1,$2 | ||
| 416 | bne $2,$129 | ||
| 417 | subq $27,1,$27 | ||
| 418 | br $31,$128 | ||
| 419 | .align 4 | ||
| 420 | $129: | ||
| 421 | mulq $27,$6,$1 | ||
| 422 | mulq $27,$5,$4 | ||
| 423 | srl $1,32,$3 | ||
| 424 | sll $1,32,$1 | ||
| 425 | addq $4,$3,$4 | ||
| 426 | cmpult $10,$1,$2 | ||
| 427 | subq $10,$1,$10 | ||
| 428 | addq $2,$4,$2 | ||
| 429 | cmpult $9,$2,$1 | ||
| 430 | bis $2,$2,$4 | ||
| 431 | beq $1,$134 | ||
| 432 | addq $9,$11,$9 | ||
| 433 | subq $27,1,$27 | ||
| 434 | $134: | ||
| 435 | subl $12,1,$12 | ||
| 436 | subq $9,$4,$9 | ||
| 437 | beq $12,$124 | ||
| 438 | sll $27,32,$13 | ||
| 439 | sll $9,32,$2 | ||
| 440 | srl $10,32,$1 | ||
| 441 | sll $10,32,$10 | ||
| 442 | bis $2,$1,$9 | ||
| 443 | br $31,$123 | ||
| 444 | .align 4 | ||
| 445 | $124: | ||
| 446 | bis $13,$27,$0 | ||
| 447 | $136: | ||
| 448 | ldq $26,0($30) | ||
| 449 | ldq $9,8($30) | ||
| 450 | ldq $10,16($30) | ||
| 451 | ldq $11,24($30) | ||
| 452 | ldq $12,32($30) | ||
| 453 | ldq $13,40($30) | ||
| 454 | addq $30,48,$30 | ||
| 455 | ret $31,($26),1 | ||
| 456 | .end bn_div_words | ||
| 457 | |||
| 458 | .set noat | ||
| 459 | .text | ||
| 460 | .align 3 | ||
| 461 | .globl bn_sub_words | ||
| 462 | .ent bn_sub_words | ||
| 463 | bn_sub_words: | ||
| 464 | bn_sub_words..ng: | ||
| 465 | .frame $30,0,$26,0 | ||
| 466 | .prologue 0 | ||
| 467 | |||
| 468 | subq $19, 4, $19 | ||
| 469 | bis $31, $31, $0 | ||
| 470 | blt $19, $100 | ||
| 471 | ldq $1, 0($17) | ||
| 472 | ldq $2, 0($18) | ||
| 473 | $101: | ||
| 474 | ldq $3, 8($17) | ||
| 475 | cmpult $1, $2, $4 | ||
| 476 | ldq $5, 8($18) | ||
| 477 | subq $1, $2, $1 | ||
| 478 | ldq $6, 16($17) | ||
| 479 | cmpult $1, $0, $2 | ||
| 480 | ldq $7, 16($18) | ||
| 481 | subq $1, $0, $23 | ||
| 482 | ldq $8, 24($17) | ||
| 483 | addq $2, $4, $0 | ||
| 484 | cmpult $3, $5, $24 | ||
| 485 | subq $3, $5, $3 | ||
| 486 | ldq $22, 24($18) | ||
| 487 | cmpult $3, $0, $5 | ||
| 488 | subq $3, $0, $25 | ||
| 489 | addq $5, $24, $0 | ||
| 490 | cmpult $6, $7, $27 | ||
| 491 | subq $6, $7, $6 | ||
| 492 | stq $23, 0($16) | ||
| 493 | cmpult $6, $0, $7 | ||
| 494 | subq $6, $0, $28 | ||
| 495 | addq $7, $27, $0 | ||
| 496 | cmpult $8, $22, $21 | ||
| 497 | subq $8, $22, $8 | ||
| 498 | stq $25, 8($16) | ||
| 499 | cmpult $8, $0, $22 | ||
| 500 | subq $8, $0, $20 | ||
| 501 | addq $22, $21, $0 | ||
| 502 | stq $28, 16($16) | ||
| 503 | subq $19, 4, $19 | ||
| 504 | stq $20, 24($16) | ||
| 505 | addq $17, 32, $17 | ||
| 506 | addq $18, 32, $18 | ||
| 507 | addq $16, 32, $16 | ||
| 508 | blt $19, $100 | ||
| 509 | ldq $1, 0($17) | ||
| 510 | ldq $2, 0($18) | ||
| 511 | br $101 | ||
| 512 | $102: | ||
| 513 | ldq $1, 0($17) | ||
| 514 | ldq $2, 0($18) | ||
| 515 | cmpult $1, $2, $27 | ||
| 516 | subq $1, $2, $1 | ||
| 517 | cmpult $1, $0, $2 | ||
| 518 | subq $1, $0, $1 | ||
| 519 | stq $1, 0($16) | ||
| 520 | addq $2, $27, $0 | ||
| 521 | addq $17, 8, $17 | ||
| 522 | addq $18, 8, $18 | ||
| 523 | addq $16, 8, $16 | ||
| 524 | subq $19, 1, $19 | ||
| 525 | bgt $19, $102 | ||
| 526 | ret $31,($26),1 | ||
| 527 | $100: | ||
| 528 | addq $19, 4, $19 | ||
| 529 | bgt $19, $102 | ||
| 530 | $103: | ||
| 531 | ret $31,($26),1 | ||
| 532 | .end bn_sub_words | ||
| 533 | .text | ||
| 534 | .align 3 | ||
| 535 | .globl bn_mul_comba4 | ||
| 536 | .ent bn_mul_comba4 | ||
| 537 | bn_mul_comba4: | ||
| 538 | bn_mul_comba4..ng: | ||
| 539 | .frame $30,0,$26,0 | ||
| 540 | .prologue 0 | ||
| 541 | |||
| 542 | ldq $0, 0($17) | ||
| 543 | ldq $1, 0($18) | ||
| 544 | ldq $2, 8($17) | ||
| 545 | ldq $3, 8($18) | ||
| 546 | ldq $4, 16($17) | ||
| 547 | ldq $5, 16($18) | ||
| 548 | ldq $6, 24($17) | ||
| 549 | ldq $7, 24($18) | ||
| 550 | bis $31, $31, $23 | ||
| 551 | mulq $0, $1, $8 | ||
| 552 | umulh $0, $1, $22 | ||
| 553 | stq $8, 0($16) | ||
| 554 | bis $31, $31, $8 | ||
| 555 | mulq $0, $3, $24 | ||
| 556 | umulh $0, $3, $25 | ||
| 557 | addq $22, $24, $22 | ||
| 558 | cmpult $22, $24, $27 | ||
| 559 | addq $27, $25, $25 | ||
| 560 | addq $23, $25, $23 | ||
| 561 | cmpult $23, $25, $28 | ||
| 562 | addq $8, $28, $8 | ||
| 563 | mulq $2, $1, $21 | ||
| 564 | umulh $2, $1, $20 | ||
| 565 | addq $22, $21, $22 | ||
| 566 | cmpult $22, $21, $19 | ||
| 567 | addq $19, $20, $20 | ||
| 568 | addq $23, $20, $23 | ||
| 569 | cmpult $23, $20, $17 | ||
| 570 | addq $8, $17, $8 | ||
| 571 | stq $22, 8($16) | ||
| 572 | bis $31, $31, $22 | ||
| 573 | mulq $2, $3, $18 | ||
| 574 | umulh $2, $3, $24 | ||
| 575 | addq $23, $18, $23 | ||
| 576 | cmpult $23, $18, $27 | ||
| 577 | addq $27, $24, $24 | ||
| 578 | addq $8, $24, $8 | ||
| 579 | cmpult $8, $24, $25 | ||
| 580 | addq $22, $25, $22 | ||
| 581 | mulq $0, $5, $28 | ||
| 582 | umulh $0, $5, $21 | ||
| 583 | addq $23, $28, $23 | ||
| 584 | cmpult $23, $28, $19 | ||
| 585 | addq $19, $21, $21 | ||
| 586 | addq $8, $21, $8 | ||
| 587 | cmpult $8, $21, $20 | ||
| 588 | addq $22, $20, $22 | ||
| 589 | mulq $4, $1, $17 | ||
| 590 | umulh $4, $1, $18 | ||
| 591 | addq $23, $17, $23 | ||
| 592 | cmpult $23, $17, $27 | ||
| 593 | addq $27, $18, $18 | ||
| 594 | addq $8, $18, $8 | ||
| 595 | cmpult $8, $18, $24 | ||
| 596 | addq $22, $24, $22 | ||
| 597 | stq $23, 16($16) | ||
| 598 | bis $31, $31, $23 | ||
| 599 | mulq $0, $7, $25 | ||
| 600 | umulh $0, $7, $28 | ||
| 601 | addq $8, $25, $8 | ||
| 602 | cmpult $8, $25, $19 | ||
| 603 | addq $19, $28, $28 | ||
| 604 | addq $22, $28, $22 | ||
| 605 | cmpult $22, $28, $21 | ||
| 606 | addq $23, $21, $23 | ||
| 607 | mulq $2, $5, $20 | ||
| 608 | umulh $2, $5, $17 | ||
| 609 | addq $8, $20, $8 | ||
| 610 | cmpult $8, $20, $27 | ||
| 611 | addq $27, $17, $17 | ||
| 612 | addq $22, $17, $22 | ||
| 613 | cmpult $22, $17, $18 | ||
| 614 | addq $23, $18, $23 | ||
| 615 | mulq $4, $3, $24 | ||
| 616 | umulh $4, $3, $25 | ||
| 617 | addq $8, $24, $8 | ||
| 618 | cmpult $8, $24, $19 | ||
| 619 | addq $19, $25, $25 | ||
| 620 | addq $22, $25, $22 | ||
| 621 | cmpult $22, $25, $28 | ||
| 622 | addq $23, $28, $23 | ||
| 623 | mulq $6, $1, $21 | ||
| 624 | umulh $6, $1, $0 | ||
| 625 | addq $8, $21, $8 | ||
| 626 | cmpult $8, $21, $20 | ||
| 627 | addq $20, $0, $0 | ||
| 628 | addq $22, $0, $22 | ||
| 629 | cmpult $22, $0, $27 | ||
| 630 | addq $23, $27, $23 | ||
| 631 | stq $8, 24($16) | ||
| 632 | bis $31, $31, $8 | ||
| 633 | mulq $2, $7, $17 | ||
| 634 | umulh $2, $7, $18 | ||
| 635 | addq $22, $17, $22 | ||
| 636 | cmpult $22, $17, $24 | ||
| 637 | addq $24, $18, $18 | ||
| 638 | addq $23, $18, $23 | ||
| 639 | cmpult $23, $18, $19 | ||
| 640 | addq $8, $19, $8 | ||
| 641 | mulq $4, $5, $25 | ||
| 642 | umulh $4, $5, $28 | ||
| 643 | addq $22, $25, $22 | ||
| 644 | cmpult $22, $25, $21 | ||
| 645 | addq $21, $28, $28 | ||
| 646 | addq $23, $28, $23 | ||
| 647 | cmpult $23, $28, $20 | ||
| 648 | addq $8, $20, $8 | ||
| 649 | mulq $6, $3, $0 | ||
| 650 | umulh $6, $3, $27 | ||
| 651 | addq $22, $0, $22 | ||
| 652 | cmpult $22, $0, $1 | ||
| 653 | addq $1, $27, $27 | ||
| 654 | addq $23, $27, $23 | ||
| 655 | cmpult $23, $27, $17 | ||
| 656 | addq $8, $17, $8 | ||
| 657 | stq $22, 32($16) | ||
| 658 | bis $31, $31, $22 | ||
| 659 | mulq $4, $7, $24 | ||
| 660 | umulh $4, $7, $18 | ||
| 661 | addq $23, $24, $23 | ||
| 662 | cmpult $23, $24, $19 | ||
| 663 | addq $19, $18, $18 | ||
| 664 | addq $8, $18, $8 | ||
| 665 | cmpult $8, $18, $2 | ||
| 666 | addq $22, $2, $22 | ||
| 667 | mulq $6, $5, $25 | ||
| 668 | umulh $6, $5, $21 | ||
| 669 | addq $23, $25, $23 | ||
| 670 | cmpult $23, $25, $28 | ||
| 671 | addq $28, $21, $21 | ||
| 672 | addq $8, $21, $8 | ||
| 673 | cmpult $8, $21, $20 | ||
| 674 | addq $22, $20, $22 | ||
| 675 | stq $23, 40($16) | ||
| 676 | bis $31, $31, $23 | ||
| 677 | mulq $6, $7, $0 | ||
| 678 | umulh $6, $7, $1 | ||
| 679 | addq $8, $0, $8 | ||
| 680 | cmpult $8, $0, $27 | ||
| 681 | addq $27, $1, $1 | ||
| 682 | addq $22, $1, $22 | ||
| 683 | cmpult $22, $1, $17 | ||
| 684 | addq $23, $17, $23 | ||
| 685 | stq $8, 48($16) | ||
| 686 | stq $22, 56($16) | ||
| 687 | ret $31,($26),1 | ||
| 688 | .end bn_mul_comba4 | ||
| 689 | .text | ||
| 690 | .align 3 | ||
| 691 | .globl bn_mul_comba8 | ||
| 692 | .ent bn_mul_comba8 | ||
| 693 | bn_mul_comba8: | ||
| 694 | bn_mul_comba8..ng: | ||
| 695 | .frame $30,0,$26,0 | ||
| 696 | .prologue 0 | ||
| 697 | ldq $1, 0($17) | ||
| 698 | ldq $2, 0($18) | ||
| 699 | zapnot $1, 15, $7 | ||
| 700 | srl $2, 32, $8 | ||
| 701 | mulq $8, $7, $22 | ||
| 702 | srl $1, 32, $6 | ||
| 703 | zapnot $2, 15, $5 | ||
| 704 | mulq $5, $6, $4 | ||
| 705 | mulq $7, $5, $24 | ||
| 706 | addq $22, $4, $22 | ||
| 707 | cmpult $22, $4, $1 | ||
| 708 | mulq $6, $8, $3 | ||
| 709 | beq $1, $173 | ||
| 710 | bis $31, 1, $1 | ||
| 711 | sll $1, 32, $1 | ||
| 712 | addq $3, $1, $3 | ||
| 713 | $173: | ||
| 714 | sll $22, 32, $4 | ||
| 715 | addq $24, $4, $24 | ||
| 716 | stq $24, 0($16) | ||
| 717 | ldq $2, 0($17) | ||
| 718 | ldq $1, 8($18) | ||
| 719 | zapnot $2, 15, $7 | ||
| 720 | srl $1, 32, $8 | ||
| 721 | mulq $8, $7, $25 | ||
| 722 | zapnot $1, 15, $5 | ||
| 723 | mulq $7, $5, $0 | ||
| 724 | srl $2, 32, $6 | ||
| 725 | mulq $5, $6, $23 | ||
| 726 | mulq $6, $8, $6 | ||
| 727 | srl $22, 32, $1 | ||
| 728 | cmpult $24, $4, $2 | ||
| 729 | addq $3, $1, $3 | ||
| 730 | addq $2, $3, $22 | ||
| 731 | addq $25, $23, $25 | ||
| 732 | cmpult $25, $23, $1 | ||
| 733 | bis $31, 1, $2 | ||
| 734 | beq $1, $177 | ||
| 735 | sll $2, 32, $1 | ||
| 736 | addq $6, $1, $6 | ||
| 737 | $177: | ||
| 738 | sll $25, 32, $23 | ||
| 739 | ldq $1, 0($18) | ||
| 740 | addq $0, $23, $0 | ||
| 741 | bis $0, $0, $7 | ||
| 742 | ldq $3, 8($17) | ||
| 743 | addq $22, $7, $22 | ||
| 744 | srl $1, 32, $8 | ||
| 745 | cmpult $22, $7, $4 | ||
| 746 | zapnot $3, 15, $7 | ||
| 747 | mulq $8, $7, $28 | ||
| 748 | zapnot $1, 15, $5 | ||
| 749 | mulq $7, $5, $21 | ||
| 750 | srl $25, 32, $1 | ||
| 751 | cmpult $0, $23, $2 | ||
| 752 | addq $6, $1, $6 | ||
| 753 | addq $2, $6, $6 | ||
| 754 | addq $4, $6, $24 | ||
| 755 | srl $3, 32, $6 | ||
| 756 | mulq $5, $6, $2 | ||
| 757 | mulq $6, $8, $6 | ||
| 758 | addq $28, $2, $28 | ||
| 759 | cmpult $28, $2, $1 | ||
| 760 | bis $31, 1, $2 | ||
| 761 | beq $1, $181 | ||
| 762 | sll $2, 32, $1 | ||
| 763 | addq $6, $1, $6 | ||
| 764 | $181: | ||
| 765 | sll $28, 32, $2 | ||
| 766 | addq $21, $2, $21 | ||
| 767 | bis $21, $21, $7 | ||
| 768 | addq $22, $7, $22 | ||
| 769 | stq $22, 8($16) | ||
| 770 | ldq $3, 16($17) | ||
| 771 | ldq $1, 0($18) | ||
| 772 | cmpult $22, $7, $4 | ||
| 773 | zapnot $3, 15, $7 | ||
| 774 | srl $1, 32, $8 | ||
| 775 | mulq $8, $7, $22 | ||
| 776 | zapnot $1, 15, $5 | ||
| 777 | mulq $7, $5, $20 | ||
| 778 | srl $28, 32, $1 | ||
| 779 | cmpult $21, $2, $2 | ||
| 780 | addq $6, $1, $6 | ||
| 781 | addq $2, $6, $6 | ||
| 782 | addq $4, $6, $6 | ||
| 783 | addq $24, $6, $24 | ||
| 784 | cmpult $24, $6, $23 | ||
| 785 | srl $3, 32, $6 | ||
| 786 | mulq $5, $6, $2 | ||
| 787 | mulq $6, $8, $6 | ||
| 788 | addq $22, $2, $22 | ||
| 789 | cmpult $22, $2, $1 | ||
| 790 | bis $31, 1, $2 | ||
| 791 | beq $1, $185 | ||
| 792 | sll $2, 32, $1 | ||
| 793 | addq $6, $1, $6 | ||
| 794 | $185: | ||
| 795 | sll $22, 32, $2 | ||
| 796 | ldq $1, 8($18) | ||
| 797 | addq $20, $2, $20 | ||
| 798 | bis $20, $20, $7 | ||
| 799 | ldq $4, 8($17) | ||
| 800 | addq $24, $7, $24 | ||
| 801 | srl $1, 32, $8 | ||
| 802 | cmpult $24, $7, $3 | ||
| 803 | zapnot $4, 15, $7 | ||
| 804 | mulq $8, $7, $25 | ||
| 805 | zapnot $1, 15, $5 | ||
| 806 | mulq $7, $5, $0 | ||
| 807 | srl $22, 32, $1 | ||
| 808 | cmpult $20, $2, $2 | ||
| 809 | addq $6, $1, $6 | ||
| 810 | addq $2, $6, $6 | ||
| 811 | addq $3, $6, $6 | ||
| 812 | addq $23, $6, $23 | ||
| 813 | cmpult $23, $6, $22 | ||
| 814 | srl $4, 32, $6 | ||
| 815 | mulq $5, $6, $5 | ||
| 816 | bis $31, 1, $21 | ||
| 817 | addq $25, $5, $25 | ||
| 818 | cmpult $25, $5, $1 | ||
| 819 | mulq $6, $8, $6 | ||
| 820 | beq $1, $189 | ||
| 821 | sll $21, 32, $1 | ||
| 822 | addq $6, $1, $6 | ||
| 823 | $189: | ||
| 824 | sll $25, 32, $5 | ||
| 825 | ldq $2, 16($18) | ||
| 826 | addq $0, $5, $0 | ||
| 827 | bis $0, $0, $7 | ||
| 828 | ldq $4, 0($17) | ||
| 829 | addq $24, $7, $24 | ||
| 830 | srl $2, 32, $8 | ||
| 831 | cmpult $24, $7, $3 | ||
| 832 | zapnot $4, 15, $7 | ||
| 833 | mulq $8, $7, $28 | ||
| 834 | srl $25, 32, $1 | ||
| 835 | addq $6, $1, $6 | ||
| 836 | cmpult $0, $5, $1 | ||
| 837 | zapnot $2, 15, $5 | ||
| 838 | addq $1, $6, $6 | ||
| 839 | addq $3, $6, $6 | ||
| 840 | addq $23, $6, $23 | ||
| 841 | cmpult $23, $6, $1 | ||
| 842 | srl $4, 32, $6 | ||
| 843 | mulq $5, $6, $25 | ||
| 844 | mulq $7, $5, $2 | ||
| 845 | addq $1, $22, $22 | ||
| 846 | addq $28, $25, $28 | ||
| 847 | cmpult $28, $25, $1 | ||
| 848 | mulq $6, $8, $6 | ||
| 849 | beq $1, $193 | ||
| 850 | sll $21, 32, $1 | ||
| 851 | addq $6, $1, $6 | ||
| 852 | $193: | ||
| 853 | sll $28, 32, $25 | ||
| 854 | addq $2, $25, $2 | ||
| 855 | bis $2, $2, $7 | ||
| 856 | addq $24, $7, $24 | ||
| 857 | stq $24, 16($16) | ||
| 858 | ldq $4, 0($17) | ||
| 859 | ldq $5, 24($18) | ||
| 860 | cmpult $24, $7, $3 | ||
| 861 | zapnot $4, 15, $7 | ||
| 862 | srl $5, 32, $8 | ||
| 863 | mulq $8, $7, $0 | ||
| 864 | srl $28, 32, $1 | ||
| 865 | cmpult $2, $25, $2 | ||
| 866 | addq $6, $1, $6 | ||
| 867 | addq $2, $6, $6 | ||
| 868 | addq $3, $6, $6 | ||
| 869 | addq $23, $6, $23 | ||
| 870 | cmpult $23, $6, $1 | ||
| 871 | srl $4, 32, $6 | ||
| 872 | zapnot $5, 15, $5 | ||
| 873 | mulq $5, $6, $24 | ||
| 874 | mulq $7, $5, $2 | ||
| 875 | addq $1, $22, $22 | ||
| 876 | addq $0, $24, $0 | ||
| 877 | cmpult $0, $24, $1 | ||
| 878 | mulq $6, $8, $6 | ||
| 879 | beq $1, $197 | ||
| 880 | sll $21, 32, $1 | ||
| 881 | addq $6, $1, $6 | ||
| 882 | $197: | ||
| 883 | sll $0, 32, $24 | ||
| 884 | ldq $1, 16($18) | ||
| 885 | addq $2, $24, $2 | ||
| 886 | bis $2, $2, $7 | ||
| 887 | ldq $4, 8($17) | ||
| 888 | addq $23, $7, $23 | ||
| 889 | srl $1, 32, $8 | ||
| 890 | cmpult $23, $7, $3 | ||
| 891 | zapnot $4, 15, $7 | ||
| 892 | mulq $8, $7, $25 | ||
| 893 | zapnot $1, 15, $5 | ||
| 894 | mulq $7, $5, $21 | ||
| 895 | srl $0, 32, $1 | ||
| 896 | cmpult $2, $24, $2 | ||
| 897 | addq $6, $1, $6 | ||
| 898 | addq $2, $6, $6 | ||
| 899 | addq $3, $6, $6 | ||
| 900 | addq $22, $6, $22 | ||
| 901 | cmpult $22, $6, $24 | ||
| 902 | srl $4, 32, $6 | ||
| 903 | mulq $5, $6, $5 | ||
| 904 | bis $31, 1, $20 | ||
| 905 | addq $25, $5, $25 | ||
| 906 | cmpult $25, $5, $1 | ||
| 907 | mulq $6, $8, $6 | ||
| 908 | beq $1, $201 | ||
| 909 | sll $20, 32, $1 | ||
| 910 | addq $6, $1, $6 | ||
| 911 | $201: | ||
| 912 | sll $25, 32, $5 | ||
| 913 | ldq $2, 8($18) | ||
| 914 | addq $21, $5, $21 | ||
| 915 | bis $21, $21, $7 | ||
| 916 | ldq $4, 16($17) | ||
| 917 | addq $23, $7, $23 | ||
| 918 | srl $2, 32, $8 | ||
| 919 | cmpult $23, $7, $3 | ||
| 920 | zapnot $4, 15, $7 | ||
| 921 | mulq $8, $7, $28 | ||
| 922 | srl $25, 32, $1 | ||
| 923 | addq $6, $1, $6 | ||
| 924 | cmpult $21, $5, $1 | ||
| 925 | zapnot $2, 15, $5 | ||
| 926 | addq $1, $6, $6 | ||
| 927 | addq $3, $6, $6 | ||
| 928 | addq $22, $6, $22 | ||
| 929 | cmpult $22, $6, $1 | ||
| 930 | srl $4, 32, $6 | ||
| 931 | mulq $5, $6, $25 | ||
| 932 | mulq $7, $5, $5 | ||
| 933 | addq $1, $24, $24 | ||
| 934 | addq $28, $25, $28 | ||
| 935 | cmpult $28, $25, $1 | ||
| 936 | mulq $6, $8, $6 | ||
| 937 | beq $1, $205 | ||
| 938 | sll $20, 32, $1 | ||
| 939 | addq $6, $1, $6 | ||
| 940 | $205: | ||
| 941 | sll $28, 32, $25 | ||
| 942 | ldq $2, 0($18) | ||
| 943 | addq $5, $25, $5 | ||
| 944 | bis $5, $5, $7 | ||
| 945 | ldq $4, 24($17) | ||
| 946 | addq $23, $7, $23 | ||
| 947 | srl $2, 32, $8 | ||
| 948 | cmpult $23, $7, $3 | ||
| 949 | zapnot $4, 15, $7 | ||
| 950 | mulq $8, $7, $0 | ||
| 951 | srl $28, 32, $1 | ||
| 952 | addq $6, $1, $6 | ||
| 953 | cmpult $5, $25, $1 | ||
| 954 | zapnot $2, 15, $5 | ||
| 955 | addq $1, $6, $6 | ||
| 956 | addq $3, $6, $6 | ||
| 957 | addq $22, $6, $22 | ||
| 958 | cmpult $22, $6, $1 | ||
| 959 | srl $4, 32, $6 | ||
| 960 | mulq $5, $6, $25 | ||
| 961 | mulq $7, $5, $2 | ||
| 962 | addq $1, $24, $24 | ||
| 963 | addq $0, $25, $0 | ||
| 964 | cmpult $0, $25, $1 | ||
| 965 | mulq $6, $8, $6 | ||
| 966 | beq $1, $209 | ||
| 967 | sll $20, 32, $1 | ||
| 968 | addq $6, $1, $6 | ||
| 969 | $209: | ||
| 970 | sll $0, 32, $25 | ||
| 971 | addq $2, $25, $2 | ||
| 972 | bis $2, $2, $7 | ||
| 973 | addq $23, $7, $23 | ||
| 974 | stq $23, 24($16) | ||
| 975 | ldq $4, 32($17) | ||
| 976 | ldq $5, 0($18) | ||
| 977 | cmpult $23, $7, $3 | ||
| 978 | zapnot $4, 15, $7 | ||
| 979 | srl $5, 32, $8 | ||
| 980 | mulq $8, $7, $28 | ||
| 981 | srl $0, 32, $1 | ||
| 982 | cmpult $2, $25, $2 | ||
| 983 | addq $6, $1, $6 | ||
| 984 | addq $2, $6, $6 | ||
| 985 | addq $3, $6, $6 | ||
| 986 | addq $22, $6, $22 | ||
| 987 | cmpult $22, $6, $1 | ||
| 988 | srl $4, 32, $6 | ||
| 989 | zapnot $5, 15, $5 | ||
| 990 | mulq $5, $6, $23 | ||
| 991 | mulq $7, $5, $2 | ||
| 992 | addq $1, $24, $24 | ||
| 993 | addq $28, $23, $28 | ||
| 994 | cmpult $28, $23, $1 | ||
| 995 | mulq $6, $8, $6 | ||
| 996 | beq $1, $213 | ||
| 997 | sll $20, 32, $1 | ||
| 998 | addq $6, $1, $6 | ||
| 999 | $213: | ||
| 1000 | sll $28, 32, $23 | ||
| 1001 | ldq $1, 8($18) | ||
| 1002 | addq $2, $23, $2 | ||
| 1003 | bis $2, $2, $7 | ||
| 1004 | ldq $4, 24($17) | ||
| 1005 | addq $22, $7, $22 | ||
| 1006 | srl $1, 32, $8 | ||
| 1007 | cmpult $22, $7, $3 | ||
| 1008 | zapnot $4, 15, $7 | ||
| 1009 | mulq $8, $7, $25 | ||
| 1010 | zapnot $1, 15, $5 | ||
| 1011 | mulq $7, $5, $0 | ||
| 1012 | srl $28, 32, $1 | ||
| 1013 | cmpult $2, $23, $2 | ||
| 1014 | addq $6, $1, $6 | ||
| 1015 | addq $2, $6, $6 | ||
| 1016 | addq $3, $6, $6 | ||
| 1017 | addq $24, $6, $24 | ||
| 1018 | cmpult $24, $6, $23 | ||
| 1019 | srl $4, 32, $6 | ||
| 1020 | mulq $5, $6, $5 | ||
| 1021 | bis $31, 1, $21 | ||
| 1022 | addq $25, $5, $25 | ||
| 1023 | cmpult $25, $5, $1 | ||
| 1024 | mulq $6, $8, $6 | ||
| 1025 | beq $1, $217 | ||
| 1026 | sll $21, 32, $1 | ||
| 1027 | addq $6, $1, $6 | ||
| 1028 | $217: | ||
| 1029 | sll $25, 32, $5 | ||
| 1030 | ldq $2, 16($18) | ||
| 1031 | addq $0, $5, $0 | ||
| 1032 | bis $0, $0, $7 | ||
| 1033 | ldq $4, 16($17) | ||
| 1034 | addq $22, $7, $22 | ||
| 1035 | srl $2, 32, $8 | ||
| 1036 | cmpult $22, $7, $3 | ||
| 1037 | zapnot $4, 15, $7 | ||
| 1038 | mulq $8, $7, $28 | ||
| 1039 | srl $25, 32, $1 | ||
| 1040 | addq $6, $1, $6 | ||
| 1041 | cmpult $0, $5, $1 | ||
| 1042 | zapnot $2, 15, $5 | ||
| 1043 | addq $1, $6, $6 | ||
| 1044 | addq $3, $6, $6 | ||
| 1045 | addq $24, $6, $24 | ||
| 1046 | cmpult $24, $6, $1 | ||
| 1047 | srl $4, 32, $6 | ||
| 1048 | mulq $5, $6, $25 | ||
| 1049 | mulq $7, $5, $5 | ||
| 1050 | addq $1, $23, $23 | ||
| 1051 | addq $28, $25, $28 | ||
| 1052 | cmpult $28, $25, $1 | ||
| 1053 | mulq $6, $8, $6 | ||
| 1054 | beq $1, $221 | ||
| 1055 | sll $21, 32, $1 | ||
| 1056 | addq $6, $1, $6 | ||
| 1057 | $221: | ||
| 1058 | sll $28, 32, $25 | ||
| 1059 | ldq $2, 24($18) | ||
| 1060 | addq $5, $25, $5 | ||
| 1061 | bis $5, $5, $7 | ||
| 1062 | ldq $4, 8($17) | ||
| 1063 | addq $22, $7, $22 | ||
| 1064 | srl $2, 32, $8 | ||
| 1065 | cmpult $22, $7, $3 | ||
| 1066 | zapnot $4, 15, $7 | ||
| 1067 | mulq $8, $7, $0 | ||
| 1068 | srl $28, 32, $1 | ||
| 1069 | addq $6, $1, $6 | ||
| 1070 | cmpult $5, $25, $1 | ||
| 1071 | zapnot $2, 15, $5 | ||
| 1072 | addq $1, $6, $6 | ||
| 1073 | addq $3, $6, $6 | ||
| 1074 | addq $24, $6, $24 | ||
| 1075 | cmpult $24, $6, $1 | ||
| 1076 | srl $4, 32, $6 | ||
| 1077 | mulq $5, $6, $25 | ||
| 1078 | mulq $7, $5, $5 | ||
| 1079 | addq $1, $23, $23 | ||
| 1080 | addq $0, $25, $0 | ||
| 1081 | cmpult $0, $25, $1 | ||
| 1082 | mulq $6, $8, $6 | ||
| 1083 | beq $1, $225 | ||
| 1084 | sll $21, 32, $1 | ||
| 1085 | addq $6, $1, $6 | ||
| 1086 | $225: | ||
| 1087 | sll $0, 32, $25 | ||
| 1088 | ldq $2, 32($18) | ||
| 1089 | addq $5, $25, $5 | ||
| 1090 | bis $5, $5, $7 | ||
| 1091 | ldq $4, 0($17) | ||
| 1092 | addq $22, $7, $22 | ||
| 1093 | srl $2, 32, $8 | ||
| 1094 | cmpult $22, $7, $3 | ||
| 1095 | zapnot $4, 15, $7 | ||
| 1096 | mulq $8, $7, $28 | ||
| 1097 | srl $0, 32, $1 | ||
| 1098 | addq $6, $1, $6 | ||
| 1099 | cmpult $5, $25, $1 | ||
| 1100 | zapnot $2, 15, $5 | ||
| 1101 | addq $1, $6, $6 | ||
| 1102 | addq $3, $6, $6 | ||
| 1103 | addq $24, $6, $24 | ||
| 1104 | cmpult $24, $6, $1 | ||
| 1105 | srl $4, 32, $6 | ||
| 1106 | mulq $5, $6, $25 | ||
| 1107 | mulq $7, $5, $2 | ||
| 1108 | addq $1, $23, $23 | ||
| 1109 | addq $28, $25, $28 | ||
| 1110 | cmpult $28, $25, $1 | ||
| 1111 | mulq $6, $8, $6 | ||
| 1112 | beq $1, $229 | ||
| 1113 | sll $21, 32, $1 | ||
| 1114 | addq $6, $1, $6 | ||
| 1115 | $229: | ||
| 1116 | sll $28, 32, $25 | ||
| 1117 | addq $2, $25, $2 | ||
| 1118 | bis $2, $2, $7 | ||
| 1119 | addq $22, $7, $22 | ||
| 1120 | stq $22, 32($16) | ||
| 1121 | ldq $4, 0($17) | ||
| 1122 | ldq $5, 40($18) | ||
| 1123 | cmpult $22, $7, $3 | ||
| 1124 | zapnot $4, 15, $7 | ||
| 1125 | srl $5, 32, $8 | ||
| 1126 | mulq $8, $7, $0 | ||
| 1127 | srl $28, 32, $1 | ||
| 1128 | cmpult $2, $25, $2 | ||
| 1129 | addq $6, $1, $6 | ||
| 1130 | addq $2, $6, $6 | ||
| 1131 | addq $3, $6, $6 | ||
| 1132 | addq $24, $6, $24 | ||
| 1133 | cmpult $24, $6, $1 | ||
| 1134 | srl $4, 32, $6 | ||
| 1135 | zapnot $5, 15, $5 | ||
| 1136 | mulq $5, $6, $22 | ||
| 1137 | mulq $7, $5, $2 | ||
| 1138 | addq $1, $23, $23 | ||
| 1139 | addq $0, $22, $0 | ||
| 1140 | cmpult $0, $22, $1 | ||
| 1141 | mulq $6, $8, $6 | ||
| 1142 | beq $1, $233 | ||
| 1143 | sll $21, 32, $1 | ||
| 1144 | addq $6, $1, $6 | ||
| 1145 | $233: | ||
| 1146 | sll $0, 32, $22 | ||
| 1147 | ldq $1, 32($18) | ||
| 1148 | addq $2, $22, $2 | ||
| 1149 | bis $2, $2, $7 | ||
| 1150 | ldq $4, 8($17) | ||
| 1151 | addq $24, $7, $24 | ||
| 1152 | srl $1, 32, $8 | ||
| 1153 | cmpult $24, $7, $3 | ||
| 1154 | zapnot $4, 15, $7 | ||
| 1155 | mulq $8, $7, $25 | ||
| 1156 | zapnot $1, 15, $5 | ||
| 1157 | mulq $7, $5, $21 | ||
| 1158 | srl $0, 32, $1 | ||
| 1159 | cmpult $2, $22, $2 | ||
| 1160 | addq $6, $1, $6 | ||
| 1161 | addq $2, $6, $6 | ||
| 1162 | addq $3, $6, $6 | ||
| 1163 | addq $23, $6, $23 | ||
| 1164 | cmpult $23, $6, $22 | ||
| 1165 | srl $4, 32, $6 | ||
| 1166 | mulq $5, $6, $5 | ||
| 1167 | bis $31, 1, $20 | ||
| 1168 | addq $25, $5, $25 | ||
| 1169 | cmpult $25, $5, $1 | ||
| 1170 | mulq $6, $8, $6 | ||
| 1171 | beq $1, $237 | ||
| 1172 | sll $20, 32, $1 | ||
| 1173 | addq $6, $1, $6 | ||
| 1174 | $237: | ||
| 1175 | sll $25, 32, $5 | ||
| 1176 | ldq $2, 24($18) | ||
| 1177 | addq $21, $5, $21 | ||
| 1178 | bis $21, $21, $7 | ||
| 1179 | ldq $4, 16($17) | ||
| 1180 | addq $24, $7, $24 | ||
| 1181 | srl $2, 32, $8 | ||
| 1182 | cmpult $24, $7, $3 | ||
| 1183 | zapnot $4, 15, $7 | ||
| 1184 | mulq $8, $7, $28 | ||
| 1185 | srl $25, 32, $1 | ||
| 1186 | addq $6, $1, $6 | ||
| 1187 | cmpult $21, $5, $1 | ||
| 1188 | zapnot $2, 15, $5 | ||
| 1189 | addq $1, $6, $6 | ||
| 1190 | addq $3, $6, $6 | ||
| 1191 | addq $23, $6, $23 | ||
| 1192 | cmpult $23, $6, $1 | ||
| 1193 | srl $4, 32, $6 | ||
| 1194 | mulq $5, $6, $25 | ||
| 1195 | mulq $7, $5, $5 | ||
| 1196 | addq $1, $22, $22 | ||
| 1197 | addq $28, $25, $28 | ||
| 1198 | cmpult $28, $25, $1 | ||
| 1199 | mulq $6, $8, $6 | ||
| 1200 | beq $1, $241 | ||
| 1201 | sll $20, 32, $1 | ||
| 1202 | addq $6, $1, $6 | ||
| 1203 | $241: | ||
| 1204 | sll $28, 32, $25 | ||
| 1205 | ldq $2, 16($18) | ||
| 1206 | addq $5, $25, $5 | ||
| 1207 | bis $5, $5, $7 | ||
| 1208 | ldq $4, 24($17) | ||
| 1209 | addq $24, $7, $24 | ||
| 1210 | srl $2, 32, $8 | ||
| 1211 | cmpult $24, $7, $3 | ||
| 1212 | zapnot $4, 15, $7 | ||
| 1213 | mulq $8, $7, $0 | ||
| 1214 | srl $28, 32, $1 | ||
| 1215 | addq $6, $1, $6 | ||
| 1216 | cmpult $5, $25, $1 | ||
| 1217 | zapnot $2, 15, $5 | ||
| 1218 | addq $1, $6, $6 | ||
| 1219 | addq $3, $6, $6 | ||
| 1220 | addq $23, $6, $23 | ||
| 1221 | cmpult $23, $6, $1 | ||
| 1222 | srl $4, 32, $6 | ||
| 1223 | mulq $5, $6, $25 | ||
| 1224 | mulq $7, $5, $5 | ||
| 1225 | addq $1, $22, $22 | ||
| 1226 | addq $0, $25, $0 | ||
| 1227 | cmpult $0, $25, $1 | ||
| 1228 | mulq $6, $8, $6 | ||
| 1229 | beq $1, $245 | ||
| 1230 | sll $20, 32, $1 | ||
| 1231 | addq $6, $1, $6 | ||
| 1232 | $245: | ||
| 1233 | sll $0, 32, $25 | ||
| 1234 | ldq $2, 8($18) | ||
| 1235 | addq $5, $25, $5 | ||
| 1236 | bis $5, $5, $7 | ||
| 1237 | ldq $4, 32($17) | ||
| 1238 | addq $24, $7, $24 | ||
| 1239 | srl $2, 32, $8 | ||
| 1240 | cmpult $24, $7, $3 | ||
| 1241 | zapnot $4, 15, $7 | ||
| 1242 | mulq $8, $7, $28 | ||
| 1243 | srl $0, 32, $1 | ||
| 1244 | addq $6, $1, $6 | ||
| 1245 | cmpult $5, $25, $1 | ||
| 1246 | zapnot $2, 15, $5 | ||
| 1247 | addq $1, $6, $6 | ||
| 1248 | addq $3, $6, $6 | ||
| 1249 | addq $23, $6, $23 | ||
| 1250 | cmpult $23, $6, $1 | ||
| 1251 | srl $4, 32, $6 | ||
| 1252 | mulq $5, $6, $25 | ||
| 1253 | mulq $7, $5, $5 | ||
| 1254 | addq $1, $22, $22 | ||
| 1255 | addq $28, $25, $28 | ||
| 1256 | cmpult $28, $25, $1 | ||
| 1257 | mulq $6, $8, $6 | ||
| 1258 | beq $1, $249 | ||
| 1259 | sll $20, 32, $1 | ||
| 1260 | addq $6, $1, $6 | ||
| 1261 | $249: | ||
| 1262 | sll $28, 32, $25 | ||
| 1263 | ldq $2, 0($18) | ||
| 1264 | addq $5, $25, $5 | ||
| 1265 | bis $5, $5, $7 | ||
| 1266 | ldq $4, 40($17) | ||
| 1267 | addq $24, $7, $24 | ||
| 1268 | srl $2, 32, $8 | ||
| 1269 | cmpult $24, $7, $3 | ||
| 1270 | zapnot $4, 15, $7 | ||
| 1271 | mulq $8, $7, $0 | ||
| 1272 | srl $28, 32, $1 | ||
| 1273 | addq $6, $1, $6 | ||
| 1274 | cmpult $5, $25, $1 | ||
| 1275 | zapnot $2, 15, $5 | ||
| 1276 | addq $1, $6, $6 | ||
| 1277 | addq $3, $6, $6 | ||
| 1278 | addq $23, $6, $23 | ||
| 1279 | cmpult $23, $6, $1 | ||
| 1280 | srl $4, 32, $6 | ||
| 1281 | mulq $5, $6, $25 | ||
| 1282 | mulq $7, $5, $2 | ||
| 1283 | addq $1, $22, $22 | ||
| 1284 | addq $0, $25, $0 | ||
| 1285 | cmpult $0, $25, $1 | ||
| 1286 | mulq $6, $8, $6 | ||
| 1287 | beq $1, $253 | ||
| 1288 | sll $20, 32, $1 | ||
| 1289 | addq $6, $1, $6 | ||
| 1290 | $253: | ||
| 1291 | sll $0, 32, $25 | ||
| 1292 | addq $2, $25, $2 | ||
| 1293 | bis $2, $2, $7 | ||
| 1294 | addq $24, $7, $24 | ||
| 1295 | stq $24, 40($16) | ||
| 1296 | ldq $4, 48($17) | ||
| 1297 | ldq $5, 0($18) | ||
| 1298 | cmpult $24, $7, $3 | ||
| 1299 | zapnot $4, 15, $7 | ||
| 1300 | srl $5, 32, $8 | ||
| 1301 | mulq $8, $7, $28 | ||
| 1302 | srl $0, 32, $1 | ||
| 1303 | cmpult $2, $25, $2 | ||
| 1304 | addq $6, $1, $6 | ||
| 1305 | addq $2, $6, $6 | ||
| 1306 | addq $3, $6, $6 | ||
| 1307 | addq $23, $6, $23 | ||
| 1308 | cmpult $23, $6, $1 | ||
| 1309 | srl $4, 32, $6 | ||
| 1310 | zapnot $5, 15, $5 | ||
| 1311 | mulq $5, $6, $24 | ||
| 1312 | mulq $7, $5, $2 | ||
| 1313 | addq $1, $22, $22 | ||
| 1314 | addq $28, $24, $28 | ||
| 1315 | cmpult $28, $24, $1 | ||
| 1316 | mulq $6, $8, $6 | ||
| 1317 | beq $1, $257 | ||
| 1318 | sll $20, 32, $1 | ||
| 1319 | addq $6, $1, $6 | ||
| 1320 | $257: | ||
| 1321 | sll $28, 32, $24 | ||
| 1322 | ldq $1, 8($18) | ||
| 1323 | addq $2, $24, $2 | ||
| 1324 | bis $2, $2, $7 | ||
| 1325 | ldq $4, 40($17) | ||
| 1326 | addq $23, $7, $23 | ||
| 1327 | srl $1, 32, $8 | ||
| 1328 | cmpult $23, $7, $3 | ||
| 1329 | zapnot $4, 15, $7 | ||
| 1330 | mulq $8, $7, $25 | ||
| 1331 | zapnot $1, 15, $5 | ||
| 1332 | mulq $7, $5, $0 | ||
| 1333 | srl $28, 32, $1 | ||
| 1334 | cmpult $2, $24, $2 | ||
| 1335 | addq $6, $1, $6 | ||
| 1336 | addq $2, $6, $6 | ||
| 1337 | addq $3, $6, $6 | ||
| 1338 | addq $22, $6, $22 | ||
| 1339 | cmpult $22, $6, $24 | ||
| 1340 | srl $4, 32, $6 | ||
| 1341 | mulq $5, $6, $5 | ||
| 1342 | bis $31, 1, $21 | ||
| 1343 | addq $25, $5, $25 | ||
| 1344 | cmpult $25, $5, $1 | ||
| 1345 | mulq $6, $8, $6 | ||
| 1346 | beq $1, $261 | ||
| 1347 | sll $21, 32, $1 | ||
| 1348 | addq $6, $1, $6 | ||
| 1349 | $261: | ||
| 1350 | sll $25, 32, $5 | ||
| 1351 | ldq $2, 16($18) | ||
| 1352 | addq $0, $5, $0 | ||
| 1353 | bis $0, $0, $7 | ||
| 1354 | ldq $4, 32($17) | ||
| 1355 | addq $23, $7, $23 | ||
| 1356 | srl $2, 32, $8 | ||
| 1357 | cmpult $23, $7, $3 | ||
| 1358 | zapnot $4, 15, $7 | ||
| 1359 | mulq $8, $7, $28 | ||
| 1360 | srl $25, 32, $1 | ||
| 1361 | addq $6, $1, $6 | ||
| 1362 | cmpult $0, $5, $1 | ||
| 1363 | zapnot $2, 15, $5 | ||
| 1364 | addq $1, $6, $6 | ||
| 1365 | addq $3, $6, $6 | ||
| 1366 | addq $22, $6, $22 | ||
| 1367 | cmpult $22, $6, $1 | ||
| 1368 | srl $4, 32, $6 | ||
| 1369 | mulq $5, $6, $25 | ||
| 1370 | mulq $7, $5, $5 | ||
| 1371 | addq $1, $24, $24 | ||
| 1372 | addq $28, $25, $28 | ||
| 1373 | cmpult $28, $25, $1 | ||
| 1374 | mulq $6, $8, $6 | ||
| 1375 | beq $1, $265 | ||
| 1376 | sll $21, 32, $1 | ||
| 1377 | addq $6, $1, $6 | ||
| 1378 | $265: | ||
| 1379 | sll $28, 32, $25 | ||
| 1380 | ldq $2, 24($18) | ||
| 1381 | addq $5, $25, $5 | ||
| 1382 | bis $5, $5, $7 | ||
| 1383 | ldq $4, 24($17) | ||
| 1384 | addq $23, $7, $23 | ||
| 1385 | srl $2, 32, $8 | ||
| 1386 | cmpult $23, $7, $3 | ||
| 1387 | zapnot $4, 15, $7 | ||
| 1388 | mulq $8, $7, $0 | ||
| 1389 | srl $28, 32, $1 | ||
| 1390 | addq $6, $1, $6 | ||
| 1391 | cmpult $5, $25, $1 | ||
| 1392 | zapnot $2, 15, $5 | ||
| 1393 | addq $1, $6, $6 | ||
| 1394 | addq $3, $6, $6 | ||
| 1395 | addq $22, $6, $22 | ||
| 1396 | cmpult $22, $6, $1 | ||
| 1397 | srl $4, 32, $6 | ||
| 1398 | mulq $5, $6, $25 | ||
| 1399 | mulq $7, $5, $5 | ||
| 1400 | addq $1, $24, $24 | ||
| 1401 | addq $0, $25, $0 | ||
| 1402 | cmpult $0, $25, $1 | ||
| 1403 | mulq $6, $8, $6 | ||
| 1404 | beq $1, $269 | ||
| 1405 | sll $21, 32, $1 | ||
| 1406 | addq $6, $1, $6 | ||
| 1407 | $269: | ||
| 1408 | sll $0, 32, $25 | ||
| 1409 | ldq $2, 32($18) | ||
| 1410 | addq $5, $25, $5 | ||
| 1411 | bis $5, $5, $7 | ||
| 1412 | ldq $4, 16($17) | ||
| 1413 | addq $23, $7, $23 | ||
| 1414 | srl $2, 32, $8 | ||
| 1415 | cmpult $23, $7, $3 | ||
| 1416 | zapnot $4, 15, $7 | ||
| 1417 | mulq $8, $7, $28 | ||
| 1418 | srl $0, 32, $1 | ||
| 1419 | addq $6, $1, $6 | ||
| 1420 | cmpult $5, $25, $1 | ||
| 1421 | zapnot $2, 15, $5 | ||
| 1422 | addq $1, $6, $6 | ||
| 1423 | addq $3, $6, $6 | ||
| 1424 | addq $22, $6, $22 | ||
| 1425 | cmpult $22, $6, $1 | ||
| 1426 | srl $4, 32, $6 | ||
| 1427 | mulq $5, $6, $25 | ||
| 1428 | mulq $7, $5, $5 | ||
| 1429 | addq $1, $24, $24 | ||
| 1430 | addq $28, $25, $28 | ||
| 1431 | cmpult $28, $25, $1 | ||
| 1432 | mulq $6, $8, $6 | ||
| 1433 | beq $1, $273 | ||
| 1434 | sll $21, 32, $1 | ||
| 1435 | addq $6, $1, $6 | ||
| 1436 | $273: | ||
| 1437 | sll $28, 32, $25 | ||
| 1438 | ldq $2, 40($18) | ||
| 1439 | addq $5, $25, $5 | ||
| 1440 | bis $5, $5, $7 | ||
| 1441 | ldq $4, 8($17) | ||
| 1442 | addq $23, $7, $23 | ||
| 1443 | srl $2, 32, $8 | ||
| 1444 | cmpult $23, $7, $3 | ||
| 1445 | zapnot $4, 15, $7 | ||
| 1446 | mulq $8, $7, $0 | ||
| 1447 | srl $28, 32, $1 | ||
| 1448 | addq $6, $1, $6 | ||
| 1449 | cmpult $5, $25, $1 | ||
| 1450 | zapnot $2, 15, $5 | ||
| 1451 | addq $1, $6, $6 | ||
| 1452 | addq $3, $6, $6 | ||
| 1453 | addq $22, $6, $22 | ||
| 1454 | cmpult $22, $6, $1 | ||
| 1455 | srl $4, 32, $6 | ||
| 1456 | mulq $5, $6, $25 | ||
| 1457 | mulq $7, $5, $5 | ||
| 1458 | addq $1, $24, $24 | ||
| 1459 | addq $0, $25, $0 | ||
| 1460 | cmpult $0, $25, $1 | ||
| 1461 | mulq $6, $8, $6 | ||
| 1462 | beq $1, $277 | ||
| 1463 | sll $21, 32, $1 | ||
| 1464 | addq $6, $1, $6 | ||
| 1465 | $277: | ||
| 1466 | sll $0, 32, $25 | ||
| 1467 | ldq $2, 48($18) | ||
| 1468 | addq $5, $25, $5 | ||
| 1469 | bis $5, $5, $7 | ||
| 1470 | ldq $4, 0($17) | ||
| 1471 | addq $23, $7, $23 | ||
| 1472 | srl $2, 32, $8 | ||
| 1473 | cmpult $23, $7, $3 | ||
| 1474 | zapnot $4, 15, $7 | ||
| 1475 | mulq $8, $7, $28 | ||
| 1476 | srl $0, 32, $1 | ||
| 1477 | addq $6, $1, $6 | ||
| 1478 | cmpult $5, $25, $1 | ||
| 1479 | zapnot $2, 15, $5 | ||
| 1480 | addq $1, $6, $6 | ||
| 1481 | addq $3, $6, $6 | ||
| 1482 | addq $22, $6, $22 | ||
| 1483 | cmpult $22, $6, $1 | ||
| 1484 | srl $4, 32, $6 | ||
| 1485 | mulq $5, $6, $25 | ||
| 1486 | mulq $7, $5, $2 | ||
| 1487 | addq $1, $24, $24 | ||
| 1488 | addq $28, $25, $28 | ||
| 1489 | cmpult $28, $25, $1 | ||
| 1490 | mulq $6, $8, $6 | ||
| 1491 | beq $1, $281 | ||
| 1492 | sll $21, 32, $1 | ||
| 1493 | addq $6, $1, $6 | ||
| 1494 | $281: | ||
| 1495 | sll $28, 32, $25 | ||
| 1496 | addq $2, $25, $2 | ||
| 1497 | bis $2, $2, $7 | ||
| 1498 | addq $23, $7, $23 | ||
| 1499 | stq $23, 48($16) | ||
| 1500 | ldq $4, 0($17) | ||
| 1501 | ldq $5, 56($18) | ||
| 1502 | cmpult $23, $7, $3 | ||
| 1503 | zapnot $4, 15, $7 | ||
| 1504 | srl $5, 32, $8 | ||
| 1505 | mulq $8, $7, $0 | ||
| 1506 | srl $28, 32, $1 | ||
| 1507 | cmpult $2, $25, $2 | ||
| 1508 | addq $6, $1, $6 | ||
| 1509 | addq $2, $6, $6 | ||
| 1510 | addq $3, $6, $6 | ||
| 1511 | addq $22, $6, $22 | ||
| 1512 | cmpult $22, $6, $1 | ||
| 1513 | srl $4, 32, $6 | ||
| 1514 | zapnot $5, 15, $5 | ||
| 1515 | mulq $5, $6, $23 | ||
| 1516 | mulq $7, $5, $2 | ||
| 1517 | addq $1, $24, $24 | ||
| 1518 | addq $0, $23, $0 | ||
| 1519 | cmpult $0, $23, $1 | ||
| 1520 | mulq $6, $8, $6 | ||
| 1521 | beq $1, $285 | ||
| 1522 | sll $21, 32, $1 | ||
| 1523 | addq $6, $1, $6 | ||
| 1524 | $285: | ||
| 1525 | sll $0, 32, $23 | ||
| 1526 | ldq $1, 48($18) | ||
| 1527 | addq $2, $23, $2 | ||
| 1528 | bis $2, $2, $7 | ||
| 1529 | ldq $4, 8($17) | ||
| 1530 | addq $22, $7, $22 | ||
| 1531 | srl $1, 32, $8 | ||
| 1532 | cmpult $22, $7, $3 | ||
| 1533 | zapnot $4, 15, $7 | ||
| 1534 | mulq $8, $7, $25 | ||
| 1535 | zapnot $1, 15, $5 | ||
| 1536 | mulq $7, $5, $21 | ||
| 1537 | srl $0, 32, $1 | ||
| 1538 | cmpult $2, $23, $2 | ||
| 1539 | addq $6, $1, $6 | ||
| 1540 | addq $2, $6, $6 | ||
| 1541 | addq $3, $6, $6 | ||
| 1542 | addq $24, $6, $24 | ||
| 1543 | cmpult $24, $6, $23 | ||
| 1544 | srl $4, 32, $6 | ||
| 1545 | mulq $5, $6, $5 | ||
| 1546 | bis $31, 1, $20 | ||
| 1547 | addq $25, $5, $25 | ||
| 1548 | cmpult $25, $5, $1 | ||
| 1549 | mulq $6, $8, $6 | ||
| 1550 | beq $1, $289 | ||
| 1551 | sll $20, 32, $1 | ||
| 1552 | addq $6, $1, $6 | ||
| 1553 | $289: | ||
| 1554 | sll $25, 32, $5 | ||
| 1555 | ldq $2, 40($18) | ||
| 1556 | addq $21, $5, $21 | ||
| 1557 | bis $21, $21, $7 | ||
| 1558 | ldq $4, 16($17) | ||
| 1559 | addq $22, $7, $22 | ||
| 1560 | srl $2, 32, $8 | ||
| 1561 | cmpult $22, $7, $3 | ||
| 1562 | zapnot $4, 15, $7 | ||
| 1563 | mulq $8, $7, $28 | ||
| 1564 | srl $25, 32, $1 | ||
| 1565 | addq $6, $1, $6 | ||
| 1566 | cmpult $21, $5, $1 | ||
| 1567 | zapnot $2, 15, $5 | ||
| 1568 | addq $1, $6, $6 | ||
| 1569 | addq $3, $6, $6 | ||
| 1570 | addq $24, $6, $24 | ||
| 1571 | cmpult $24, $6, $1 | ||
| 1572 | srl $4, 32, $6 | ||
| 1573 | mulq $5, $6, $25 | ||
| 1574 | mulq $7, $5, $5 | ||
| 1575 | addq $1, $23, $23 | ||
| 1576 | addq $28, $25, $28 | ||
| 1577 | cmpult $28, $25, $1 | ||
| 1578 | mulq $6, $8, $6 | ||
| 1579 | beq $1, $293 | ||
| 1580 | sll $20, 32, $1 | ||
| 1581 | addq $6, $1, $6 | ||
| 1582 | $293: | ||
| 1583 | sll $28, 32, $25 | ||
| 1584 | ldq $2, 32($18) | ||
| 1585 | addq $5, $25, $5 | ||
| 1586 | bis $5, $5, $7 | ||
| 1587 | ldq $4, 24($17) | ||
| 1588 | addq $22, $7, $22 | ||
| 1589 | srl $2, 32, $8 | ||
| 1590 | cmpult $22, $7, $3 | ||
| 1591 | zapnot $4, 15, $7 | ||
| 1592 | mulq $8, $7, $0 | ||
| 1593 | srl $28, 32, $1 | ||
| 1594 | addq $6, $1, $6 | ||
| 1595 | cmpult $5, $25, $1 | ||
| 1596 | zapnot $2, 15, $5 | ||
| 1597 | addq $1, $6, $6 | ||
| 1598 | addq $3, $6, $6 | ||
| 1599 | addq $24, $6, $24 | ||
| 1600 | cmpult $24, $6, $1 | ||
| 1601 | srl $4, 32, $6 | ||
| 1602 | mulq $5, $6, $25 | ||
| 1603 | mulq $7, $5, $5 | ||
| 1604 | addq $1, $23, $23 | ||
| 1605 | addq $0, $25, $0 | ||
| 1606 | cmpult $0, $25, $1 | ||
| 1607 | mulq $6, $8, $6 | ||
| 1608 | beq $1, $297 | ||
| 1609 | sll $20, 32, $1 | ||
| 1610 | addq $6, $1, $6 | ||
| 1611 | $297: | ||
| 1612 | sll $0, 32, $25 | ||
| 1613 | ldq $2, 24($18) | ||
| 1614 | addq $5, $25, $5 | ||
| 1615 | bis $5, $5, $7 | ||
| 1616 | ldq $4, 32($17) | ||
| 1617 | addq $22, $7, $22 | ||
| 1618 | srl $2, 32, $8 | ||
| 1619 | cmpult $22, $7, $3 | ||
| 1620 | zapnot $4, 15, $7 | ||
| 1621 | mulq $8, $7, $28 | ||
| 1622 | srl $0, 32, $1 | ||
| 1623 | addq $6, $1, $6 | ||
| 1624 | cmpult $5, $25, $1 | ||
| 1625 | zapnot $2, 15, $5 | ||
| 1626 | addq $1, $6, $6 | ||
| 1627 | addq $3, $6, $6 | ||
| 1628 | addq $24, $6, $24 | ||
| 1629 | cmpult $24, $6, $1 | ||
| 1630 | srl $4, 32, $6 | ||
| 1631 | mulq $5, $6, $25 | ||
| 1632 | mulq $7, $5, $5 | ||
| 1633 | addq $1, $23, $23 | ||
| 1634 | addq $28, $25, $28 | ||
| 1635 | cmpult $28, $25, $1 | ||
| 1636 | mulq $6, $8, $6 | ||
| 1637 | beq $1, $301 | ||
| 1638 | sll $20, 32, $1 | ||
| 1639 | addq $6, $1, $6 | ||
| 1640 | $301: | ||
| 1641 | sll $28, 32, $25 | ||
| 1642 | ldq $2, 16($18) | ||
| 1643 | addq $5, $25, $5 | ||
| 1644 | bis $5, $5, $7 | ||
| 1645 | ldq $4, 40($17) | ||
| 1646 | addq $22, $7, $22 | ||
| 1647 | srl $2, 32, $8 | ||
| 1648 | cmpult $22, $7, $3 | ||
| 1649 | zapnot $4, 15, $7 | ||
| 1650 | mulq $8, $7, $0 | ||
| 1651 | srl $28, 32, $1 | ||
| 1652 | addq $6, $1, $6 | ||
| 1653 | cmpult $5, $25, $1 | ||
| 1654 | zapnot $2, 15, $5 | ||
| 1655 | addq $1, $6, $6 | ||
| 1656 | addq $3, $6, $6 | ||
| 1657 | addq $24, $6, $24 | ||
| 1658 | cmpult $24, $6, $1 | ||
| 1659 | srl $4, 32, $6 | ||
| 1660 | mulq $5, $6, $25 | ||
| 1661 | mulq $7, $5, $5 | ||
| 1662 | addq $1, $23, $23 | ||
| 1663 | addq $0, $25, $0 | ||
| 1664 | cmpult $0, $25, $1 | ||
| 1665 | mulq $6, $8, $6 | ||
| 1666 | beq $1, $305 | ||
| 1667 | sll $20, 32, $1 | ||
| 1668 | addq $6, $1, $6 | ||
| 1669 | $305: | ||
| 1670 | sll $0, 32, $25 | ||
| 1671 | ldq $2, 8($18) | ||
| 1672 | addq $5, $25, $5 | ||
| 1673 | bis $5, $5, $7 | ||
| 1674 | ldq $4, 48($17) | ||
| 1675 | addq $22, $7, $22 | ||
| 1676 | srl $2, 32, $8 | ||
| 1677 | cmpult $22, $7, $3 | ||
| 1678 | zapnot $4, 15, $7 | ||
| 1679 | mulq $8, $7, $28 | ||
| 1680 | srl $0, 32, $1 | ||
| 1681 | addq $6, $1, $6 | ||
| 1682 | cmpult $5, $25, $1 | ||
| 1683 | zapnot $2, 15, $5 | ||
| 1684 | addq $1, $6, $6 | ||
| 1685 | addq $3, $6, $6 | ||
| 1686 | addq $24, $6, $24 | ||
| 1687 | cmpult $24, $6, $1 | ||
| 1688 | srl $4, 32, $6 | ||
| 1689 | mulq $5, $6, $25 | ||
| 1690 | mulq $7, $5, $5 | ||
| 1691 | addq $1, $23, $23 | ||
| 1692 | addq $28, $25, $28 | ||
| 1693 | cmpult $28, $25, $1 | ||
| 1694 | mulq $6, $8, $6 | ||
| 1695 | beq $1, $309 | ||
| 1696 | sll $20, 32, $1 | ||
| 1697 | addq $6, $1, $6 | ||
| 1698 | $309: | ||
| 1699 | sll $28, 32, $25 | ||
| 1700 | ldq $2, 0($18) | ||
| 1701 | addq $5, $25, $5 | ||
| 1702 | bis $5, $5, $7 | ||
| 1703 | ldq $4, 56($17) | ||
| 1704 | addq $22, $7, $22 | ||
| 1705 | srl $2, 32, $8 | ||
| 1706 | cmpult $22, $7, $3 | ||
| 1707 | zapnot $4, 15, $7 | ||
| 1708 | mulq $8, $7, $0 | ||
| 1709 | srl $28, 32, $1 | ||
| 1710 | addq $6, $1, $6 | ||
| 1711 | cmpult $5, $25, $1 | ||
| 1712 | zapnot $2, 15, $5 | ||
| 1713 | addq $1, $6, $6 | ||
| 1714 | addq $3, $6, $6 | ||
| 1715 | addq $24, $6, $24 | ||
| 1716 | cmpult $24, $6, $1 | ||
| 1717 | srl $4, 32, $6 | ||
| 1718 | mulq $5, $6, $25 | ||
| 1719 | mulq $7, $5, $2 | ||
| 1720 | addq $1, $23, $23 | ||
| 1721 | addq $0, $25, $0 | ||
| 1722 | cmpult $0, $25, $1 | ||
| 1723 | mulq $6, $8, $6 | ||
| 1724 | beq $1, $313 | ||
| 1725 | sll $20, 32, $1 | ||
| 1726 | addq $6, $1, $6 | ||
| 1727 | $313: | ||
| 1728 | sll $0, 32, $25 | ||
| 1729 | addq $2, $25, $2 | ||
| 1730 | bis $2, $2, $7 | ||
| 1731 | addq $22, $7, $22 | ||
| 1732 | stq $22, 56($16) | ||
| 1733 | ldq $4, 56($17) | ||
| 1734 | ldq $5, 8($18) | ||
| 1735 | cmpult $22, $7, $3 | ||
| 1736 | zapnot $4, 15, $7 | ||
| 1737 | srl $5, 32, $8 | ||
| 1738 | mulq $8, $7, $28 | ||
| 1739 | srl $0, 32, $1 | ||
| 1740 | cmpult $2, $25, $2 | ||
| 1741 | addq $6, $1, $6 | ||
| 1742 | addq $2, $6, $6 | ||
| 1743 | addq $3, $6, $6 | ||
| 1744 | addq $24, $6, $24 | ||
| 1745 | cmpult $24, $6, $1 | ||
| 1746 | srl $4, 32, $6 | ||
| 1747 | zapnot $5, 15, $5 | ||
| 1748 | mulq $5, $6, $22 | ||
| 1749 | mulq $7, $5, $2 | ||
| 1750 | addq $1, $23, $23 | ||
| 1751 | addq $28, $22, $28 | ||
| 1752 | cmpult $28, $22, $1 | ||
| 1753 | mulq $6, $8, $6 | ||
| 1754 | beq $1, $317 | ||
| 1755 | sll $20, 32, $1 | ||
| 1756 | addq $6, $1, $6 | ||
| 1757 | $317: | ||
| 1758 | sll $28, 32, $22 | ||
| 1759 | ldq $1, 16($18) | ||
| 1760 | addq $2, $22, $2 | ||
| 1761 | bis $2, $2, $7 | ||
| 1762 | ldq $4, 48($17) | ||
| 1763 | addq $24, $7, $24 | ||
| 1764 | srl $1, 32, $8 | ||
| 1765 | cmpult $24, $7, $3 | ||
| 1766 | zapnot $4, 15, $7 | ||
| 1767 | mulq $8, $7, $25 | ||
| 1768 | zapnot $1, 15, $5 | ||
| 1769 | mulq $7, $5, $0 | ||
| 1770 | srl $28, 32, $1 | ||
| 1771 | cmpult $2, $22, $2 | ||
| 1772 | addq $6, $1, $6 | ||
| 1773 | addq $2, $6, $6 | ||
| 1774 | addq $3, $6, $6 | ||
| 1775 | addq $23, $6, $23 | ||
| 1776 | cmpult $23, $6, $22 | ||
| 1777 | srl $4, 32, $6 | ||
| 1778 | mulq $5, $6, $5 | ||
| 1779 | bis $31, 1, $21 | ||
| 1780 | addq $25, $5, $25 | ||
| 1781 | cmpult $25, $5, $1 | ||
| 1782 | mulq $6, $8, $6 | ||
| 1783 | beq $1, $321 | ||
| 1784 | sll $21, 32, $1 | ||
| 1785 | addq $6, $1, $6 | ||
| 1786 | $321: | ||
| 1787 | sll $25, 32, $5 | ||
| 1788 | ldq $2, 24($18) | ||
| 1789 | addq $0, $5, $0 | ||
| 1790 | bis $0, $0, $7 | ||
| 1791 | ldq $4, 40($17) | ||
| 1792 | addq $24, $7, $24 | ||
| 1793 | srl $2, 32, $8 | ||
| 1794 | cmpult $24, $7, $3 | ||
| 1795 | zapnot $4, 15, $7 | ||
| 1796 | mulq $8, $7, $28 | ||
| 1797 | srl $25, 32, $1 | ||
| 1798 | addq $6, $1, $6 | ||
| 1799 | cmpult $0, $5, $1 | ||
| 1800 | zapnot $2, 15, $5 | ||
| 1801 | addq $1, $6, $6 | ||
| 1802 | addq $3, $6, $6 | ||
| 1803 | addq $23, $6, $23 | ||
| 1804 | cmpult $23, $6, $1 | ||
| 1805 | srl $4, 32, $6 | ||
| 1806 | mulq $5, $6, $25 | ||
| 1807 | mulq $7, $5, $5 | ||
| 1808 | addq $1, $22, $22 | ||
| 1809 | addq $28, $25, $28 | ||
| 1810 | cmpult $28, $25, $1 | ||
| 1811 | mulq $6, $8, $6 | ||
| 1812 | beq $1, $325 | ||
| 1813 | sll $21, 32, $1 | ||
| 1814 | addq $6, $1, $6 | ||
| 1815 | $325: | ||
| 1816 | sll $28, 32, $25 | ||
| 1817 | ldq $2, 32($18) | ||
| 1818 | addq $5, $25, $5 | ||
| 1819 | bis $5, $5, $7 | ||
| 1820 | ldq $4, 32($17) | ||
| 1821 | addq $24, $7, $24 | ||
| 1822 | srl $2, 32, $8 | ||
| 1823 | cmpult $24, $7, $3 | ||
| 1824 | zapnot $4, 15, $7 | ||
| 1825 | mulq $8, $7, $0 | ||
| 1826 | srl $28, 32, $1 | ||
| 1827 | addq $6, $1, $6 | ||
| 1828 | cmpult $5, $25, $1 | ||
| 1829 | zapnot $2, 15, $5 | ||
| 1830 | addq $1, $6, $6 | ||
| 1831 | addq $3, $6, $6 | ||
| 1832 | addq $23, $6, $23 | ||
| 1833 | cmpult $23, $6, $1 | ||
| 1834 | srl $4, 32, $6 | ||
| 1835 | mulq $5, $6, $25 | ||
| 1836 | mulq $7, $5, $5 | ||
| 1837 | addq $1, $22, $22 | ||
| 1838 | addq $0, $25, $0 | ||
| 1839 | cmpult $0, $25, $1 | ||
| 1840 | mulq $6, $8, $6 | ||
| 1841 | beq $1, $329 | ||
| 1842 | sll $21, 32, $1 | ||
| 1843 | addq $6, $1, $6 | ||
| 1844 | $329: | ||
| 1845 | sll $0, 32, $25 | ||
| 1846 | ldq $2, 40($18) | ||
| 1847 | addq $5, $25, $5 | ||
| 1848 | bis $5, $5, $7 | ||
| 1849 | ldq $4, 24($17) | ||
| 1850 | addq $24, $7, $24 | ||
| 1851 | srl $2, 32, $8 | ||
| 1852 | cmpult $24, $7, $3 | ||
| 1853 | zapnot $4, 15, $7 | ||
| 1854 | mulq $8, $7, $28 | ||
| 1855 | srl $0, 32, $1 | ||
| 1856 | addq $6, $1, $6 | ||
| 1857 | cmpult $5, $25, $1 | ||
| 1858 | zapnot $2, 15, $5 | ||
| 1859 | addq $1, $6, $6 | ||
| 1860 | addq $3, $6, $6 | ||
| 1861 | addq $23, $6, $23 | ||
| 1862 | cmpult $23, $6, $1 | ||
| 1863 | srl $4, 32, $6 | ||
| 1864 | mulq $5, $6, $25 | ||
| 1865 | mulq $7, $5, $5 | ||
| 1866 | addq $1, $22, $22 | ||
| 1867 | addq $28, $25, $28 | ||
| 1868 | cmpult $28, $25, $1 | ||
| 1869 | mulq $6, $8, $6 | ||
| 1870 | beq $1, $333 | ||
| 1871 | sll $21, 32, $1 | ||
| 1872 | addq $6, $1, $6 | ||
| 1873 | $333: | ||
| 1874 | sll $28, 32, $25 | ||
| 1875 | ldq $2, 48($18) | ||
| 1876 | addq $5, $25, $5 | ||
| 1877 | bis $5, $5, $7 | ||
| 1878 | ldq $4, 16($17) | ||
| 1879 | addq $24, $7, $24 | ||
| 1880 | srl $2, 32, $8 | ||
| 1881 | cmpult $24, $7, $3 | ||
| 1882 | zapnot $4, 15, $7 | ||
| 1883 | mulq $8, $7, $0 | ||
| 1884 | srl $28, 32, $1 | ||
| 1885 | addq $6, $1, $6 | ||
| 1886 | cmpult $5, $25, $1 | ||
| 1887 | zapnot $2, 15, $5 | ||
| 1888 | addq $1, $6, $6 | ||
| 1889 | addq $3, $6, $6 | ||
| 1890 | addq $23, $6, $23 | ||
| 1891 | cmpult $23, $6, $1 | ||
| 1892 | srl $4, 32, $6 | ||
| 1893 | mulq $5, $6, $25 | ||
| 1894 | mulq $7, $5, $5 | ||
| 1895 | addq $1, $22, $22 | ||
| 1896 | addq $0, $25, $0 | ||
| 1897 | cmpult $0, $25, $1 | ||
| 1898 | mulq $6, $8, $6 | ||
| 1899 | beq $1, $337 | ||
| 1900 | sll $21, 32, $1 | ||
| 1901 | addq $6, $1, $6 | ||
| 1902 | $337: | ||
| 1903 | sll $0, 32, $25 | ||
| 1904 | ldq $2, 56($18) | ||
| 1905 | addq $5, $25, $5 | ||
| 1906 | bis $5, $5, $7 | ||
| 1907 | ldq $4, 8($17) | ||
| 1908 | addq $24, $7, $24 | ||
| 1909 | srl $2, 32, $8 | ||
| 1910 | cmpult $24, $7, $3 | ||
| 1911 | zapnot $4, 15, $7 | ||
| 1912 | mulq $8, $7, $28 | ||
| 1913 | srl $0, 32, $1 | ||
| 1914 | addq $6, $1, $6 | ||
| 1915 | cmpult $5, $25, $1 | ||
| 1916 | zapnot $2, 15, $5 | ||
| 1917 | addq $1, $6, $6 | ||
| 1918 | addq $3, $6, $6 | ||
| 1919 | addq $23, $6, $23 | ||
| 1920 | cmpult $23, $6, $1 | ||
| 1921 | srl $4, 32, $6 | ||
| 1922 | mulq $5, $6, $25 | ||
| 1923 | mulq $7, $5, $2 | ||
| 1924 | addq $1, $22, $22 | ||
| 1925 | addq $28, $25, $28 | ||
| 1926 | cmpult $28, $25, $1 | ||
| 1927 | mulq $6, $8, $6 | ||
| 1928 | beq $1, $341 | ||
| 1929 | sll $21, 32, $1 | ||
| 1930 | addq $6, $1, $6 | ||
| 1931 | $341: | ||
| 1932 | sll $28, 32, $25 | ||
| 1933 | addq $2, $25, $2 | ||
| 1934 | bis $2, $2, $7 | ||
| 1935 | addq $24, $7, $24 | ||
| 1936 | stq $24, 64($16) | ||
| 1937 | ldq $4, 16($17) | ||
| 1938 | ldq $5, 56($18) | ||
| 1939 | cmpult $24, $7, $3 | ||
| 1940 | zapnot $4, 15, $7 | ||
| 1941 | srl $5, 32, $8 | ||
| 1942 | mulq $8, $7, $0 | ||
| 1943 | srl $28, 32, $1 | ||
| 1944 | cmpult $2, $25, $2 | ||
| 1945 | addq $6, $1, $6 | ||
| 1946 | addq $2, $6, $6 | ||
| 1947 | addq $3, $6, $6 | ||
| 1948 | addq $23, $6, $23 | ||
| 1949 | cmpult $23, $6, $1 | ||
| 1950 | srl $4, 32, $6 | ||
| 1951 | zapnot $5, 15, $5 | ||
| 1952 | mulq $5, $6, $24 | ||
| 1953 | mulq $7, $5, $2 | ||
| 1954 | addq $1, $22, $22 | ||
| 1955 | addq $0, $24, $0 | ||
| 1956 | cmpult $0, $24, $1 | ||
| 1957 | mulq $6, $8, $6 | ||
| 1958 | beq $1, $345 | ||
| 1959 | sll $21, 32, $1 | ||
| 1960 | addq $6, $1, $6 | ||
| 1961 | $345: | ||
| 1962 | sll $0, 32, $24 | ||
| 1963 | ldq $1, 48($18) | ||
| 1964 | addq $2, $24, $2 | ||
| 1965 | bis $2, $2, $7 | ||
| 1966 | ldq $4, 24($17) | ||
| 1967 | addq $23, $7, $23 | ||
| 1968 | srl $1, 32, $8 | ||
| 1969 | cmpult $23, $7, $3 | ||
| 1970 | zapnot $4, 15, $7 | ||
| 1971 | mulq $8, $7, $25 | ||
| 1972 | zapnot $1, 15, $5 | ||
| 1973 | mulq $7, $5, $21 | ||
| 1974 | srl $0, 32, $1 | ||
| 1975 | cmpult $2, $24, $2 | ||
| 1976 | addq $6, $1, $6 | ||
| 1977 | addq $2, $6, $6 | ||
| 1978 | addq $3, $6, $6 | ||
| 1979 | addq $22, $6, $22 | ||
| 1980 | cmpult $22, $6, $24 | ||
| 1981 | srl $4, 32, $6 | ||
| 1982 | mulq $5, $6, $5 | ||
| 1983 | bis $31, 1, $20 | ||
| 1984 | addq $25, $5, $25 | ||
| 1985 | cmpult $25, $5, $1 | ||
| 1986 | mulq $6, $8, $6 | ||
| 1987 | beq $1, $349 | ||
| 1988 | sll $20, 32, $1 | ||
| 1989 | addq $6, $1, $6 | ||
| 1990 | $349: | ||
| 1991 | sll $25, 32, $5 | ||
| 1992 | ldq $2, 40($18) | ||
| 1993 | addq $21, $5, $21 | ||
| 1994 | bis $21, $21, $7 | ||
| 1995 | ldq $4, 32($17) | ||
| 1996 | addq $23, $7, $23 | ||
| 1997 | srl $2, 32, $8 | ||
| 1998 | cmpult $23, $7, $3 | ||
| 1999 | zapnot $4, 15, $7 | ||
| 2000 | mulq $8, $7, $28 | ||
| 2001 | srl $25, 32, $1 | ||
| 2002 | addq $6, $1, $6 | ||
| 2003 | cmpult $21, $5, $1 | ||
| 2004 | zapnot $2, 15, $5 | ||
| 2005 | addq $1, $6, $6 | ||
| 2006 | addq $3, $6, $6 | ||
| 2007 | addq $22, $6, $22 | ||
| 2008 | cmpult $22, $6, $1 | ||
| 2009 | srl $4, 32, $6 | ||
| 2010 | mulq $5, $6, $25 | ||
| 2011 | mulq $7, $5, $5 | ||
| 2012 | addq $1, $24, $24 | ||
| 2013 | addq $28, $25, $28 | ||
| 2014 | cmpult $28, $25, $1 | ||
| 2015 | mulq $6, $8, $6 | ||
| 2016 | beq $1, $353 | ||
| 2017 | sll $20, 32, $1 | ||
| 2018 | addq $6, $1, $6 | ||
| 2019 | $353: | ||
| 2020 | sll $28, 32, $25 | ||
| 2021 | ldq $2, 32($18) | ||
| 2022 | addq $5, $25, $5 | ||
| 2023 | bis $5, $5, $7 | ||
| 2024 | ldq $4, 40($17) | ||
| 2025 | addq $23, $7, $23 | ||
| 2026 | srl $2, 32, $8 | ||
| 2027 | cmpult $23, $7, $3 | ||
| 2028 | zapnot $4, 15, $7 | ||
| 2029 | mulq $8, $7, $0 | ||
| 2030 | srl $28, 32, $1 | ||
| 2031 | addq $6, $1, $6 | ||
| 2032 | cmpult $5, $25, $1 | ||
| 2033 | zapnot $2, 15, $5 | ||
| 2034 | addq $1, $6, $6 | ||
| 2035 | addq $3, $6, $6 | ||
| 2036 | addq $22, $6, $22 | ||
| 2037 | cmpult $22, $6, $1 | ||
| 2038 | srl $4, 32, $6 | ||
| 2039 | mulq $5, $6, $25 | ||
| 2040 | mulq $7, $5, $5 | ||
| 2041 | addq $1, $24, $24 | ||
| 2042 | addq $0, $25, $0 | ||
| 2043 | cmpult $0, $25, $1 | ||
| 2044 | mulq $6, $8, $6 | ||
| 2045 | beq $1, $357 | ||
| 2046 | sll $20, 32, $1 | ||
| 2047 | addq $6, $1, $6 | ||
| 2048 | $357: | ||
| 2049 | sll $0, 32, $25 | ||
| 2050 | ldq $2, 24($18) | ||
| 2051 | addq $5, $25, $5 | ||
| 2052 | bis $5, $5, $7 | ||
| 2053 | ldq $4, 48($17) | ||
| 2054 | addq $23, $7, $23 | ||
| 2055 | srl $2, 32, $8 | ||
| 2056 | cmpult $23, $7, $3 | ||
| 2057 | zapnot $4, 15, $7 | ||
| 2058 | mulq $8, $7, $28 | ||
| 2059 | srl $0, 32, $1 | ||
| 2060 | addq $6, $1, $6 | ||
| 2061 | cmpult $5, $25, $1 | ||
| 2062 | zapnot $2, 15, $5 | ||
| 2063 | addq $1, $6, $6 | ||
| 2064 | addq $3, $6, $6 | ||
| 2065 | addq $22, $6, $22 | ||
| 2066 | cmpult $22, $6, $1 | ||
| 2067 | srl $4, 32, $6 | ||
| 2068 | mulq $5, $6, $25 | ||
| 2069 | mulq $7, $5, $5 | ||
| 2070 | addq $1, $24, $24 | ||
| 2071 | addq $28, $25, $28 | ||
| 2072 | cmpult $28, $25, $1 | ||
| 2073 | mulq $6, $8, $6 | ||
| 2074 | beq $1, $361 | ||
| 2075 | sll $20, 32, $1 | ||
| 2076 | addq $6, $1, $6 | ||
| 2077 | $361: | ||
| 2078 | sll $28, 32, $25 | ||
| 2079 | ldq $2, 16($18) | ||
| 2080 | addq $5, $25, $5 | ||
| 2081 | bis $5, $5, $7 | ||
| 2082 | ldq $4, 56($17) | ||
| 2083 | addq $23, $7, $23 | ||
| 2084 | srl $2, 32, $8 | ||
| 2085 | cmpult $23, $7, $3 | ||
| 2086 | zapnot $4, 15, $7 | ||
| 2087 | mulq $8, $7, $0 | ||
| 2088 | srl $28, 32, $1 | ||
| 2089 | addq $6, $1, $6 | ||
| 2090 | cmpult $5, $25, $1 | ||
| 2091 | zapnot $2, 15, $5 | ||
| 2092 | addq $1, $6, $6 | ||
| 2093 | addq $3, $6, $6 | ||
| 2094 | addq $22, $6, $22 | ||
| 2095 | cmpult $22, $6, $1 | ||
| 2096 | srl $4, 32, $6 | ||
| 2097 | mulq $5, $6, $25 | ||
| 2098 | mulq $7, $5, $2 | ||
| 2099 | addq $1, $24, $24 | ||
| 2100 | addq $0, $25, $0 | ||
| 2101 | cmpult $0, $25, $1 | ||
| 2102 | mulq $6, $8, $6 | ||
| 2103 | beq $1, $365 | ||
| 2104 | sll $20, 32, $1 | ||
| 2105 | addq $6, $1, $6 | ||
| 2106 | $365: | ||
| 2107 | sll $0, 32, $25 | ||
| 2108 | addq $2, $25, $2 | ||
| 2109 | bis $2, $2, $7 | ||
| 2110 | addq $23, $7, $23 | ||
| 2111 | stq $23, 72($16) | ||
| 2112 | ldq $4, 56($17) | ||
| 2113 | ldq $5, 24($18) | ||
| 2114 | cmpult $23, $7, $3 | ||
| 2115 | zapnot $4, 15, $7 | ||
| 2116 | srl $5, 32, $8 | ||
| 2117 | mulq $8, $7, $28 | ||
| 2118 | srl $0, 32, $1 | ||
| 2119 | cmpult $2, $25, $2 | ||
| 2120 | addq $6, $1, $6 | ||
| 2121 | addq $2, $6, $6 | ||
| 2122 | addq $3, $6, $6 | ||
| 2123 | addq $22, $6, $22 | ||
| 2124 | cmpult $22, $6, $1 | ||
| 2125 | srl $4, 32, $6 | ||
| 2126 | zapnot $5, 15, $5 | ||
| 2127 | mulq $5, $6, $23 | ||
| 2128 | mulq $7, $5, $2 | ||
| 2129 | addq $1, $24, $24 | ||
| 2130 | addq $28, $23, $28 | ||
| 2131 | cmpult $28, $23, $1 | ||
| 2132 | mulq $6, $8, $6 | ||
| 2133 | beq $1, $369 | ||
| 2134 | sll $20, 32, $1 | ||
| 2135 | addq $6, $1, $6 | ||
| 2136 | $369: | ||
| 2137 | sll $28, 32, $23 | ||
| 2138 | ldq $1, 32($18) | ||
| 2139 | addq $2, $23, $2 | ||
| 2140 | bis $2, $2, $7 | ||
| 2141 | ldq $4, 48($17) | ||
| 2142 | addq $22, $7, $22 | ||
| 2143 | srl $1, 32, $8 | ||
| 2144 | cmpult $22, $7, $3 | ||
| 2145 | zapnot $4, 15, $7 | ||
| 2146 | mulq $8, $7, $25 | ||
| 2147 | zapnot $1, 15, $5 | ||
| 2148 | mulq $7, $5, $0 | ||
| 2149 | srl $28, 32, $1 | ||
| 2150 | cmpult $2, $23, $2 | ||
| 2151 | addq $6, $1, $6 | ||
| 2152 | addq $2, $6, $6 | ||
| 2153 | addq $3, $6, $6 | ||
| 2154 | addq $24, $6, $24 | ||
| 2155 | cmpult $24, $6, $23 | ||
| 2156 | srl $4, 32, $6 | ||
| 2157 | mulq $5, $6, $5 | ||
| 2158 | bis $31, 1, $21 | ||
| 2159 | addq $25, $5, $25 | ||
| 2160 | cmpult $25, $5, $1 | ||
| 2161 | mulq $6, $8, $6 | ||
| 2162 | beq $1, $373 | ||
| 2163 | sll $21, 32, $1 | ||
| 2164 | addq $6, $1, $6 | ||
| 2165 | $373: | ||
| 2166 | sll $25, 32, $5 | ||
| 2167 | ldq $2, 40($18) | ||
| 2168 | addq $0, $5, $0 | ||
| 2169 | bis $0, $0, $7 | ||
| 2170 | ldq $4, 40($17) | ||
| 2171 | addq $22, $7, $22 | ||
| 2172 | srl $2, 32, $8 | ||
| 2173 | cmpult $22, $7, $3 | ||
| 2174 | zapnot $4, 15, $7 | ||
| 2175 | mulq $8, $7, $28 | ||
| 2176 | srl $25, 32, $1 | ||
| 2177 | addq $6, $1, $6 | ||
| 2178 | cmpult $0, $5, $1 | ||
| 2179 | zapnot $2, 15, $5 | ||
| 2180 | addq $1, $6, $6 | ||
| 2181 | addq $3, $6, $6 | ||
| 2182 | addq $24, $6, $24 | ||
| 2183 | cmpult $24, $6, $1 | ||
| 2184 | srl $4, 32, $6 | ||
| 2185 | mulq $5, $6, $25 | ||
| 2186 | mulq $7, $5, $5 | ||
| 2187 | addq $1, $23, $23 | ||
| 2188 | addq $28, $25, $28 | ||
| 2189 | cmpult $28, $25, $1 | ||
| 2190 | mulq $6, $8, $6 | ||
| 2191 | beq $1, $377 | ||
| 2192 | sll $21, 32, $1 | ||
| 2193 | addq $6, $1, $6 | ||
| 2194 | $377: | ||
| 2195 | sll $28, 32, $25 | ||
| 2196 | ldq $2, 48($18) | ||
| 2197 | addq $5, $25, $5 | ||
| 2198 | bis $5, $5, $7 | ||
| 2199 | ldq $4, 32($17) | ||
| 2200 | addq $22, $7, $22 | ||
| 2201 | srl $2, 32, $8 | ||
| 2202 | cmpult $22, $7, $3 | ||
| 2203 | zapnot $4, 15, $7 | ||
| 2204 | mulq $8, $7, $0 | ||
| 2205 | srl $28, 32, $1 | ||
| 2206 | addq $6, $1, $6 | ||
| 2207 | cmpult $5, $25, $1 | ||
| 2208 | zapnot $2, 15, $5 | ||
| 2209 | addq $1, $6, $6 | ||
| 2210 | addq $3, $6, $6 | ||
| 2211 | addq $24, $6, $24 | ||
| 2212 | cmpult $24, $6, $1 | ||
| 2213 | srl $4, 32, $6 | ||
| 2214 | mulq $5, $6, $25 | ||
| 2215 | mulq $7, $5, $5 | ||
| 2216 | addq $1, $23, $23 | ||
| 2217 | addq $0, $25, $0 | ||
| 2218 | cmpult $0, $25, $1 | ||
| 2219 | mulq $6, $8, $6 | ||
| 2220 | beq $1, $381 | ||
| 2221 | sll $21, 32, $1 | ||
| 2222 | addq $6, $1, $6 | ||
| 2223 | $381: | ||
| 2224 | sll $0, 32, $25 | ||
| 2225 | ldq $2, 56($18) | ||
| 2226 | addq $5, $25, $5 | ||
| 2227 | bis $5, $5, $7 | ||
| 2228 | ldq $4, 24($17) | ||
| 2229 | addq $22, $7, $22 | ||
| 2230 | srl $2, 32, $8 | ||
| 2231 | cmpult $22, $7, $3 | ||
| 2232 | zapnot $4, 15, $7 | ||
| 2233 | mulq $8, $7, $28 | ||
| 2234 | srl $0, 32, $1 | ||
| 2235 | addq $6, $1, $6 | ||
| 2236 | cmpult $5, $25, $1 | ||
| 2237 | zapnot $2, 15, $5 | ||
| 2238 | addq $1, $6, $6 | ||
| 2239 | addq $3, $6, $6 | ||
| 2240 | addq $24, $6, $24 | ||
| 2241 | cmpult $24, $6, $1 | ||
| 2242 | srl $4, 32, $6 | ||
| 2243 | mulq $5, $6, $25 | ||
| 2244 | mulq $7, $5, $2 | ||
| 2245 | addq $1, $23, $23 | ||
| 2246 | addq $28, $25, $28 | ||
| 2247 | cmpult $28, $25, $1 | ||
| 2248 | mulq $6, $8, $6 | ||
| 2249 | beq $1, $385 | ||
| 2250 | sll $21, 32, $1 | ||
| 2251 | addq $6, $1, $6 | ||
| 2252 | $385: | ||
| 2253 | sll $28, 32, $25 | ||
| 2254 | addq $2, $25, $2 | ||
| 2255 | bis $2, $2, $7 | ||
| 2256 | addq $22, $7, $22 | ||
| 2257 | stq $22, 80($16) | ||
| 2258 | ldq $4, 32($17) | ||
| 2259 | ldq $5, 56($18) | ||
| 2260 | cmpult $22, $7, $3 | ||
| 2261 | zapnot $4, 15, $7 | ||
| 2262 | srl $5, 32, $8 | ||
| 2263 | mulq $8, $7, $0 | ||
| 2264 | srl $28, 32, $1 | ||
| 2265 | cmpult $2, $25, $2 | ||
| 2266 | addq $6, $1, $6 | ||
| 2267 | addq $2, $6, $6 | ||
| 2268 | addq $3, $6, $6 | ||
| 2269 | addq $24, $6, $24 | ||
| 2270 | cmpult $24, $6, $1 | ||
| 2271 | srl $4, 32, $6 | ||
| 2272 | zapnot $5, 15, $5 | ||
| 2273 | mulq $5, $6, $22 | ||
| 2274 | mulq $7, $5, $2 | ||
| 2275 | addq $1, $23, $23 | ||
| 2276 | addq $0, $22, $0 | ||
| 2277 | cmpult $0, $22, $1 | ||
| 2278 | mulq $6, $8, $6 | ||
| 2279 | beq $1, $389 | ||
| 2280 | sll $21, 32, $1 | ||
| 2281 | addq $6, $1, $6 | ||
| 2282 | $389: | ||
| 2283 | sll $0, 32, $22 | ||
| 2284 | ldq $1, 48($18) | ||
| 2285 | addq $2, $22, $2 | ||
| 2286 | bis $2, $2, $7 | ||
| 2287 | ldq $4, 40($17) | ||
| 2288 | addq $24, $7, $24 | ||
| 2289 | srl $1, 32, $8 | ||
| 2290 | cmpult $24, $7, $3 | ||
| 2291 | zapnot $4, 15, $7 | ||
| 2292 | mulq $8, $7, $25 | ||
| 2293 | zapnot $1, 15, $5 | ||
| 2294 | mulq $7, $5, $21 | ||
| 2295 | srl $0, 32, $1 | ||
| 2296 | cmpult $2, $22, $2 | ||
| 2297 | addq $6, $1, $6 | ||
| 2298 | addq $2, $6, $6 | ||
| 2299 | addq $3, $6, $6 | ||
| 2300 | addq $23, $6, $23 | ||
| 2301 | cmpult $23, $6, $22 | ||
| 2302 | srl $4, 32, $6 | ||
| 2303 | mulq $5, $6, $5 | ||
| 2304 | bis $31, 1, $20 | ||
| 2305 | addq $25, $5, $25 | ||
| 2306 | cmpult $25, $5, $1 | ||
| 2307 | mulq $6, $8, $6 | ||
| 2308 | beq $1, $393 | ||
| 2309 | sll $20, 32, $1 | ||
| 2310 | addq $6, $1, $6 | ||
| 2311 | $393: | ||
| 2312 | sll $25, 32, $5 | ||
| 2313 | ldq $2, 40($18) | ||
| 2314 | addq $21, $5, $21 | ||
| 2315 | bis $21, $21, $7 | ||
| 2316 | ldq $4, 48($17) | ||
| 2317 | addq $24, $7, $24 | ||
| 2318 | srl $2, 32, $8 | ||
| 2319 | cmpult $24, $7, $3 | ||
| 2320 | zapnot $4, 15, $7 | ||
| 2321 | mulq $8, $7, $28 | ||
| 2322 | srl $25, 32, $1 | ||
| 2323 | addq $6, $1, $6 | ||
| 2324 | cmpult $21, $5, $1 | ||
| 2325 | zapnot $2, 15, $5 | ||
| 2326 | addq $1, $6, $6 | ||
| 2327 | addq $3, $6, $6 | ||
| 2328 | addq $23, $6, $23 | ||
| 2329 | cmpult $23, $6, $1 | ||
| 2330 | srl $4, 32, $6 | ||
| 2331 | mulq $5, $6, $25 | ||
| 2332 | mulq $7, $5, $5 | ||
| 2333 | addq $1, $22, $22 | ||
| 2334 | addq $28, $25, $28 | ||
| 2335 | cmpult $28, $25, $1 | ||
| 2336 | mulq $6, $8, $6 | ||
| 2337 | beq $1, $397 | ||
| 2338 | sll $20, 32, $1 | ||
| 2339 | addq $6, $1, $6 | ||
| 2340 | $397: | ||
| 2341 | sll $28, 32, $25 | ||
| 2342 | ldq $2, 32($18) | ||
| 2343 | addq $5, $25, $5 | ||
| 2344 | bis $5, $5, $7 | ||
| 2345 | ldq $4, 56($17) | ||
| 2346 | addq $24, $7, $24 | ||
| 2347 | srl $2, 32, $8 | ||
| 2348 | cmpult $24, $7, $3 | ||
| 2349 | zapnot $4, 15, $7 | ||
| 2350 | mulq $8, $7, $21 | ||
| 2351 | srl $28, 32, $1 | ||
| 2352 | addq $6, $1, $6 | ||
| 2353 | cmpult $5, $25, $1 | ||
| 2354 | zapnot $2, 15, $5 | ||
| 2355 | addq $1, $6, $6 | ||
| 2356 | addq $3, $6, $6 | ||
| 2357 | addq $23, $6, $23 | ||
| 2358 | cmpult $23, $6, $1 | ||
| 2359 | srl $4, 32, $6 | ||
| 2360 | mulq $5, $6, $25 | ||
| 2361 | mulq $7, $5, $2 | ||
| 2362 | addq $1, $22, $22 | ||
| 2363 | addq $21, $25, $21 | ||
| 2364 | cmpult $21, $25, $1 | ||
| 2365 | mulq $6, $8, $6 | ||
| 2366 | beq $1, $401 | ||
| 2367 | sll $20, 32, $1 | ||
| 2368 | addq $6, $1, $6 | ||
| 2369 | $401: | ||
| 2370 | sll $21, 32, $25 | ||
| 2371 | addq $2, $25, $2 | ||
| 2372 | bis $2, $2, $7 | ||
| 2373 | addq $24, $7, $24 | ||
| 2374 | stq $24, 88($16) | ||
| 2375 | ldq $4, 56($17) | ||
| 2376 | ldq $5, 40($18) | ||
| 2377 | cmpult $24, $7, $3 | ||
| 2378 | zapnot $4, 15, $7 | ||
| 2379 | srl $5, 32, $8 | ||
| 2380 | mulq $8, $7, $0 | ||
| 2381 | srl $21, 32, $1 | ||
| 2382 | cmpult $2, $25, $2 | ||
| 2383 | addq $6, $1, $6 | ||
| 2384 | addq $2, $6, $6 | ||
| 2385 | addq $3, $6, $6 | ||
| 2386 | addq $23, $6, $23 | ||
| 2387 | cmpult $23, $6, $1 | ||
| 2388 | srl $4, 32, $6 | ||
| 2389 | zapnot $5, 15, $5 | ||
| 2390 | mulq $5, $6, $24 | ||
| 2391 | mulq $7, $5, $5 | ||
| 2392 | addq $1, $22, $22 | ||
| 2393 | addq $0, $24, $0 | ||
| 2394 | cmpult $0, $24, $1 | ||
| 2395 | mulq $6, $8, $6 | ||
| 2396 | beq $1, $405 | ||
| 2397 | sll $20, 32, $1 | ||
| 2398 | addq $6, $1, $6 | ||
| 2399 | $405: | ||
| 2400 | sll $0, 32, $24 | ||
| 2401 | ldq $2, 48($18) | ||
| 2402 | addq $5, $24, $5 | ||
| 2403 | bis $5, $5, $7 | ||
| 2404 | ldq $4, 48($17) | ||
| 2405 | addq $23, $7, $23 | ||
| 2406 | srl $2, 32, $8 | ||
| 2407 | cmpult $23, $7, $3 | ||
| 2408 | zapnot $4, 15, $7 | ||
| 2409 | mulq $8, $7, $28 | ||
| 2410 | srl $0, 32, $1 | ||
| 2411 | addq $6, $1, $6 | ||
| 2412 | cmpult $5, $24, $1 | ||
| 2413 | zapnot $2, 15, $5 | ||
| 2414 | addq $1, $6, $6 | ||
| 2415 | addq $3, $6, $6 | ||
| 2416 | addq $22, $6, $22 | ||
| 2417 | cmpult $22, $6, $24 | ||
| 2418 | srl $4, 32, $6 | ||
| 2419 | mulq $5, $6, $25 | ||
| 2420 | mulq $7, $5, $5 | ||
| 2421 | addq $28, $25, $28 | ||
| 2422 | cmpult $28, $25, $1 | ||
| 2423 | mulq $6, $8, $6 | ||
| 2424 | beq $1, $409 | ||
| 2425 | sll $20, 32, $1 | ||
| 2426 | addq $6, $1, $6 | ||
| 2427 | $409: | ||
| 2428 | sll $28, 32, $25 | ||
| 2429 | ldq $2, 56($18) | ||
| 2430 | addq $5, $25, $5 | ||
| 2431 | bis $5, $5, $7 | ||
| 2432 | ldq $4, 40($17) | ||
| 2433 | addq $23, $7, $23 | ||
| 2434 | srl $2, 32, $8 | ||
| 2435 | cmpult $23, $7, $3 | ||
| 2436 | zapnot $4, 15, $7 | ||
| 2437 | mulq $8, $7, $0 | ||
| 2438 | srl $28, 32, $1 | ||
| 2439 | addq $6, $1, $6 | ||
| 2440 | cmpult $5, $25, $1 | ||
| 2441 | zapnot $2, 15, $5 | ||
| 2442 | addq $1, $6, $6 | ||
| 2443 | addq $3, $6, $6 | ||
| 2444 | addq $22, $6, $22 | ||
| 2445 | cmpult $22, $6, $1 | ||
| 2446 | srl $4, 32, $6 | ||
| 2447 | mulq $5, $6, $25 | ||
| 2448 | mulq $7, $5, $2 | ||
| 2449 | addq $1, $24, $24 | ||
| 2450 | addq $0, $25, $0 | ||
| 2451 | cmpult $0, $25, $1 | ||
| 2452 | mulq $6, $8, $6 | ||
| 2453 | beq $1, $413 | ||
| 2454 | sll $20, 32, $1 | ||
| 2455 | addq $6, $1, $6 | ||
| 2456 | $413: | ||
| 2457 | sll $0, 32, $25 | ||
| 2458 | addq $2, $25, $2 | ||
| 2459 | bis $2, $2, $7 | ||
| 2460 | addq $23, $7, $23 | ||
| 2461 | stq $23, 96($16) | ||
| 2462 | ldq $4, 48($17) | ||
| 2463 | ldq $5, 56($18) | ||
| 2464 | cmpult $23, $7, $3 | ||
| 2465 | zapnot $4, 15, $7 | ||
| 2466 | srl $5, 32, $8 | ||
| 2467 | mulq $8, $7, $28 | ||
| 2468 | srl $0, 32, $1 | ||
| 2469 | cmpult $2, $25, $2 | ||
| 2470 | addq $6, $1, $6 | ||
| 2471 | addq $2, $6, $6 | ||
| 2472 | addq $3, $6, $6 | ||
| 2473 | addq $22, $6, $22 | ||
| 2474 | cmpult $22, $6, $1 | ||
| 2475 | srl $4, 32, $6 | ||
| 2476 | zapnot $5, 15, $5 | ||
| 2477 | mulq $5, $6, $23 | ||
| 2478 | mulq $7, $5, $5 | ||
| 2479 | addq $1, $24, $24 | ||
| 2480 | addq $28, $23, $28 | ||
| 2481 | cmpult $28, $23, $1 | ||
| 2482 | mulq $6, $8, $6 | ||
| 2483 | beq $1, $417 | ||
| 2484 | sll $20, 32, $1 | ||
| 2485 | addq $6, $1, $6 | ||
| 2486 | $417: | ||
| 2487 | sll $28, 32, $23 | ||
| 2488 | ldq $2, 48($18) | ||
| 2489 | addq $5, $23, $5 | ||
| 2490 | bis $5, $5, $7 | ||
| 2491 | ldq $4, 56($17) | ||
| 2492 | addq $22, $7, $22 | ||
| 2493 | srl $2, 32, $8 | ||
| 2494 | cmpult $22, $7, $3 | ||
| 2495 | zapnot $4, 15, $7 | ||
| 2496 | mulq $8, $7, $0 | ||
| 2497 | srl $28, 32, $1 | ||
| 2498 | addq $6, $1, $6 | ||
| 2499 | cmpult $5, $23, $1 | ||
| 2500 | zapnot $2, 15, $5 | ||
| 2501 | addq $1, $6, $6 | ||
| 2502 | addq $3, $6, $6 | ||
| 2503 | addq $24, $6, $24 | ||
| 2504 | cmpult $24, $6, $23 | ||
| 2505 | srl $4, 32, $6 | ||
| 2506 | mulq $5, $6, $25 | ||
| 2507 | mulq $7, $5, $2 | ||
| 2508 | addq $0, $25, $0 | ||
| 2509 | cmpult $0, $25, $1 | ||
| 2510 | mulq $6, $8, $6 | ||
| 2511 | beq $1, $421 | ||
| 2512 | sll $20, 32, $1 | ||
| 2513 | addq $6, $1, $6 | ||
| 2514 | $421: | ||
| 2515 | sll $0, 32, $25 | ||
| 2516 | addq $2, $25, $2 | ||
| 2517 | bis $2, $2, $7 | ||
| 2518 | addq $22, $7, $22 | ||
| 2519 | stq $22, 104($16) | ||
| 2520 | ldq $4, 56($17) | ||
| 2521 | ldq $5, 56($18) | ||
| 2522 | cmpult $22, $7, $3 | ||
| 2523 | zapnot $4, 15, $7 | ||
| 2524 | srl $5, 32, $8 | ||
| 2525 | mulq $8, $7, $28 | ||
| 2526 | srl $0, 32, $1 | ||
| 2527 | cmpult $2, $25, $2 | ||
| 2528 | addq $6, $1, $6 | ||
| 2529 | addq $2, $6, $6 | ||
| 2530 | addq $3, $6, $6 | ||
| 2531 | addq $24, $6, $24 | ||
| 2532 | cmpult $24, $6, $1 | ||
| 2533 | srl $4, 32, $6 | ||
| 2534 | zapnot $5, 15, $5 | ||
| 2535 | mulq $5, $6, $22 | ||
| 2536 | mulq $7, $5, $2 | ||
| 2537 | addq $1, $23, $23 | ||
| 2538 | addq $28, $22, $28 | ||
| 2539 | cmpult $28, $22, $1 | ||
| 2540 | mulq $6, $8, $3 | ||
| 2541 | beq $1, $425 | ||
| 2542 | sll $20, 32, $1 | ||
| 2543 | addq $3, $1, $3 | ||
| 2544 | $425: | ||
| 2545 | sll $28, 32, $22 | ||
| 2546 | srl $28, 32, $1 | ||
| 2547 | addq $2, $22, $2 | ||
| 2548 | addq $3, $1, $3 | ||
| 2549 | bis $2, $2, $7 | ||
| 2550 | addq $24, $7, $24 | ||
| 2551 | cmpult $7, $22, $1 | ||
| 2552 | cmpult $24, $7, $2 | ||
| 2553 | addq $1, $3, $6 | ||
| 2554 | addq $2, $6, $6 | ||
| 2555 | stq $24, 112($16) | ||
| 2556 | addq $23, $6, $23 | ||
| 2557 | stq $23, 120($16) | ||
| 2558 | ret $31, ($26), 1 | ||
| 2559 | .end bn_mul_comba8 | ||
| 2560 | .text | ||
| 2561 | .align 3 | ||
| 2562 | .globl bn_sqr_comba4 | ||
| 2563 | .ent bn_sqr_comba4 | ||
| 2564 | bn_sqr_comba4: | ||
| 2565 | bn_sqr_comba4..ng: | ||
| 2566 | .frame $30,0,$26,0 | ||
| 2567 | .prologue 0 | ||
| 2568 | |||
| 2569 | ldq $0, 0($17) | ||
| 2570 | ldq $1, 8($17) | ||
| 2571 | ldq $2, 16($17) | ||
| 2572 | ldq $3, 24($17) | ||
| 2573 | bis $31, $31, $6 | ||
| 2574 | mulq $0, $0, $4 | ||
| 2575 | umulh $0, $0, $5 | ||
| 2576 | stq $4, 0($16) | ||
| 2577 | bis $31, $31, $4 | ||
| 2578 | mulq $0, $1, $7 | ||
| 2579 | umulh $0, $1, $8 | ||
| 2580 | cmplt $7, $31, $22 | ||
| 2581 | cmplt $8, $31, $23 | ||
| 2582 | addq $7, $7, $7 | ||
| 2583 | addq $8, $8, $8 | ||
| 2584 | addq $8, $22, $8 | ||
| 2585 | addq $4, $23, $4 | ||
| 2586 | addq $5, $7, $5 | ||
| 2587 | addq $6, $8, $6 | ||
| 2588 | cmpult $5, $7, $24 | ||
| 2589 | cmpult $6, $8, $25 | ||
| 2590 | addq $6, $24, $6 | ||
| 2591 | addq $4, $25, $4 | ||
| 2592 | stq $5, 8($16) | ||
| 2593 | bis $31, $31, $5 | ||
| 2594 | mulq $1, $1, $27 | ||
| 2595 | umulh $1, $1, $28 | ||
| 2596 | addq $6, $27, $6 | ||
| 2597 | addq $4, $28, $4 | ||
| 2598 | cmpult $6, $27, $21 | ||
| 2599 | cmpult $4, $28, $20 | ||
| 2600 | addq $4, $21, $4 | ||
| 2601 | addq $5, $20, $5 | ||
| 2602 | mulq $2, $0, $19 | ||
| 2603 | umulh $2, $0, $18 | ||
| 2604 | cmplt $19, $31, $17 | ||
| 2605 | cmplt $18, $31, $22 | ||
| 2606 | addq $19, $19, $19 | ||
| 2607 | addq $18, $18, $18 | ||
| 2608 | addq $18, $17, $18 | ||
| 2609 | addq $5, $22, $5 | ||
| 2610 | addq $6, $19, $6 | ||
| 2611 | addq $4, $18, $4 | ||
| 2612 | cmpult $6, $19, $23 | ||
| 2613 | cmpult $4, $18, $7 | ||
| 2614 | addq $4, $23, $4 | ||
| 2615 | addq $5, $7, $5 | ||
| 2616 | stq $6, 16($16) | ||
| 2617 | bis $31, $31, $6 | ||
| 2618 | mulq $3, $0, $8 | ||
| 2619 | umulh $3, $0, $24 | ||
| 2620 | cmplt $8, $31, $25 | ||
| 2621 | cmplt $24, $31, $27 | ||
| 2622 | addq $8, $8, $8 | ||
| 2623 | addq $24, $24, $24 | ||
| 2624 | addq $24, $25, $24 | ||
| 2625 | addq $6, $27, $6 | ||
| 2626 | addq $4, $8, $4 | ||
| 2627 | addq $5, $24, $5 | ||
| 2628 | cmpult $4, $8, $28 | ||
| 2629 | cmpult $5, $24, $21 | ||
| 2630 | addq $5, $28, $5 | ||
| 2631 | addq $6, $21, $6 | ||
| 2632 | mulq $2, $1, $20 | ||
| 2633 | umulh $2, $1, $17 | ||
| 2634 | cmplt $20, $31, $22 | ||
| 2635 | cmplt $17, $31, $19 | ||
| 2636 | addq $20, $20, $20 | ||
| 2637 | addq $17, $17, $17 | ||
| 2638 | addq $17, $22, $17 | ||
| 2639 | addq $6, $19, $6 | ||
| 2640 | addq $4, $20, $4 | ||
| 2641 | addq $5, $17, $5 | ||
| 2642 | cmpult $4, $20, $18 | ||
| 2643 | cmpult $5, $17, $23 | ||
| 2644 | addq $5, $18, $5 | ||
| 2645 | addq $6, $23, $6 | ||
| 2646 | stq $4, 24($16) | ||
| 2647 | bis $31, $31, $4 | ||
| 2648 | mulq $2, $2, $7 | ||
| 2649 | umulh $2, $2, $25 | ||
| 2650 | addq $5, $7, $5 | ||
| 2651 | addq $6, $25, $6 | ||
| 2652 | cmpult $5, $7, $27 | ||
| 2653 | cmpult $6, $25, $8 | ||
| 2654 | addq $6, $27, $6 | ||
| 2655 | addq $4, $8, $4 | ||
| 2656 | mulq $3, $1, $24 | ||
| 2657 | umulh $3, $1, $28 | ||
| 2658 | cmplt $24, $31, $21 | ||
| 2659 | cmplt $28, $31, $22 | ||
| 2660 | addq $24, $24, $24 | ||
| 2661 | addq $28, $28, $28 | ||
| 2662 | addq $28, $21, $28 | ||
| 2663 | addq $4, $22, $4 | ||
| 2664 | addq $5, $24, $5 | ||
| 2665 | addq $6, $28, $6 | ||
| 2666 | cmpult $5, $24, $19 | ||
| 2667 | cmpult $6, $28, $20 | ||
| 2668 | addq $6, $19, $6 | ||
| 2669 | addq $4, $20, $4 | ||
| 2670 | stq $5, 32($16) | ||
| 2671 | bis $31, $31, $5 | ||
| 2672 | mulq $3, $2, $17 | ||
| 2673 | umulh $3, $2, $18 | ||
| 2674 | cmplt $17, $31, $23 | ||
| 2675 | cmplt $18, $31, $7 | ||
| 2676 | addq $17, $17, $17 | ||
| 2677 | addq $18, $18, $18 | ||
| 2678 | addq $18, $23, $18 | ||
| 2679 | addq $5, $7, $5 | ||
| 2680 | addq $6, $17, $6 | ||
| 2681 | addq $4, $18, $4 | ||
| 2682 | cmpult $6, $17, $25 | ||
| 2683 | cmpult $4, $18, $27 | ||
| 2684 | addq $4, $25, $4 | ||
| 2685 | addq $5, $27, $5 | ||
| 2686 | stq $6, 40($16) | ||
| 2687 | bis $31, $31, $6 | ||
| 2688 | mulq $3, $3, $8 | ||
| 2689 | umulh $3, $3, $21 | ||
| 2690 | addq $4, $8, $4 | ||
| 2691 | addq $5, $21, $5 | ||
| 2692 | cmpult $4, $8, $22 | ||
| 2693 | cmpult $5, $21, $24 | ||
| 2694 | addq $5, $22, $5 | ||
| 2695 | addq $6, $24, $6 | ||
| 2696 | stq $4, 48($16) | ||
| 2697 | stq $5, 56($16) | ||
| 2698 | ret $31,($26),1 | ||
| 2699 | .end bn_sqr_comba4 | ||
| 2700 | .text | ||
| 2701 | .align 3 | ||
| 2702 | .globl bn_sqr_comba8 | ||
| 2703 | .ent bn_sqr_comba8 | ||
| 2704 | bn_sqr_comba8: | ||
| 2705 | bn_sqr_comba8..ng: | ||
| 2706 | .frame $30,0,$26,0 | ||
| 2707 | .prologue 0 | ||
| 2708 | |||
| 2709 | ldq $0, 0($17) | ||
| 2710 | ldq $1, 8($17) | ||
| 2711 | ldq $2, 16($17) | ||
| 2712 | ldq $3, 24($17) | ||
| 2713 | ldq $4, 32($17) | ||
| 2714 | ldq $5, 40($17) | ||
| 2715 | ldq $6, 48($17) | ||
| 2716 | ldq $7, 56($17) | ||
| 2717 | bis $31, $31, $23 | ||
| 2718 | mulq $0, $0, $8 | ||
| 2719 | umulh $0, $0, $22 | ||
| 2720 | stq $8, 0($16) | ||
| 2721 | bis $31, $31, $8 | ||
| 2722 | mulq $1, $0, $24 | ||
| 2723 | umulh $1, $0, $25 | ||
| 2724 | cmplt $24, $31, $27 | ||
| 2725 | cmplt $25, $31, $28 | ||
| 2726 | addq $24, $24, $24 | ||
| 2727 | addq $25, $25, $25 | ||
| 2728 | addq $25, $27, $25 | ||
| 2729 | addq $8, $28, $8 | ||
| 2730 | addq $22, $24, $22 | ||
| 2731 | addq $23, $25, $23 | ||
| 2732 | cmpult $22, $24, $21 | ||
| 2733 | cmpult $23, $25, $20 | ||
| 2734 | addq $23, $21, $23 | ||
| 2735 | addq $8, $20, $8 | ||
| 2736 | stq $22, 8($16) | ||
| 2737 | bis $31, $31, $22 | ||
| 2738 | mulq $1, $1, $19 | ||
| 2739 | umulh $1, $1, $18 | ||
| 2740 | addq $23, $19, $23 | ||
| 2741 | addq $8, $18, $8 | ||
| 2742 | cmpult $23, $19, $17 | ||
| 2743 | cmpult $8, $18, $27 | ||
| 2744 | addq $8, $17, $8 | ||
| 2745 | addq $22, $27, $22 | ||
| 2746 | mulq $2, $0, $28 | ||
| 2747 | umulh $2, $0, $24 | ||
| 2748 | cmplt $28, $31, $25 | ||
| 2749 | cmplt $24, $31, $21 | ||
| 2750 | addq $28, $28, $28 | ||
| 2751 | addq $24, $24, $24 | ||
| 2752 | addq $24, $25, $24 | ||
| 2753 | addq $22, $21, $22 | ||
| 2754 | addq $23, $28, $23 | ||
| 2755 | addq $8, $24, $8 | ||
| 2756 | cmpult $23, $28, $20 | ||
| 2757 | cmpult $8, $24, $19 | ||
| 2758 | addq $8, $20, $8 | ||
| 2759 | addq $22, $19, $22 | ||
| 2760 | stq $23, 16($16) | ||
| 2761 | bis $31, $31, $23 | ||
| 2762 | mulq $2, $1, $18 | ||
| 2763 | umulh $2, $1, $17 | ||
| 2764 | cmplt $18, $31, $27 | ||
| 2765 | cmplt $17, $31, $25 | ||
| 2766 | addq $18, $18, $18 | ||
| 2767 | addq $17, $17, $17 | ||
| 2768 | addq $17, $27, $17 | ||
| 2769 | addq $23, $25, $23 | ||
| 2770 | addq $8, $18, $8 | ||
| 2771 | addq $22, $17, $22 | ||
| 2772 | cmpult $8, $18, $21 | ||
| 2773 | cmpult $22, $17, $28 | ||
| 2774 | addq $22, $21, $22 | ||
| 2775 | addq $23, $28, $23 | ||
| 2776 | mulq $3, $0, $24 | ||
| 2777 | umulh $3, $0, $20 | ||
| 2778 | cmplt $24, $31, $19 | ||
| 2779 | cmplt $20, $31, $27 | ||
| 2780 | addq $24, $24, $24 | ||
| 2781 | addq $20, $20, $20 | ||
| 2782 | addq $20, $19, $20 | ||
| 2783 | addq $23, $27, $23 | ||
| 2784 | addq $8, $24, $8 | ||
| 2785 | addq $22, $20, $22 | ||
| 2786 | cmpult $8, $24, $25 | ||
| 2787 | cmpult $22, $20, $18 | ||
| 2788 | addq $22, $25, $22 | ||
| 2789 | addq $23, $18, $23 | ||
| 2790 | stq $8, 24($16) | ||
| 2791 | bis $31, $31, $8 | ||
| 2792 | mulq $2, $2, $17 | ||
| 2793 | umulh $2, $2, $21 | ||
| 2794 | addq $22, $17, $22 | ||
| 2795 | addq $23, $21, $23 | ||
| 2796 | cmpult $22, $17, $28 | ||
| 2797 | cmpult $23, $21, $19 | ||
| 2798 | addq $23, $28, $23 | ||
| 2799 | addq $8, $19, $8 | ||
| 2800 | mulq $3, $1, $27 | ||
| 2801 | umulh $3, $1, $24 | ||
| 2802 | cmplt $27, $31, $20 | ||
| 2803 | cmplt $24, $31, $25 | ||
| 2804 | addq $27, $27, $27 | ||
| 2805 | addq $24, $24, $24 | ||
| 2806 | addq $24, $20, $24 | ||
| 2807 | addq $8, $25, $8 | ||
| 2808 | addq $22, $27, $22 | ||
| 2809 | addq $23, $24, $23 | ||
| 2810 | cmpult $22, $27, $18 | ||
| 2811 | cmpult $23, $24, $17 | ||
| 2812 | addq $23, $18, $23 | ||
| 2813 | addq $8, $17, $8 | ||
| 2814 | mulq $4, $0, $21 | ||
| 2815 | umulh $4, $0, $28 | ||
| 2816 | cmplt $21, $31, $19 | ||
| 2817 | cmplt $28, $31, $20 | ||
| 2818 | addq $21, $21, $21 | ||
| 2819 | addq $28, $28, $28 | ||
| 2820 | addq $28, $19, $28 | ||
| 2821 | addq $8, $20, $8 | ||
| 2822 | addq $22, $21, $22 | ||
| 2823 | addq $23, $28, $23 | ||
| 2824 | cmpult $22, $21, $25 | ||
| 2825 | cmpult $23, $28, $27 | ||
| 2826 | addq $23, $25, $23 | ||
| 2827 | addq $8, $27, $8 | ||
| 2828 | stq $22, 32($16) | ||
| 2829 | bis $31, $31, $22 | ||
| 2830 | mulq $3, $2, $24 | ||
| 2831 | umulh $3, $2, $18 | ||
| 2832 | cmplt $24, $31, $17 | ||
| 2833 | cmplt $18, $31, $19 | ||
| 2834 | addq $24, $24, $24 | ||
| 2835 | addq $18, $18, $18 | ||
| 2836 | addq $18, $17, $18 | ||
| 2837 | addq $22, $19, $22 | ||
| 2838 | addq $23, $24, $23 | ||
| 2839 | addq $8, $18, $8 | ||
| 2840 | cmpult $23, $24, $20 | ||
| 2841 | cmpult $8, $18, $21 | ||
| 2842 | addq $8, $20, $8 | ||
| 2843 | addq $22, $21, $22 | ||
| 2844 | mulq $4, $1, $28 | ||
| 2845 | umulh $4, $1, $25 | ||
| 2846 | cmplt $28, $31, $27 | ||
| 2847 | cmplt $25, $31, $17 | ||
| 2848 | addq $28, $28, $28 | ||
| 2849 | addq $25, $25, $25 | ||
| 2850 | addq $25, $27, $25 | ||
| 2851 | addq $22, $17, $22 | ||
| 2852 | addq $23, $28, $23 | ||
| 2853 | addq $8, $25, $8 | ||
| 2854 | cmpult $23, $28, $19 | ||
| 2855 | cmpult $8, $25, $24 | ||
| 2856 | addq $8, $19, $8 | ||
| 2857 | addq $22, $24, $22 | ||
| 2858 | mulq $5, $0, $18 | ||
| 2859 | umulh $5, $0, $20 | ||
| 2860 | cmplt $18, $31, $21 | ||
| 2861 | cmplt $20, $31, $27 | ||
| 2862 | addq $18, $18, $18 | ||
| 2863 | addq $20, $20, $20 | ||
| 2864 | addq $20, $21, $20 | ||
| 2865 | addq $22, $27, $22 | ||
| 2866 | addq $23, $18, $23 | ||
| 2867 | addq $8, $20, $8 | ||
| 2868 | cmpult $23, $18, $17 | ||
| 2869 | cmpult $8, $20, $28 | ||
| 2870 | addq $8, $17, $8 | ||
| 2871 | addq $22, $28, $22 | ||
| 2872 | stq $23, 40($16) | ||
| 2873 | bis $31, $31, $23 | ||
| 2874 | mulq $3, $3, $25 | ||
| 2875 | umulh $3, $3, $19 | ||
| 2876 | addq $8, $25, $8 | ||
| 2877 | addq $22, $19, $22 | ||
| 2878 | cmpult $8, $25, $24 | ||
| 2879 | cmpult $22, $19, $21 | ||
| 2880 | addq $22, $24, $22 | ||
| 2881 | addq $23, $21, $23 | ||
| 2882 | mulq $4, $2, $27 | ||
| 2883 | umulh $4, $2, $18 | ||
| 2884 | cmplt $27, $31, $20 | ||
| 2885 | cmplt $18, $31, $17 | ||
| 2886 | addq $27, $27, $27 | ||
| 2887 | addq $18, $18, $18 | ||
| 2888 | addq $18, $20, $18 | ||
| 2889 | addq $23, $17, $23 | ||
| 2890 | addq $8, $27, $8 | ||
| 2891 | addq $22, $18, $22 | ||
| 2892 | cmpult $8, $27, $28 | ||
| 2893 | cmpult $22, $18, $25 | ||
| 2894 | addq $22, $28, $22 | ||
| 2895 | addq $23, $25, $23 | ||
| 2896 | mulq $5, $1, $19 | ||
| 2897 | umulh $5, $1, $24 | ||
| 2898 | cmplt $19, $31, $21 | ||
| 2899 | cmplt $24, $31, $20 | ||
| 2900 | addq $19, $19, $19 | ||
| 2901 | addq $24, $24, $24 | ||
| 2902 | addq $24, $21, $24 | ||
| 2903 | addq $23, $20, $23 | ||
| 2904 | addq $8, $19, $8 | ||
| 2905 | addq $22, $24, $22 | ||
| 2906 | cmpult $8, $19, $17 | ||
| 2907 | cmpult $22, $24, $27 | ||
| 2908 | addq $22, $17, $22 | ||
| 2909 | addq $23, $27, $23 | ||
| 2910 | mulq $6, $0, $18 | ||
| 2911 | umulh $6, $0, $28 | ||
| 2912 | cmplt $18, $31, $25 | ||
| 2913 | cmplt $28, $31, $21 | ||
| 2914 | addq $18, $18, $18 | ||
| 2915 | addq $28, $28, $28 | ||
| 2916 | addq $28, $25, $28 | ||
| 2917 | addq $23, $21, $23 | ||
| 2918 | addq $8, $18, $8 | ||
| 2919 | addq $22, $28, $22 | ||
| 2920 | cmpult $8, $18, $20 | ||
| 2921 | cmpult $22, $28, $19 | ||
| 2922 | addq $22, $20, $22 | ||
| 2923 | addq $23, $19, $23 | ||
| 2924 | stq $8, 48($16) | ||
| 2925 | bis $31, $31, $8 | ||
| 2926 | mulq $4, $3, $24 | ||
| 2927 | umulh $4, $3, $17 | ||
| 2928 | cmplt $24, $31, $27 | ||
| 2929 | cmplt $17, $31, $25 | ||
| 2930 | addq $24, $24, $24 | ||
| 2931 | addq $17, $17, $17 | ||
| 2932 | addq $17, $27, $17 | ||
| 2933 | addq $8, $25, $8 | ||
| 2934 | addq $22, $24, $22 | ||
| 2935 | addq $23, $17, $23 | ||
| 2936 | cmpult $22, $24, $21 | ||
| 2937 | cmpult $23, $17, $18 | ||
| 2938 | addq $23, $21, $23 | ||
| 2939 | addq $8, $18, $8 | ||
| 2940 | mulq $5, $2, $28 | ||
| 2941 | umulh $5, $2, $20 | ||
| 2942 | cmplt $28, $31, $19 | ||
| 2943 | cmplt $20, $31, $27 | ||
| 2944 | addq $28, $28, $28 | ||
| 2945 | addq $20, $20, $20 | ||
| 2946 | addq $20, $19, $20 | ||
| 2947 | addq $8, $27, $8 | ||
| 2948 | addq $22, $28, $22 | ||
| 2949 | addq $23, $20, $23 | ||
| 2950 | cmpult $22, $28, $25 | ||
| 2951 | cmpult $23, $20, $24 | ||
| 2952 | addq $23, $25, $23 | ||
| 2953 | addq $8, $24, $8 | ||
| 2954 | mulq $6, $1, $17 | ||
| 2955 | umulh $6, $1, $21 | ||
| 2956 | cmplt $17, $31, $18 | ||
| 2957 | cmplt $21, $31, $19 | ||
| 2958 | addq $17, $17, $17 | ||
| 2959 | addq $21, $21, $21 | ||
| 2960 | addq $21, $18, $21 | ||
| 2961 | addq $8, $19, $8 | ||
| 2962 | addq $22, $17, $22 | ||
| 2963 | addq $23, $21, $23 | ||
| 2964 | cmpult $22, $17, $27 | ||
| 2965 | cmpult $23, $21, $28 | ||
| 2966 | addq $23, $27, $23 | ||
| 2967 | addq $8, $28, $8 | ||
| 2968 | mulq $7, $0, $20 | ||
| 2969 | umulh $7, $0, $25 | ||
| 2970 | cmplt $20, $31, $24 | ||
| 2971 | cmplt $25, $31, $18 | ||
| 2972 | addq $20, $20, $20 | ||
| 2973 | addq $25, $25, $25 | ||
| 2974 | addq $25, $24, $25 | ||
| 2975 | addq $8, $18, $8 | ||
| 2976 | addq $22, $20, $22 | ||
| 2977 | addq $23, $25, $23 | ||
| 2978 | cmpult $22, $20, $19 | ||
| 2979 | cmpult $23, $25, $17 | ||
| 2980 | addq $23, $19, $23 | ||
| 2981 | addq $8, $17, $8 | ||
| 2982 | stq $22, 56($16) | ||
| 2983 | bis $31, $31, $22 | ||
| 2984 | mulq $4, $4, $21 | ||
| 2985 | umulh $4, $4, $27 | ||
| 2986 | addq $23, $21, $23 | ||
| 2987 | addq $8, $27, $8 | ||
| 2988 | cmpult $23, $21, $28 | ||
| 2989 | cmpult $8, $27, $24 | ||
| 2990 | addq $8, $28, $8 | ||
| 2991 | addq $22, $24, $22 | ||
| 2992 | mulq $5, $3, $18 | ||
| 2993 | umulh $5, $3, $20 | ||
| 2994 | cmplt $18, $31, $25 | ||
| 2995 | cmplt $20, $31, $19 | ||
| 2996 | addq $18, $18, $18 | ||
| 2997 | addq $20, $20, $20 | ||
| 2998 | addq $20, $25, $20 | ||
| 2999 | addq $22, $19, $22 | ||
| 3000 | addq $23, $18, $23 | ||
| 3001 | addq $8, $20, $8 | ||
| 3002 | cmpult $23, $18, $17 | ||
| 3003 | cmpult $8, $20, $21 | ||
| 3004 | addq $8, $17, $8 | ||
| 3005 | addq $22, $21, $22 | ||
| 3006 | mulq $6, $2, $27 | ||
| 3007 | umulh $6, $2, $28 | ||
| 3008 | cmplt $27, $31, $24 | ||
| 3009 | cmplt $28, $31, $25 | ||
| 3010 | addq $27, $27, $27 | ||
| 3011 | addq $28, $28, $28 | ||
| 3012 | addq $28, $24, $28 | ||
| 3013 | addq $22, $25, $22 | ||
| 3014 | addq $23, $27, $23 | ||
| 3015 | addq $8, $28, $8 | ||
| 3016 | cmpult $23, $27, $19 | ||
| 3017 | cmpult $8, $28, $18 | ||
| 3018 | addq $8, $19, $8 | ||
| 3019 | addq $22, $18, $22 | ||
| 3020 | mulq $7, $1, $20 | ||
| 3021 | umulh $7, $1, $17 | ||
| 3022 | cmplt $20, $31, $21 | ||
| 3023 | cmplt $17, $31, $24 | ||
| 3024 | addq $20, $20, $20 | ||
| 3025 | addq $17, $17, $17 | ||
| 3026 | addq $17, $21, $17 | ||
| 3027 | addq $22, $24, $22 | ||
| 3028 | addq $23, $20, $23 | ||
| 3029 | addq $8, $17, $8 | ||
| 3030 | cmpult $23, $20, $25 | ||
| 3031 | cmpult $8, $17, $27 | ||
| 3032 | addq $8, $25, $8 | ||
| 3033 | addq $22, $27, $22 | ||
| 3034 | stq $23, 64($16) | ||
| 3035 | bis $31, $31, $23 | ||
| 3036 | mulq $5, $4, $28 | ||
| 3037 | umulh $5, $4, $19 | ||
| 3038 | cmplt $28, $31, $18 | ||
| 3039 | cmplt $19, $31, $21 | ||
| 3040 | addq $28, $28, $28 | ||
| 3041 | addq $19, $19, $19 | ||
| 3042 | addq $19, $18, $19 | ||
| 3043 | addq $23, $21, $23 | ||
| 3044 | addq $8, $28, $8 | ||
| 3045 | addq $22, $19, $22 | ||
| 3046 | cmpult $8, $28, $24 | ||
| 3047 | cmpult $22, $19, $20 | ||
| 3048 | addq $22, $24, $22 | ||
| 3049 | addq $23, $20, $23 | ||
| 3050 | mulq $6, $3, $17 | ||
| 3051 | umulh $6, $3, $25 | ||
| 3052 | cmplt $17, $31, $27 | ||
| 3053 | cmplt $25, $31, $18 | ||
| 3054 | addq $17, $17, $17 | ||
| 3055 | addq $25, $25, $25 | ||
| 3056 | addq $25, $27, $25 | ||
| 3057 | addq $23, $18, $23 | ||
| 3058 | addq $8, $17, $8 | ||
| 3059 | addq $22, $25, $22 | ||
| 3060 | cmpult $8, $17, $21 | ||
| 3061 | cmpult $22, $25, $28 | ||
| 3062 | addq $22, $21, $22 | ||
| 3063 | addq $23, $28, $23 | ||
| 3064 | mulq $7, $2, $19 | ||
| 3065 | umulh $7, $2, $24 | ||
| 3066 | cmplt $19, $31, $20 | ||
| 3067 | cmplt $24, $31, $27 | ||
| 3068 | addq $19, $19, $19 | ||
| 3069 | addq $24, $24, $24 | ||
| 3070 | addq $24, $20, $24 | ||
| 3071 | addq $23, $27, $23 | ||
| 3072 | addq $8, $19, $8 | ||
| 3073 | addq $22, $24, $22 | ||
| 3074 | cmpult $8, $19, $18 | ||
| 3075 | cmpult $22, $24, $17 | ||
| 3076 | addq $22, $18, $22 | ||
| 3077 | addq $23, $17, $23 | ||
| 3078 | stq $8, 72($16) | ||
| 3079 | bis $31, $31, $8 | ||
| 3080 | mulq $5, $5, $25 | ||
| 3081 | umulh $5, $5, $21 | ||
| 3082 | addq $22, $25, $22 | ||
| 3083 | addq $23, $21, $23 | ||
| 3084 | cmpult $22, $25, $28 | ||
| 3085 | cmpult $23, $21, $20 | ||
| 3086 | addq $23, $28, $23 | ||
| 3087 | addq $8, $20, $8 | ||
| 3088 | mulq $6, $4, $27 | ||
| 3089 | umulh $6, $4, $19 | ||
| 3090 | cmplt $27, $31, $24 | ||
| 3091 | cmplt $19, $31, $18 | ||
| 3092 | addq $27, $27, $27 | ||
| 3093 | addq $19, $19, $19 | ||
| 3094 | addq $19, $24, $19 | ||
| 3095 | addq $8, $18, $8 | ||
| 3096 | addq $22, $27, $22 | ||
| 3097 | addq $23, $19, $23 | ||
| 3098 | cmpult $22, $27, $17 | ||
| 3099 | cmpult $23, $19, $25 | ||
| 3100 | addq $23, $17, $23 | ||
| 3101 | addq $8, $25, $8 | ||
| 3102 | mulq $7, $3, $21 | ||
| 3103 | umulh $7, $3, $28 | ||
| 3104 | cmplt $21, $31, $20 | ||
| 3105 | cmplt $28, $31, $24 | ||
| 3106 | addq $21, $21, $21 | ||
| 3107 | addq $28, $28, $28 | ||
| 3108 | addq $28, $20, $28 | ||
| 3109 | addq $8, $24, $8 | ||
| 3110 | addq $22, $21, $22 | ||
| 3111 | addq $23, $28, $23 | ||
| 3112 | cmpult $22, $21, $18 | ||
| 3113 | cmpult $23, $28, $27 | ||
| 3114 | addq $23, $18, $23 | ||
| 3115 | addq $8, $27, $8 | ||
| 3116 | stq $22, 80($16) | ||
| 3117 | bis $31, $31, $22 | ||
| 3118 | mulq $6, $5, $19 | ||
| 3119 | umulh $6, $5, $17 | ||
| 3120 | cmplt $19, $31, $25 | ||
| 3121 | cmplt $17, $31, $20 | ||
| 3122 | addq $19, $19, $19 | ||
| 3123 | addq $17, $17, $17 | ||
| 3124 | addq $17, $25, $17 | ||
| 3125 | addq $22, $20, $22 | ||
| 3126 | addq $23, $19, $23 | ||
| 3127 | addq $8, $17, $8 | ||
| 3128 | cmpult $23, $19, $24 | ||
| 3129 | cmpult $8, $17, $21 | ||
| 3130 | addq $8, $24, $8 | ||
| 3131 | addq $22, $21, $22 | ||
| 3132 | mulq $7, $4, $28 | ||
| 3133 | umulh $7, $4, $18 | ||
| 3134 | cmplt $28, $31, $27 | ||
| 3135 | cmplt $18, $31, $25 | ||
| 3136 | addq $28, $28, $28 | ||
| 3137 | addq $18, $18, $18 | ||
| 3138 | addq $18, $27, $18 | ||
| 3139 | addq $22, $25, $22 | ||
| 3140 | addq $23, $28, $23 | ||
| 3141 | addq $8, $18, $8 | ||
| 3142 | cmpult $23, $28, $20 | ||
| 3143 | cmpult $8, $18, $19 | ||
| 3144 | addq $8, $20, $8 | ||
| 3145 | addq $22, $19, $22 | ||
| 3146 | stq $23, 88($16) | ||
| 3147 | bis $31, $31, $23 | ||
| 3148 | mulq $6, $6, $17 | ||
| 3149 | umulh $6, $6, $24 | ||
| 3150 | addq $8, $17, $8 | ||
| 3151 | addq $22, $24, $22 | ||
| 3152 | cmpult $8, $17, $21 | ||
| 3153 | cmpult $22, $24, $27 | ||
| 3154 | addq $22, $21, $22 | ||
| 3155 | addq $23, $27, $23 | ||
| 3156 | mulq $7, $5, $25 | ||
| 3157 | umulh $7, $5, $28 | ||
| 3158 | cmplt $25, $31, $18 | ||
| 3159 | cmplt $28, $31, $20 | ||
| 3160 | addq $25, $25, $25 | ||
| 3161 | addq $28, $28, $28 | ||
| 3162 | addq $28, $18, $28 | ||
| 3163 | addq $23, $20, $23 | ||
| 3164 | addq $8, $25, $8 | ||
| 3165 | addq $22, $28, $22 | ||
| 3166 | cmpult $8, $25, $19 | ||
| 3167 | cmpult $22, $28, $17 | ||
| 3168 | addq $22, $19, $22 | ||
| 3169 | addq $23, $17, $23 | ||
| 3170 | stq $8, 96($16) | ||
| 3171 | bis $31, $31, $8 | ||
| 3172 | mulq $7, $6, $24 | ||
| 3173 | umulh $7, $6, $21 | ||
| 3174 | cmplt $24, $31, $27 | ||
| 3175 | cmplt $21, $31, $18 | ||
| 3176 | addq $24, $24, $24 | ||
| 3177 | addq $21, $21, $21 | ||
| 3178 | addq $21, $27, $21 | ||
| 3179 | addq $8, $18, $8 | ||
| 3180 | addq $22, $24, $22 | ||
| 3181 | addq $23, $21, $23 | ||
| 3182 | cmpult $22, $24, $20 | ||
| 3183 | cmpult $23, $21, $25 | ||
| 3184 | addq $23, $20, $23 | ||
| 3185 | addq $8, $25, $8 | ||
| 3186 | stq $22, 104($16) | ||
| 3187 | bis $31, $31, $22 | ||
| 3188 | mulq $7, $7, $28 | ||
| 3189 | umulh $7, $7, $19 | ||
| 3190 | addq $23, $28, $23 | ||
| 3191 | addq $8, $19, $8 | ||
| 3192 | cmpult $23, $28, $17 | ||
| 3193 | cmpult $8, $19, $27 | ||
| 3194 | addq $8, $17, $8 | ||
| 3195 | addq $22, $27, $22 | ||
| 3196 | stq $23, 112($16) | ||
| 3197 | stq $8, 120($16) | ||
| 3198 | ret $31,($26),1 | ||
| 3199 | .end bn_sqr_comba8 | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.s.works b/src/lib/libcrypto/bn/asm/alpha.s.works deleted file mode 100644 index ee6c587809..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.s.works +++ /dev/null | |||
| @@ -1,533 +0,0 @@ | |||
| 1 | |||
| 2 | # DEC Alpha assember | ||
| 3 | # The bn_div64 is actually gcc output but the other parts are hand done. | ||
| 4 | # Thanks to tzeruch@ceddec.com for sending me the gcc output for | ||
| 5 | # bn_div64. | ||
| 6 | # I've gone back and re-done most of routines. | ||
| 7 | # The key thing to remeber for the 164 CPU is that while a | ||
| 8 | # multiply operation takes 8 cycles, another one can only be issued | ||
| 9 | # after 4 cycles have elapsed. I've done modification to help | ||
| 10 | # improve this. Also, normally, a ld instruction will not be available | ||
| 11 | # for about 3 cycles. | ||
| 12 | .file 1 "bn_asm.c" | ||
| 13 | .set noat | ||
| 14 | gcc2_compiled.: | ||
| 15 | __gnu_compiled_c: | ||
| 16 | .text | ||
| 17 | .align 3 | ||
| 18 | .globl bn_mul_add_words | ||
| 19 | .ent bn_mul_add_words | ||
| 20 | bn_mul_add_words: | ||
| 21 | bn_mul_add_words..ng: | ||
| 22 | .frame $30,0,$26,0 | ||
| 23 | .prologue 0 | ||
| 24 | .align 5 | ||
| 25 | subq $18,4,$18 | ||
| 26 | bis $31,$31,$0 | ||
| 27 | blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code | ||
| 28 | ldq $20,0($17) # 1 1 | ||
| 29 | ldq $1,0($16) # 1 1 | ||
| 30 | .align 3 | ||
| 31 | $42: | ||
| 32 | mulq $20,$19,$5 # 1 2 1 ###### | ||
| 33 | ldq $21,8($17) # 2 1 | ||
| 34 | ldq $2,8($16) # 2 1 | ||
| 35 | umulh $20,$19,$20 # 1 2 ###### | ||
| 36 | ldq $27,16($17) # 3 1 | ||
| 37 | ldq $3,16($16) # 3 1 | ||
| 38 | mulq $21,$19,$6 # 2 2 1 ###### | ||
| 39 | ldq $28,24($17) # 4 1 | ||
| 40 | addq $1,$5,$1 # 1 2 2 | ||
| 41 | ldq $4,24($16) # 4 1 | ||
| 42 | umulh $21,$19,$21 # 2 2 ###### | ||
| 43 | cmpult $1,$5,$22 # 1 2 3 1 | ||
| 44 | addq $20,$22,$20 # 1 3 1 | ||
| 45 | addq $1,$0,$1 # 1 2 3 1 | ||
| 46 | mulq $27,$19,$7 # 3 2 1 ###### | ||
| 47 | cmpult $1,$0,$0 # 1 2 3 2 | ||
| 48 | addq $2,$6,$2 # 2 2 2 | ||
| 49 | addq $20,$0,$0 # 1 3 2 | ||
| 50 | cmpult $2,$6,$23 # 2 2 3 1 | ||
| 51 | addq $21,$23,$21 # 2 3 1 | ||
| 52 | umulh $27,$19,$27 # 3 2 ###### | ||
| 53 | addq $2,$0,$2 # 2 2 3 1 | ||
| 54 | cmpult $2,$0,$0 # 2 2 3 2 | ||
| 55 | subq $18,4,$18 | ||
| 56 | mulq $28,$19,$8 # 4 2 1 ###### | ||
| 57 | addq $21,$0,$0 # 2 3 2 | ||
| 58 | addq $3,$7,$3 # 3 2 2 | ||
| 59 | addq $16,32,$16 | ||
| 60 | cmpult $3,$7,$24 # 3 2 3 1 | ||
| 61 | stq $1,-32($16) # 1 2 4 | ||
| 62 | umulh $28,$19,$28 # 4 2 ###### | ||
| 63 | addq $27,$24,$27 # 3 3 1 | ||
| 64 | addq $3,$0,$3 # 3 2 3 1 | ||
| 65 | stq $2,-24($16) # 2 2 4 | ||
| 66 | cmpult $3,$0,$0 # 3 2 3 2 | ||
| 67 | stq $3,-16($16) # 3 2 4 | ||
| 68 | addq $4,$8,$4 # 4 2 2 | ||
| 69 | addq $27,$0,$0 # 3 3 2 | ||
| 70 | cmpult $4,$8,$25 # 4 2 3 1 | ||
| 71 | addq $17,32,$17 | ||
| 72 | addq $28,$25,$28 # 4 3 1 | ||
| 73 | addq $4,$0,$4 # 4 2 3 1 | ||
| 74 | cmpult $4,$0,$0 # 4 2 3 2 | ||
| 75 | stq $4,-8($16) # 4 2 4 | ||
| 76 | addq $28,$0,$0 # 4 3 2 | ||
| 77 | blt $18,$43 | ||
| 78 | |||
| 79 | ldq $20,0($17) # 1 1 | ||
| 80 | ldq $1,0($16) # 1 1 | ||
| 81 | |||
| 82 | br $42 | ||
| 83 | |||
| 84 | .align 4 | ||
| 85 | $45: | ||
| 86 | ldq $20,0($17) # 4 1 | ||
| 87 | ldq $1,0($16) # 4 1 | ||
| 88 | mulq $20,$19,$5 # 4 2 1 | ||
| 89 | subq $18,1,$18 | ||
| 90 | addq $16,8,$16 | ||
| 91 | addq $17,8,$17 | ||
| 92 | umulh $20,$19,$20 # 4 2 | ||
| 93 | addq $1,$5,$1 # 4 2 2 | ||
| 94 | cmpult $1,$5,$22 # 4 2 3 1 | ||
| 95 | addq $20,$22,$20 # 4 3 1 | ||
| 96 | addq $1,$0,$1 # 4 2 3 1 | ||
| 97 | cmpult $1,$0,$0 # 4 2 3 2 | ||
| 98 | addq $20,$0,$0 # 4 3 2 | ||
| 99 | stq $1,-8($16) # 4 2 4 | ||
| 100 | bgt $18,$45 | ||
| 101 | ret $31,($26),1 # else exit | ||
| 102 | |||
| 103 | .align 4 | ||
| 104 | $43: | ||
| 105 | addq $18,4,$18 | ||
| 106 | bgt $18,$45 # goto tail code | ||
| 107 | ret $31,($26),1 # else exit | ||
| 108 | |||
| 109 | .end bn_mul_add_words | ||
| 110 | .align 3 | ||
| 111 | .globl bn_mul_words | ||
| 112 | .ent bn_mul_words | ||
| 113 | bn_mul_words: | ||
| 114 | bn_mul_words..ng: | ||
| 115 | .frame $30,0,$26,0 | ||
| 116 | .prologue 0 | ||
| 117 | .align 5 | ||
| 118 | subq $18,4,$18 | ||
| 119 | bis $31,$31,$0 | ||
| 120 | blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code | ||
| 121 | ldq $20,0($17) # 1 1 | ||
| 122 | .align 3 | ||
| 123 | $142: | ||
| 124 | |||
| 125 | mulq $20,$19,$5 # 1 2 1 ##### | ||
| 126 | ldq $21,8($17) # 2 1 | ||
| 127 | ldq $27,16($17) # 3 1 | ||
| 128 | umulh $20,$19,$20 # 1 2 ##### | ||
| 129 | ldq $28,24($17) # 4 1 | ||
| 130 | mulq $21,$19,$6 # 2 2 1 ##### | ||
| 131 | addq $5,$0,$5 # 1 2 3 1 | ||
| 132 | subq $18,4,$18 | ||
| 133 | cmpult $5,$0,$0 # 1 2 3 2 | ||
| 134 | umulh $21,$19,$21 # 2 2 ##### | ||
| 135 | addq $20,$0,$0 # 1 3 2 | ||
| 136 | addq $17,32,$17 | ||
| 137 | addq $6,$0,$6 # 2 2 3 1 | ||
| 138 | mulq $27,$19,$7 # 3 2 1 ##### | ||
| 139 | cmpult $6,$0,$0 # 2 2 3 2 | ||
| 140 | addq $21,$0,$0 # 2 3 2 | ||
| 141 | addq $16,32,$16 | ||
| 142 | umulh $27,$19,$27 # 3 2 ##### | ||
| 143 | stq $5,-32($16) # 1 2 4 | ||
| 144 | mulq $28,$19,$8 # 4 2 1 ##### | ||
| 145 | addq $7,$0,$7 # 3 2 3 1 | ||
| 146 | stq $6,-24($16) # 2 2 4 | ||
| 147 | cmpult $7,$0,$0 # 3 2 3 2 | ||
| 148 | umulh $28,$19,$28 # 4 2 ##### | ||
| 149 | addq $27,$0,$0 # 3 3 2 | ||
| 150 | stq $7,-16($16) # 3 2 4 | ||
| 151 | addq $8,$0,$8 # 4 2 3 1 | ||
| 152 | cmpult $8,$0,$0 # 4 2 3 2 | ||
| 153 | |||
| 154 | addq $28,$0,$0 # 4 3 2 | ||
| 155 | |||
| 156 | stq $8,-8($16) # 4 2 4 | ||
| 157 | |||
| 158 | blt $18,$143 | ||
| 159 | |||
| 160 | ldq $20,0($17) # 1 1 | ||
| 161 | |||
| 162 | br $142 | ||
| 163 | |||
| 164 | .align 4 | ||
| 165 | $145: | ||
| 166 | ldq $20,0($17) # 4 1 | ||
| 167 | mulq $20,$19,$5 # 4 2 1 | ||
| 168 | subq $18,1,$18 | ||
| 169 | umulh $20,$19,$20 # 4 2 | ||
| 170 | addq $5,$0,$5 # 4 2 3 1 | ||
| 171 | addq $16,8,$16 | ||
| 172 | cmpult $5,$0,$0 # 4 2 3 2 | ||
| 173 | addq $17,8,$17 | ||
| 174 | addq $20,$0,$0 # 4 3 2 | ||
| 175 | stq $5,-8($16) # 4 2 4 | ||
| 176 | |||
| 177 | bgt $18,$145 | ||
| 178 | ret $31,($26),1 # else exit | ||
| 179 | |||
| 180 | .align 4 | ||
| 181 | $143: | ||
| 182 | addq $18,4,$18 | ||
| 183 | bgt $18,$145 # goto tail code | ||
| 184 | ret $31,($26),1 # else exit | ||
| 185 | |||
| 186 | .end bn_mul_words | ||
| 187 | .align 3 | ||
| 188 | .globl bn_sqr_words | ||
| 189 | .ent bn_sqr_words | ||
| 190 | bn_sqr_words: | ||
| 191 | bn_sqr_words..ng: | ||
| 192 | .frame $30,0,$26,0 | ||
| 193 | .prologue 0 | ||
| 194 | |||
| 195 | subq $18,4,$18 | ||
| 196 | blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code | ||
| 197 | ldq $20,0($17) # 1 1 | ||
| 198 | .align 3 | ||
| 199 | $542: | ||
| 200 | mulq $20,$20,$5 ###### | ||
| 201 | ldq $21,8($17) # 1 1 | ||
| 202 | subq $18,4 | ||
| 203 | umulh $20,$20,$1 ###### | ||
| 204 | ldq $27,16($17) # 1 1 | ||
| 205 | mulq $21,$21,$6 ###### | ||
| 206 | ldq $28,24($17) # 1 1 | ||
| 207 | stq $5,0($16) # r[0] | ||
| 208 | umulh $21,$21,$2 ###### | ||
| 209 | stq $1,8($16) # r[1] | ||
| 210 | mulq $27,$27,$7 ###### | ||
| 211 | stq $6,16($16) # r[0] | ||
| 212 | umulh $27,$27,$3 ###### | ||
| 213 | stq $2,24($16) # r[1] | ||
| 214 | mulq $28,$28,$8 ###### | ||
| 215 | stq $7,32($16) # r[0] | ||
| 216 | umulh $28,$28,$4 ###### | ||
| 217 | stq $3,40($16) # r[1] | ||
| 218 | |||
| 219 | addq $16,64,$16 | ||
| 220 | addq $17,32,$17 | ||
| 221 | stq $8,-16($16) # r[0] | ||
| 222 | stq $4,-8($16) # r[1] | ||
| 223 | |||
| 224 | blt $18,$543 | ||
| 225 | ldq $20,0($17) # 1 1 | ||
| 226 | br $542 | ||
| 227 | |||
| 228 | $442: | ||
| 229 | ldq $20,0($17) # a[0] | ||
| 230 | mulq $20,$20,$5 # a[0]*w low part r2 | ||
| 231 | addq $16,16,$16 | ||
| 232 | addq $17,8,$17 | ||
| 233 | subq $18,1,$18 | ||
| 234 | umulh $20,$20,$1 # a[0]*w high part r3 | ||
| 235 | stq $5,-16($16) # r[0] | ||
| 236 | stq $1,-8($16) # r[1] | ||
| 237 | |||
| 238 | bgt $18,$442 | ||
| 239 | ret $31,($26),1 # else exit | ||
| 240 | |||
| 241 | .align 4 | ||
| 242 | $543: | ||
| 243 | addq $18,4,$18 | ||
| 244 | bgt $18,$442 # goto tail code | ||
| 245 | ret $31,($26),1 # else exit | ||
| 246 | .end bn_sqr_words | ||
| 247 | |||
| 248 | .align 3 | ||
| 249 | .globl bn_add_words | ||
| 250 | .ent bn_add_words | ||
| 251 | bn_add_words: | ||
| 252 | bn_add_words..ng: | ||
| 253 | .frame $30,0,$26,0 | ||
| 254 | .prologue 0 | ||
| 255 | |||
| 256 | subq $19,4,$19 | ||
| 257 | bis $31,$31,$0 # carry = 0 | ||
| 258 | blt $19,$900 | ||
| 259 | ldq $5,0($17) # a[0] | ||
| 260 | ldq $1,0($18) # b[1] | ||
| 261 | .align 3 | ||
| 262 | $901: | ||
| 263 | addq $1,$5,$1 # r=a+b; | ||
| 264 | ldq $6,8($17) # a[1] | ||
| 265 | cmpult $1,$5,$22 # did we overflow? | ||
| 266 | ldq $2,8($18) # b[1] | ||
| 267 | addq $1,$0,$1 # c+= overflow | ||
| 268 | ldq $7,16($17) # a[2] | ||
| 269 | cmpult $1,$0,$0 # overflow? | ||
| 270 | ldq $3,16($18) # b[2] | ||
| 271 | addq $0,$22,$0 | ||
| 272 | ldq $8,24($17) # a[3] | ||
| 273 | addq $2,$6,$2 # r=a+b; | ||
| 274 | ldq $4,24($18) # b[3] | ||
| 275 | cmpult $2,$6,$23 # did we overflow? | ||
| 276 | addq $3,$7,$3 # r=a+b; | ||
| 277 | addq $2,$0,$2 # c+= overflow | ||
| 278 | cmpult $3,$7,$24 # did we overflow? | ||
| 279 | cmpult $2,$0,$0 # overflow? | ||
| 280 | addq $4,$8,$4 # r=a+b; | ||
| 281 | addq $0,$23,$0 | ||
| 282 | cmpult $4,$8,$25 # did we overflow? | ||
| 283 | addq $3,$0,$3 # c+= overflow | ||
| 284 | stq $1,0($16) # r[0]=c | ||
| 285 | cmpult $3,$0,$0 # overflow? | ||
| 286 | stq $2,8($16) # r[1]=c | ||
| 287 | addq $0,$24,$0 | ||
| 288 | stq $3,16($16) # r[2]=c | ||
| 289 | addq $4,$0,$4 # c+= overflow | ||
| 290 | subq $19,4,$19 # loop-- | ||
| 291 | cmpult $4,$0,$0 # overflow? | ||
| 292 | addq $17,32,$17 # a++ | ||
| 293 | addq $0,$25,$0 | ||
| 294 | stq $4,24($16) # r[3]=c | ||
| 295 | addq $18,32,$18 # b++ | ||
| 296 | addq $16,32,$16 # r++ | ||
| 297 | |||
| 298 | blt $19,$900 | ||
| 299 | ldq $5,0($17) # a[0] | ||
| 300 | ldq $1,0($18) # b[1] | ||
| 301 | br $901 | ||
| 302 | .align 4 | ||
| 303 | $945: | ||
| 304 | ldq $5,0($17) # a[0] | ||
| 305 | ldq $1,0($18) # b[1] | ||
| 306 | addq $1,$5,$1 # r=a+b; | ||
| 307 | subq $19,1,$19 # loop-- | ||
| 308 | addq $1,$0,$1 # c+= overflow | ||
| 309 | addq $17,8,$17 # a++ | ||
| 310 | cmpult $1,$5,$22 # did we overflow? | ||
| 311 | cmpult $1,$0,$0 # overflow? | ||
| 312 | addq $18,8,$18 # b++ | ||
| 313 | stq $1,0($16) # r[0]=c | ||
| 314 | addq $0,$22,$0 | ||
| 315 | addq $16,8,$16 # r++ | ||
| 316 | |||
| 317 | bgt $19,$945 | ||
| 318 | ret $31,($26),1 # else exit | ||
| 319 | |||
| 320 | $900: | ||
| 321 | addq $19,4,$19 | ||
| 322 | bgt $19,$945 # goto tail code | ||
| 323 | ret $31,($26),1 # else exit | ||
| 324 | .end bn_add_words | ||
| 325 | |||
| 326 | # | ||
| 327 | # What follows was taken directly from the C compiler with a few | ||
| 328 | # hacks to redo the lables. | ||
| 329 | # | ||
| 330 | .text | ||
| 331 | .align 3 | ||
| 332 | .globl bn_div64 | ||
| 333 | .ent bn_div64 | ||
| 334 | bn_div64: | ||
| 335 | ldgp $29,0($27) | ||
| 336 | bn_div64..ng: | ||
| 337 | lda $30,-48($30) | ||
| 338 | .frame $30,48,$26,0 | ||
| 339 | stq $26,0($30) | ||
| 340 | stq $9,8($30) | ||
| 341 | stq $10,16($30) | ||
| 342 | stq $11,24($30) | ||
| 343 | stq $12,32($30) | ||
| 344 | stq $13,40($30) | ||
| 345 | .mask 0x4003e00,-48 | ||
| 346 | .prologue 1 | ||
| 347 | bis $16,$16,$9 | ||
| 348 | bis $17,$17,$10 | ||
| 349 | bis $18,$18,$11 | ||
| 350 | bis $31,$31,$13 | ||
| 351 | bis $31,2,$12 | ||
| 352 | bne $11,$119 | ||
| 353 | lda $0,-1 | ||
| 354 | br $31,$136 | ||
| 355 | .align 4 | ||
| 356 | $119: | ||
| 357 | bis $11,$11,$16 | ||
| 358 | jsr $26,BN_num_bits_word | ||
| 359 | ldgp $29,0($26) | ||
| 360 | subq $0,64,$1 | ||
| 361 | beq $1,$120 | ||
| 362 | bis $31,1,$1 | ||
| 363 | sll $1,$0,$1 | ||
| 364 | cmpule $9,$1,$1 | ||
| 365 | bne $1,$120 | ||
| 366 | # lda $16,_IO_stderr_ | ||
| 367 | # lda $17,$C32 | ||
| 368 | # bis $0,$0,$18 | ||
| 369 | # jsr $26,fprintf | ||
| 370 | # ldgp $29,0($26) | ||
| 371 | jsr $26,abort | ||
| 372 | ldgp $29,0($26) | ||
| 373 | .align 4 | ||
| 374 | $120: | ||
| 375 | bis $31,64,$3 | ||
| 376 | cmpult $9,$11,$2 | ||
| 377 | subq $3,$0,$1 | ||
| 378 | addl $1,$31,$0 | ||
| 379 | subq $9,$11,$1 | ||
| 380 | cmoveq $2,$1,$9 | ||
| 381 | beq $0,$122 | ||
| 382 | zapnot $0,15,$2 | ||
| 383 | subq $3,$0,$1 | ||
| 384 | sll $11,$2,$11 | ||
| 385 | sll $9,$2,$3 | ||
| 386 | srl $10,$1,$1 | ||
| 387 | sll $10,$2,$10 | ||
| 388 | bis $3,$1,$9 | ||
| 389 | $122: | ||
| 390 | srl $11,32,$5 | ||
| 391 | zapnot $11,15,$6 | ||
| 392 | lda $7,-1 | ||
| 393 | .align 5 | ||
| 394 | $123: | ||
| 395 | srl $9,32,$1 | ||
| 396 | subq $1,$5,$1 | ||
| 397 | bne $1,$126 | ||
| 398 | zapnot $7,15,$27 | ||
| 399 | br $31,$127 | ||
| 400 | .align 4 | ||
| 401 | $126: | ||
| 402 | bis $9,$9,$24 | ||
| 403 | bis $5,$5,$25 | ||
| 404 | divqu $24,$25,$27 | ||
| 405 | $127: | ||
| 406 | srl $10,32,$4 | ||
| 407 | .align 5 | ||
| 408 | $128: | ||
| 409 | mulq $27,$5,$1 | ||
| 410 | subq $9,$1,$3 | ||
| 411 | zapnot $3,240,$1 | ||
| 412 | bne $1,$129 | ||
| 413 | mulq $6,$27,$2 | ||
| 414 | sll $3,32,$1 | ||
| 415 | addq $1,$4,$1 | ||
| 416 | cmpule $2,$1,$2 | ||
| 417 | bne $2,$129 | ||
| 418 | subq $27,1,$27 | ||
| 419 | br $31,$128 | ||
| 420 | .align 4 | ||
| 421 | $129: | ||
| 422 | mulq $27,$6,$1 | ||
| 423 | mulq $27,$5,$4 | ||
| 424 | srl $1,32,$3 | ||
| 425 | sll $1,32,$1 | ||
| 426 | addq $4,$3,$4 | ||
| 427 | cmpult $10,$1,$2 | ||
| 428 | subq $10,$1,$10 | ||
| 429 | addq $2,$4,$2 | ||
| 430 | cmpult $9,$2,$1 | ||
| 431 | bis $2,$2,$4 | ||
| 432 | beq $1,$134 | ||
| 433 | addq $9,$11,$9 | ||
| 434 | subq $27,1,$27 | ||
| 435 | $134: | ||
| 436 | subl $12,1,$12 | ||
| 437 | subq $9,$4,$9 | ||
| 438 | beq $12,$124 | ||
| 439 | sll $27,32,$13 | ||
| 440 | sll $9,32,$2 | ||
| 441 | srl $10,32,$1 | ||
| 442 | sll $10,32,$10 | ||
| 443 | bis $2,$1,$9 | ||
| 444 | br $31,$123 | ||
| 445 | .align 4 | ||
| 446 | $124: | ||
| 447 | bis $13,$27,$0 | ||
| 448 | $136: | ||
| 449 | ldq $26,0($30) | ||
| 450 | ldq $9,8($30) | ||
| 451 | ldq $10,16($30) | ||
| 452 | ldq $11,24($30) | ||
| 453 | ldq $12,32($30) | ||
| 454 | ldq $13,40($30) | ||
| 455 | addq $30,48,$30 | ||
| 456 | ret $31,($26),1 | ||
| 457 | .end bn_div64 | ||
| 458 | |||
| 459 | .set noat | ||
| 460 | .text | ||
| 461 | .align 3 | ||
| 462 | .globl bn_sub_words | ||
| 463 | .ent bn_sub_words | ||
| 464 | bn_sub_words: | ||
| 465 | bn_sub_words..ng: | ||
| 466 | .frame $30,0,$26,0 | ||
| 467 | .prologue 0 | ||
| 468 | |||
| 469 | subq $19, 4, $19 | ||
| 470 | bis $31, $31, $0 | ||
| 471 | blt $19, $100 | ||
| 472 | ldq $1, 0($17) | ||
| 473 | ldq $2, 0($18) | ||
| 474 | $101: | ||
| 475 | ldq $3, 8($17) | ||
| 476 | cmpult $1, $2, $4 | ||
| 477 | ldq $5, 8($18) | ||
| 478 | subq $1, $2, $1 | ||
| 479 | ldq $6, 16($17) | ||
| 480 | cmpult $1, $0, $2 | ||
| 481 | ldq $7, 16($18) | ||
| 482 | subq $1, $0, $23 | ||
| 483 | ldq $8, 24($17) | ||
| 484 | addq $2, $4, $0 | ||
| 485 | cmpult $3, $5, $24 | ||
| 486 | subq $3, $5, $3 | ||
| 487 | ldq $22, 24($18) | ||
| 488 | cmpult $3, $0, $5 | ||
| 489 | subq $3, $0, $25 | ||
| 490 | addq $5, $24, $0 | ||
| 491 | cmpult $6, $7, $27 | ||
| 492 | subq $6, $7, $6 | ||
| 493 | stq $23, 0($16) | ||
| 494 | cmpult $6, $0, $7 | ||
| 495 | subq $6, $0, $28 | ||
| 496 | addq $7, $27, $0 | ||
| 497 | cmpult $8, $22, $21 | ||
| 498 | subq $8, $22, $8 | ||
| 499 | stq $25, 8($16) | ||
| 500 | cmpult $8, $0, $22 | ||
| 501 | subq $8, $0, $20 | ||
| 502 | addq $22, $21, $0 | ||
| 503 | stq $28, 16($16) | ||
| 504 | subq $19, 4, $19 | ||
| 505 | stq $20, 24($16) | ||
| 506 | addq $17, 32, $17 | ||
| 507 | addq $18, 32, $18 | ||
| 508 | addq $16, 32, $16 | ||
| 509 | blt $19, $100 | ||
| 510 | ldq $1, 0($17) | ||
| 511 | ldq $2, 0($18) | ||
| 512 | br $101 | ||
| 513 | $102: | ||
| 514 | ldq $1, 0($17) | ||
| 515 | ldq $2, 0($18) | ||
| 516 | cmpult $1, $2, $27 | ||
| 517 | subq $1, $2, $1 | ||
| 518 | cmpult $1, $0, $2 | ||
| 519 | subq $1, $0, $1 | ||
| 520 | stq $1, 0($16) | ||
| 521 | addq $2, $27, $0 | ||
| 522 | addq $17, 8, $17 | ||
| 523 | addq $18, 8, $18 | ||
| 524 | addq $16, 8, $16 | ||
| 525 | subq $19, 1, $19 | ||
| 526 | bgt $19, $102 | ||
| 527 | ret $31,($26),1 | ||
| 528 | $100: | ||
| 529 | addq $19, 4, $19 | ||
| 530 | bgt $19, $102 | ||
| 531 | $103: | ||
| 532 | ret $31,($26),1 | ||
| 533 | .end bn_sub_words | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/add.pl b/src/lib/libcrypto/bn/asm/alpha.works/add.pl deleted file mode 100644 index 4dc76e6b69..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.works/add.pl +++ /dev/null | |||
| @@ -1,119 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_add_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local($cc,$a,$b,$r); | ||
| 8 | |||
| 9 | &init_pool(4); | ||
| 10 | ($cc)=GR("r0"); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $bp=&wparam(2); | ||
| 15 | $count=&wparam(3); | ||
| 16 | |||
| 17 | &function_begin($name,""); | ||
| 18 | |||
| 19 | &comment(""); | ||
| 20 | &sub($count,4,$count); | ||
| 21 | &mov("zero",$cc); | ||
| 22 | &br(&label("finish")); | ||
| 23 | &blt($count,&label("finish")); | ||
| 24 | |||
| 25 | ($a0,$b0)=&NR(2); | ||
| 26 | &ld($a0,&QWPw(0,$ap)); | ||
| 27 | &ld($b0,&QWPw(0,$bp)); | ||
| 28 | |||
| 29 | ########################################################## | ||
| 30 | &set_label("loop"); | ||
| 31 | |||
| 32 | ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap)); | ||
| 33 | ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp)); | ||
| 34 | ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap)); | ||
| 35 | ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp)); | ||
| 36 | ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap)); | ||
| 37 | ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp)); | ||
| 38 | |||
| 39 | ($o0,$t0)=&NR(2); | ||
| 40 | &add($a0,$b0,$o0); | ||
| 41 | &cmpult($o0,$b0,$t0); | ||
| 42 | &add($o0,$cc,$o0); | ||
| 43 | &cmpult($o0,$cc,$cc); | ||
| 44 | &add($cc,$t0,$cc); &FR($t0); | ||
| 45 | |||
| 46 | ($t1,$o1)=&NR(2); | ||
| 47 | |||
| 48 | &add($a1,$b1,$o1); &FR($a1); | ||
| 49 | &cmpult($o1,$b1,$t1); &FR($b1); | ||
| 50 | &add($o1,$cc,$o1); | ||
| 51 | &cmpult($o1,$cc,$cc); | ||
| 52 | &add($cc,$t1,$cc); &FR($t1); | ||
| 53 | |||
| 54 | ($t2,$o2)=&NR(2); | ||
| 55 | |||
| 56 | &add($a2,$b2,$o2); &FR($a2); | ||
| 57 | &cmpult($o2,$b2,$t2); &FR($b2); | ||
| 58 | &add($o2,$cc,$o2); | ||
| 59 | &cmpult($o2,$cc,$cc); | ||
| 60 | &add($cc,$t2,$cc); &FR($t2); | ||
| 61 | |||
| 62 | ($t3,$o3)=&NR(2); | ||
| 63 | |||
| 64 | &add($a3,$b3,$o3); &FR($a3); | ||
| 65 | &cmpult($o3,$b3,$t3); &FR($b3); | ||
| 66 | &add($o3,$cc,$o3); | ||
| 67 | &cmpult($o3,$cc,$cc); | ||
| 68 | &add($cc,$t3,$cc); &FR($t3); | ||
| 69 | |||
| 70 | &st($o0,&QWPw(0,$rp)); &FR($o0); | ||
| 71 | &st($o1,&QWPw(0,$rp)); &FR($o1); | ||
| 72 | &st($o2,&QWPw(0,$rp)); &FR($o2); | ||
| 73 | &st($o3,&QWPw(0,$rp)); &FR($o3); | ||
| 74 | |||
| 75 | &sub($count,4,$count); # count-=4 | ||
| 76 | &add($ap,4*$QWS,$ap); # count+=4 | ||
| 77 | &add($bp,4*$QWS,$bp); # count+=4 | ||
| 78 | &add($rp,4*$QWS,$rp); # count+=4 | ||
| 79 | |||
| 80 | &blt($count,&label("finish")); | ||
| 81 | &ld($a0,&QWPw(0,$ap)); | ||
| 82 | &ld($b0,&QWPw(0,$bp)); | ||
| 83 | &br(&label("loop")); | ||
| 84 | ################################################## | ||
| 85 | # Do the last 0..3 words | ||
| 86 | |||
| 87 | ($t0,$o0)=&NR(2); | ||
| 88 | &set_label("last_loop"); | ||
| 89 | |||
| 90 | &ld($a0,&QWPw(0,$ap)); # get a | ||
| 91 | &ld($b0,&QWPw(0,$bp)); # get b | ||
| 92 | |||
| 93 | &add($a0,$b0,$o0); | ||
| 94 | &cmpult($o0,$b0,$t0); # will we borrow? | ||
| 95 | &add($o0,$cc,$o0); # will we borrow? | ||
| 96 | &cmpult($o0,$cc,$cc); # will we borrow? | ||
| 97 | &add($cc,$t0,$cc); # add the borrows | ||
| 98 | &st($o0,&QWPw(0,$rp)); # save | ||
| 99 | |||
| 100 | &add($ap,$QWS,$ap); | ||
| 101 | &add($bp,$QWS,$bp); | ||
| 102 | &add($rp,$QWS,$rp); | ||
| 103 | &sub($count,1,$count); | ||
| 104 | &bgt($count,&label("last_loop")); | ||
| 105 | &function_end_A($name); | ||
| 106 | |||
| 107 | ###################################################### | ||
| 108 | &set_label("finish"); | ||
| 109 | &add($count,4,$count); | ||
| 110 | &bgt($count,&label("last_loop")); | ||
| 111 | |||
| 112 | &FR($o0,$t0,$a0,$b0); | ||
| 113 | &set_label("end"); | ||
| 114 | &function_end($name); | ||
| 115 | |||
| 116 | &fin_pool; | ||
| 117 | } | ||
| 118 | |||
| 119 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/div.pl b/src/lib/libcrypto/bn/asm/alpha.works/div.pl deleted file mode 100644 index 7ec144377f..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.works/div.pl +++ /dev/null | |||
| @@ -1,144 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | sub bn_div64 | ||
| 4 | { | ||
| 5 | local($data)=<<'EOF'; | ||
| 6 | # | ||
| 7 | # What follows was taken directly from the C compiler with a few | ||
| 8 | # hacks to redo the lables. | ||
| 9 | # | ||
| 10 | .text | ||
| 11 | .set noreorder | ||
| 12 | .set volatile | ||
| 13 | .align 3 | ||
| 14 | .globl bn_div64 | ||
| 15 | .ent bn_div64 | ||
| 16 | bn_div64: | ||
| 17 | ldgp $29,0($27) | ||
| 18 | bn_div64..ng: | ||
| 19 | lda $30,-48($30) | ||
| 20 | .frame $30,48,$26,0 | ||
| 21 | stq $26,0($30) | ||
| 22 | stq $9,8($30) | ||
| 23 | stq $10,16($30) | ||
| 24 | stq $11,24($30) | ||
| 25 | stq $12,32($30) | ||
| 26 | stq $13,40($30) | ||
| 27 | .mask 0x4003e00,-48 | ||
| 28 | .prologue 1 | ||
| 29 | bis $16,$16,$9 | ||
| 30 | bis $17,$17,$10 | ||
| 31 | bis $18,$18,$11 | ||
| 32 | bis $31,$31,$13 | ||
| 33 | bis $31,2,$12 | ||
| 34 | bne $11,$9119 | ||
| 35 | lda $0,-1 | ||
| 36 | br $31,$9136 | ||
| 37 | .align 4 | ||
| 38 | $9119: | ||
| 39 | bis $11,$11,$16 | ||
| 40 | jsr $26,BN_num_bits_word | ||
| 41 | ldgp $29,0($26) | ||
| 42 | subq $0,64,$1 | ||
| 43 | beq $1,$9120 | ||
| 44 | bis $31,1,$1 | ||
| 45 | sll $1,$0,$1 | ||
| 46 | cmpule $9,$1,$1 | ||
| 47 | bne $1,$9120 | ||
| 48 | # lda $16,_IO_stderr_ | ||
| 49 | # lda $17,$C32 | ||
| 50 | # bis $0,$0,$18 | ||
| 51 | # jsr $26,fprintf | ||
| 52 | # ldgp $29,0($26) | ||
| 53 | jsr $26,abort | ||
| 54 | ldgp $29,0($26) | ||
| 55 | .align 4 | ||
| 56 | $9120: | ||
| 57 | bis $31,64,$3 | ||
| 58 | cmpult $9,$11,$2 | ||
| 59 | subq $3,$0,$1 | ||
| 60 | addl $1,$31,$0 | ||
| 61 | subq $9,$11,$1 | ||
| 62 | cmoveq $2,$1,$9 | ||
| 63 | beq $0,$9122 | ||
| 64 | zapnot $0,15,$2 | ||
| 65 | subq $3,$0,$1 | ||
| 66 | sll $11,$2,$11 | ||
| 67 | sll $9,$2,$3 | ||
| 68 | srl $10,$1,$1 | ||
| 69 | sll $10,$2,$10 | ||
| 70 | bis $3,$1,$9 | ||
| 71 | $9122: | ||
| 72 | srl $11,32,$5 | ||
| 73 | zapnot $11,15,$6 | ||
| 74 | lda $7,-1 | ||
| 75 | .align 5 | ||
| 76 | $9123: | ||
| 77 | srl $9,32,$1 | ||
| 78 | subq $1,$5,$1 | ||
| 79 | bne $1,$9126 | ||
| 80 | zapnot $7,15,$27 | ||
| 81 | br $31,$9127 | ||
| 82 | .align 4 | ||
| 83 | $9126: | ||
| 84 | bis $9,$9,$24 | ||
| 85 | bis $5,$5,$25 | ||
| 86 | divqu $24,$25,$27 | ||
| 87 | $9127: | ||
| 88 | srl $10,32,$4 | ||
| 89 | .align 5 | ||
| 90 | $9128: | ||
| 91 | mulq $27,$5,$1 | ||
| 92 | subq $9,$1,$3 | ||
| 93 | zapnot $3,240,$1 | ||
| 94 | bne $1,$9129 | ||
| 95 | mulq $6,$27,$2 | ||
| 96 | sll $3,32,$1 | ||
| 97 | addq $1,$4,$1 | ||
| 98 | cmpule $2,$1,$2 | ||
| 99 | bne $2,$9129 | ||
| 100 | subq $27,1,$27 | ||
| 101 | br $31,$9128 | ||
| 102 | .align 4 | ||
| 103 | $9129: | ||
| 104 | mulq $27,$6,$1 | ||
| 105 | mulq $27,$5,$4 | ||
| 106 | srl $1,32,$3 | ||
| 107 | sll $1,32,$1 | ||
| 108 | addq $4,$3,$4 | ||
| 109 | cmpult $10,$1,$2 | ||
| 110 | subq $10,$1,$10 | ||
| 111 | addq $2,$4,$2 | ||
| 112 | cmpult $9,$2,$1 | ||
| 113 | bis $2,$2,$4 | ||
| 114 | beq $1,$9134 | ||
| 115 | addq $9,$11,$9 | ||
| 116 | subq $27,1,$27 | ||
| 117 | $9134: | ||
| 118 | subl $12,1,$12 | ||
| 119 | subq $9,$4,$9 | ||
| 120 | beq $12,$9124 | ||
| 121 | sll $27,32,$13 | ||
| 122 | sll $9,32,$2 | ||
| 123 | srl $10,32,$1 | ||
| 124 | sll $10,32,$10 | ||
| 125 | bis $2,$1,$9 | ||
| 126 | br $31,$9123 | ||
| 127 | .align 4 | ||
| 128 | $9124: | ||
| 129 | bis $13,$27,$0 | ||
| 130 | $9136: | ||
| 131 | ldq $26,0($30) | ||
| 132 | ldq $9,8($30) | ||
| 133 | ldq $10,16($30) | ||
| 134 | ldq $11,24($30) | ||
| 135 | ldq $12,32($30) | ||
| 136 | ldq $13,40($30) | ||
| 137 | addq $30,48,$30 | ||
| 138 | ret $31,($26),1 | ||
| 139 | .end bn_div64 | ||
| 140 | EOF | ||
| 141 | &asm_add($data); | ||
| 142 | } | ||
| 143 | |||
| 144 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul.pl deleted file mode 100644 index b182bae452..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.works/mul.pl +++ /dev/null | |||
| @@ -1,116 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_mul_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local($cc,$a,$b,$r,$couny); | ||
| 8 | |||
| 9 | &init_pool(4); | ||
| 10 | ($cc)=GR("r0"); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $count=&wparam(2); | ||
| 15 | $word=&wparam(3); | ||
| 16 | |||
| 17 | &function_begin($name,""); | ||
| 18 | |||
| 19 | &comment(""); | ||
| 20 | &sub($count,4,$count); | ||
| 21 | &mov("zero",$cc); | ||
| 22 | &br(&label("finish")); | ||
| 23 | &blt($count,&label("finish")); | ||
| 24 | |||
| 25 | ($a0,$r0)=&NR(2); | ||
| 26 | &ld($a0,&QWPw(0,$ap)); | ||
| 27 | &ld($r0,&QWPw(0,$rp)); | ||
| 28 | |||
| 29 | $a=<<'EOF'; | ||
| 30 | ########################################################## | ||
| 31 | &set_label("loop"); | ||
| 32 | |||
| 33 | ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap)); | ||
| 34 | ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp)); | ||
| 35 | ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap)); | ||
| 36 | ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp)); | ||
| 37 | ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap)); | ||
| 38 | ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp)); | ||
| 39 | |||
| 40 | ($o0,$t0)=&NR(2); | ||
| 41 | &add($a0,$b0,$o0); | ||
| 42 | &cmpult($o0,$b0,$t0); | ||
| 43 | &add($o0,$cc,$o0); | ||
| 44 | &cmpult($o0,$cc,$cc); | ||
| 45 | &add($cc,$t0,$cc); &FR($t0); | ||
| 46 | |||
| 47 | ($t1,$o1)=&NR(2); | ||
| 48 | |||
| 49 | &add($a1,$b1,$o1); &FR($a1); | ||
| 50 | &cmpult($o1,$b1,$t1); &FR($b1); | ||
| 51 | &add($o1,$cc,$o1); | ||
| 52 | &cmpult($o1,$cc,$cc); | ||
| 53 | &add($cc,$t1,$cc); &FR($t1); | ||
| 54 | |||
| 55 | ($t2,$o2)=&NR(2); | ||
| 56 | |||
| 57 | &add($a2,$b2,$o2); &FR($a2); | ||
| 58 | &cmpult($o2,$b2,$t2); &FR($b2); | ||
| 59 | &add($o2,$cc,$o2); | ||
| 60 | &cmpult($o2,$cc,$cc); | ||
| 61 | &add($cc,$t2,$cc); &FR($t2); | ||
| 62 | |||
| 63 | ($t3,$o3)=&NR(2); | ||
| 64 | |||
| 65 | &add($a3,$b3,$o3); &FR($a3); | ||
| 66 | &cmpult($o3,$b3,$t3); &FR($b3); | ||
| 67 | &add($o3,$cc,$o3); | ||
| 68 | &cmpult($o3,$cc,$cc); | ||
| 69 | &add($cc,$t3,$cc); &FR($t3); | ||
| 70 | |||
| 71 | &st($o0,&QWPw(0,$rp)); &FR($o0); | ||
| 72 | &st($o1,&QWPw(0,$rp)); &FR($o1); | ||
| 73 | &st($o2,&QWPw(0,$rp)); &FR($o2); | ||
| 74 | &st($o3,&QWPw(0,$rp)); &FR($o3); | ||
| 75 | |||
| 76 | &sub($count,4,$count); # count-=4 | ||
| 77 | &add($ap,4*$QWS,$ap); # count+=4 | ||
| 78 | &add($bp,4*$QWS,$bp); # count+=4 | ||
| 79 | &add($rp,4*$QWS,$rp); # count+=4 | ||
| 80 | |||
| 81 | &blt($count,&label("finish")); | ||
| 82 | &ld($a0,&QWPw(0,$ap)); | ||
| 83 | &ld($b0,&QWPw(0,$bp)); | ||
| 84 | &br(&label("loop")); | ||
| 85 | EOF | ||
| 86 | ################################################## | ||
| 87 | # Do the last 0..3 words | ||
| 88 | |||
| 89 | &set_label("last_loop"); | ||
| 90 | |||
| 91 | &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a | ||
| 92 | &mul($a0,$word,($l0)=&NR(1)); | ||
| 93 | &add($ap,$QWS,$ap); | ||
| 94 | &muh($a0,$word,($h0)=&NR(1)); &FR($a0); | ||
| 95 | &add($l0,$cc,$l0); | ||
| 96 | &add($rp,$QWS,$rp); | ||
| 97 | &sub($count,1,$count); | ||
| 98 | &cmpult($l0,$cc,$cc); | ||
| 99 | &st($l0,&QWPw(-1,$rp)); &FR($l0); | ||
| 100 | &add($h0,$cc,$cc); &FR($h0); | ||
| 101 | |||
| 102 | &bgt($count,&label("last_loop")); | ||
| 103 | &function_end_A($name); | ||
| 104 | |||
| 105 | ###################################################### | ||
| 106 | &set_label("finish"); | ||
| 107 | &add($count,4,$count); | ||
| 108 | &bgt($count,&label("last_loop")); | ||
| 109 | |||
| 110 | &set_label("end"); | ||
| 111 | &function_end($name); | ||
| 112 | |||
| 113 | &fin_pool; | ||
| 114 | } | ||
| 115 | |||
| 116 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_add.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_add.pl deleted file mode 100644 index e37f6315fb..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.works/mul_add.pl +++ /dev/null | |||
| @@ -1,120 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_mul_add_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local($cc,$a,$b,$r,$couny); | ||
| 8 | |||
| 9 | &init_pool(4); | ||
| 10 | ($cc)=GR("r0"); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $count=&wparam(2); | ||
| 15 | $word=&wparam(3); | ||
| 16 | |||
| 17 | &function_begin($name,""); | ||
| 18 | |||
| 19 | &comment(""); | ||
| 20 | &sub($count,4,$count); | ||
| 21 | &mov("zero",$cc); | ||
| 22 | &br(&label("finish")); | ||
| 23 | &blt($count,&label("finish")); | ||
| 24 | |||
| 25 | ($a0,$r0)=&NR(2); | ||
| 26 | &ld($a0,&QWPw(0,$ap)); | ||
| 27 | &ld($r0,&QWPw(0,$rp)); | ||
| 28 | |||
| 29 | $a=<<'EOF'; | ||
| 30 | ########################################################## | ||
| 31 | &set_label("loop"); | ||
| 32 | |||
| 33 | ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap)); | ||
| 34 | ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp)); | ||
| 35 | ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap)); | ||
| 36 | ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp)); | ||
| 37 | ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap)); | ||
| 38 | ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp)); | ||
| 39 | |||
| 40 | ($o0,$t0)=&NR(2); | ||
| 41 | &add($a0,$b0,$o0); | ||
| 42 | &cmpult($o0,$b0,$t0); | ||
| 43 | &add($o0,$cc,$o0); | ||
| 44 | &cmpult($o0,$cc,$cc); | ||
| 45 | &add($cc,$t0,$cc); &FR($t0); | ||
| 46 | |||
| 47 | ($t1,$o1)=&NR(2); | ||
| 48 | |||
| 49 | &add($a1,$b1,$o1); &FR($a1); | ||
| 50 | &cmpult($o1,$b1,$t1); &FR($b1); | ||
| 51 | &add($o1,$cc,$o1); | ||
| 52 | &cmpult($o1,$cc,$cc); | ||
| 53 | &add($cc,$t1,$cc); &FR($t1); | ||
| 54 | |||
| 55 | ($t2,$o2)=&NR(2); | ||
| 56 | |||
| 57 | &add($a2,$b2,$o2); &FR($a2); | ||
| 58 | &cmpult($o2,$b2,$t2); &FR($b2); | ||
| 59 | &add($o2,$cc,$o2); | ||
| 60 | &cmpult($o2,$cc,$cc); | ||
| 61 | &add($cc,$t2,$cc); &FR($t2); | ||
| 62 | |||
| 63 | ($t3,$o3)=&NR(2); | ||
| 64 | |||
| 65 | &add($a3,$b3,$o3); &FR($a3); | ||
| 66 | &cmpult($o3,$b3,$t3); &FR($b3); | ||
| 67 | &add($o3,$cc,$o3); | ||
| 68 | &cmpult($o3,$cc,$cc); | ||
| 69 | &add($cc,$t3,$cc); &FR($t3); | ||
| 70 | |||
| 71 | &st($o0,&QWPw(0,$rp)); &FR($o0); | ||
| 72 | &st($o1,&QWPw(0,$rp)); &FR($o1); | ||
| 73 | &st($o2,&QWPw(0,$rp)); &FR($o2); | ||
| 74 | &st($o3,&QWPw(0,$rp)); &FR($o3); | ||
| 75 | |||
| 76 | &sub($count,4,$count); # count-=4 | ||
| 77 | &add($ap,4*$QWS,$ap); # count+=4 | ||
| 78 | &add($bp,4*$QWS,$bp); # count+=4 | ||
| 79 | &add($rp,4*$QWS,$rp); # count+=4 | ||
| 80 | |||
| 81 | &blt($count,&label("finish")); | ||
| 82 | &ld($a0,&QWPw(0,$ap)); | ||
| 83 | &ld($b0,&QWPw(0,$bp)); | ||
| 84 | &br(&label("loop")); | ||
| 85 | EOF | ||
| 86 | ################################################## | ||
| 87 | # Do the last 0..3 words | ||
| 88 | |||
| 89 | &set_label("last_loop"); | ||
| 90 | |||
| 91 | &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a | ||
| 92 | &ld(($r0)=&NR(1),&QWPw(0,$rp)); # get b | ||
| 93 | &mul($a0,$word,($l0)=&NR(1)); | ||
| 94 | &sub($count,1,$count); | ||
| 95 | &add($ap,$QWS,$ap); | ||
| 96 | &muh($a0,$word,($h0)=&NR(1)); &FR($a0); | ||
| 97 | &add($r0,$l0,$r0); | ||
| 98 | &add($rp,$QWS,$rp); | ||
| 99 | &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0); | ||
| 100 | &add($r0,$cc,$r0); | ||
| 101 | &add($h0,$t0,$h0); &FR($t0); | ||
| 102 | &cmpult($r0,$cc,$cc); | ||
| 103 | &st($r0,&QWPw(-1,$rp)); &FR($r0); | ||
| 104 | &add($h0,$cc,$cc); &FR($h0); | ||
| 105 | |||
| 106 | &bgt($count,&label("last_loop")); | ||
| 107 | &function_end_A($name); | ||
| 108 | |||
| 109 | ###################################################### | ||
| 110 | &set_label("finish"); | ||
| 111 | &add($count,4,$count); | ||
| 112 | &bgt($count,&label("last_loop")); | ||
| 113 | |||
| 114 | &set_label("end"); | ||
| 115 | &function_end($name); | ||
| 116 | |||
| 117 | &fin_pool; | ||
| 118 | } | ||
| 119 | |||
| 120 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.pl deleted file mode 100644 index 5efd201281..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.pl +++ /dev/null | |||
| @@ -1,213 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub mul_add_c | ||
| 5 | { | ||
| 6 | local($a,$b,$c0,$c1,$c2)=@_; | ||
| 7 | local($l1,$h1,$t1,$t2); | ||
| 8 | |||
| 9 | &mul($a,$b,($l1)=&NR(1)); | ||
| 10 | &muh($a,$b,($h1)=&NR(1)); | ||
| 11 | &add($c0,$l1,$c0); | ||
| 12 | &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1); | ||
| 13 | &add($t1,$h1,$h1); &FR($t1); | ||
| 14 | &add($c1,$h1,$c1); | ||
| 15 | &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1); | ||
| 16 | &add($c2,$t2,$c2); &FR($t2); | ||
| 17 | } | ||
| 18 | |||
| 19 | sub bn_mul_comba4 | ||
| 20 | { | ||
| 21 | local($name)=@_; | ||
| 22 | local(@a,@b,$r,$c0,$c1,$c2); | ||
| 23 | |||
| 24 | $cnt=1; | ||
| 25 | &init_pool(3); | ||
| 26 | |||
| 27 | $rp=&wparam(0); | ||
| 28 | $ap=&wparam(1); | ||
| 29 | $bp=&wparam(2); | ||
| 30 | |||
| 31 | &function_begin($name,""); | ||
| 32 | |||
| 33 | &comment(""); | ||
| 34 | |||
| 35 | &ld(($a[0])=&NR(1),&QWPw(0,$ap)); | ||
| 36 | &ld(($b[0])=&NR(1),&QWPw(0,$bp)); | ||
| 37 | &ld(($a[1])=&NR(1),&QWPw(1,$ap)); | ||
| 38 | &ld(($b[1])=&NR(1),&QWPw(1,$bp)); | ||
| 39 | &mul($a[0],$b[0],($r00)=&NR(1)); | ||
| 40 | &ld(($a[2])=&NR(1),&QWPw(2,$ap)); | ||
| 41 | &ld(($b[2])=&NR(1),&QWPw(2,$bp)); | ||
| 42 | &muh($a[0],$b[0],($r01)=&NR(1)); | ||
| 43 | &FR($ap); &ld(($a[3])=&NR(1),&QWPw(3,$ap)); | ||
| 44 | &FR($bp); &ld(($b[3])=&NR(1),&QWPw(3,$bp)); | ||
| 45 | &mul($a[0],$b[1],($r02)=&NR(1)); | ||
| 46 | |||
| 47 | ($R,$H1,$H2)=&NR(3); | ||
| 48 | |||
| 49 | &st($r00,&QWPw(0,$rp)); &FR($r00); | ||
| 50 | |||
| 51 | &mov("zero",$R); | ||
| 52 | &mul($a[1],$b[0],($r03)=&NR(1)); | ||
| 53 | |||
| 54 | &mov("zero",$H1); | ||
| 55 | &mov("zero",$H0); | ||
| 56 | &add($R,$r01,$R); | ||
| 57 | &muh($a[0],$b[1],($r04)=&NR(1)); | ||
| 58 | &cmpult($R,$r01,($t01)=&NR(1)); &FR($r01); | ||
| 59 | &add($R,$r02,$R); | ||
| 60 | &add($H1,$t01,$H1) &FR($t01); | ||
| 61 | &muh($a[1],$b[0],($r05)=&NR(1)); | ||
| 62 | &cmpult($R,$r02,($t02)=&NR(1)); &FR($r02); | ||
| 63 | &add($R,$r03,$R); | ||
| 64 | &add($H2,$t02,$H2) &FR($t02); | ||
| 65 | &mul($a[0],$b[2],($r06)=&NR(1)); | ||
| 66 | &cmpult($R,$r03,($t03)=&NR(1)); &FR($r03); | ||
| 67 | &add($H1,$t03,$H1) &FR($t03); | ||
| 68 | &st($R,&QWPw(1,$rp)); | ||
| 69 | &add($H1,$H2,$R); | ||
| 70 | |||
| 71 | &mov("zero",$H1); | ||
| 72 | &add($R,$r04,$R); | ||
| 73 | &mov("zero",$H2); | ||
| 74 | &mul($a[1],$b[1],($r07)=&NR(1)); | ||
| 75 | &cmpult($R,$r04,($t04)=&NR(1)); &FR($r04); | ||
| 76 | &add($R,$r05,$R); | ||
| 77 | &add($H1,$t04,$H1) &FR($t04); | ||
| 78 | &mul($a[2],$b[0],($r08)=&NR(1)); | ||
| 79 | &cmpult($R,$r05,($t05)=&NR(1)); &FR($r05); | ||
| 80 | &add($R,$r01,$R); | ||
| 81 | &add($H2,$t05,$H2) &FR($t05); | ||
| 82 | &muh($a[0],$b[2],($r09)=&NR(1)); | ||
| 83 | &cmpult($R,$r06,($t06)=&NR(1)); &FR($r06); | ||
| 84 | &add($R,$r07,$R); | ||
| 85 | &add($H1,$t06,$H1) &FR($t06); | ||
| 86 | &muh($a[1],$b[1],($r10)=&NR(1)); | ||
| 87 | &cmpult($R,$r07,($t07)=&NR(1)); &FR($r07); | ||
| 88 | &add($R,$r08,$R); | ||
| 89 | &add($H2,$t07,$H2) &FR($t07); | ||
| 90 | &muh($a[2],$b[0],($r11)=&NR(1)); | ||
| 91 | &cmpult($R,$r08,($t08)=&NR(1)); &FR($r08); | ||
| 92 | &add($H1,$t08,$H1) &FR($t08); | ||
| 93 | &st($R,&QWPw(2,$rp)); | ||
| 94 | &add($H1,$H2,$R); | ||
| 95 | |||
| 96 | &mov("zero",$H1); | ||
| 97 | &add($R,$r09,$R); | ||
| 98 | &mov("zero",$H2); | ||
| 99 | &mul($a[0],$b[3],($r12)=&NR(1)); | ||
| 100 | &cmpult($R,$r09,($t09)=&NR(1)); &FR($r09); | ||
| 101 | &add($R,$r10,$R); | ||
| 102 | &add($H1,$t09,$H1) &FR($t09); | ||
| 103 | &mul($a[1],$b[2],($r13)=&NR(1)); | ||
| 104 | &cmpult($R,$r10,($t10)=&NR(1)); &FR($r10); | ||
| 105 | &add($R,$r11,$R); | ||
| 106 | &add($H1,$t10,$H1) &FR($t10); | ||
| 107 | &mul($a[2],$b[1],($r14)=&NR(1)); | ||
| 108 | &cmpult($R,$r11,($t11)=&NR(1)); &FR($r11); | ||
| 109 | &add($R,$r12,$R); | ||
| 110 | &add($H1,$t11,$H1) &FR($t11); | ||
| 111 | &mul($a[3],$b[0],($r15)=&NR(1)); | ||
| 112 | &cmpult($R,$r12,($t12)=&NR(1)); &FR($r12); | ||
| 113 | &add($R,$r13,$R); | ||
| 114 | &add($H1,$t12,$H1) &FR($t12); | ||
| 115 | &muh($a[0],$b[3],($r16)=&NR(1)); | ||
| 116 | &cmpult($R,$r13,($t13)=&NR(1)); &FR($r13); | ||
| 117 | &add($R,$r14,$R); | ||
| 118 | &add($H1,$t13,$H1) &FR($t13); | ||
| 119 | &muh($a[1],$b[2],($r17)=&NR(1)); | ||
| 120 | &cmpult($R,$r14,($t14)=&NR(1)); &FR($r14); | ||
| 121 | &add($R,$r15,$R); | ||
| 122 | &add($H1,$t14,$H1) &FR($t14); | ||
| 123 | &muh($a[2],$b[1],($r18)=&NR(1)); | ||
| 124 | &cmpult($R,$r15,($t15)=&NR(1)); &FR($r15); | ||
| 125 | &add($H1,$t15,$H1) &FR($t15); | ||
| 126 | &st($R,&QWPw(3,$rp)); | ||
| 127 | &add($H1,$H2,$R); | ||
| 128 | |||
| 129 | &mov("zero",$H1); | ||
| 130 | &add($R,$r16,$R); | ||
| 131 | &mov("zero",$H2); | ||
| 132 | &muh($a[3],$b[0],($r19)=&NR(1)); | ||
| 133 | &cmpult($R,$r16,($t16)=&NR(1)); &FR($r16); | ||
| 134 | &add($R,$r17,$R); | ||
| 135 | &add($H1,$t16,$H1) &FR($t16); | ||
| 136 | &mul($a[1],$b[3],($r20)=&NR(1)); | ||
| 137 | &cmpult($R,$r17,($t17)=&NR(1)); &FR($r17); | ||
| 138 | &add($R,$r18,$R); | ||
| 139 | &add($H1,$t17,$H1) &FR($t17); | ||
| 140 | &mul($a[2],$b[2],($r21)=&NR(1)); | ||
| 141 | &cmpult($R,$r18,($t18)=&NR(1)); &FR($r18); | ||
| 142 | &add($R,$r19,$R); | ||
| 143 | &add($H1,$t18,$H1) &FR($t18); | ||
| 144 | &mul($a[3],$b[1],($r22)=&NR(1)); | ||
| 145 | &cmpult($R,$r19,($t19)=&NR(1)); &FR($r19); | ||
| 146 | &add($R,$r20,$R); | ||
| 147 | &add($H1,$t19,$H1) &FR($t19); | ||
| 148 | &muh($a[1],$b[3],($r23)=&NR(1)); | ||
| 149 | &cmpult($R,$r20,($t20)=&NR(1)); &FR($r20); | ||
| 150 | &add($R,$r21,$R); | ||
| 151 | &add($H1,$t20,$H1) &FR($t20); | ||
| 152 | &muh($a[2],$b[2],($r24)=&NR(1)); | ||
| 153 | &cmpult($R,$r21,($t21)=&NR(1)); &FR($r21); | ||
| 154 | &add($R,$r22,$R); | ||
| 155 | &add($H1,$t21,$H1) &FR($t21); | ||
| 156 | &muh($a[3],$b[1],($r25)=&NR(1)); | ||
| 157 | &cmpult($R,$r22,($t22)=&NR(1)); &FR($r22); | ||
| 158 | &add($H1,$t22,$H1) &FR($t22); | ||
| 159 | &st($R,&QWPw(4,$rp)); | ||
| 160 | &add($H1,$H2,$R); | ||
| 161 | |||
| 162 | &mov("zero",$H1); | ||
| 163 | &add($R,$r23,$R); | ||
| 164 | &mov("zero",$H2); | ||
| 165 | &mul($a[2],$b[3],($r26)=&NR(1)); | ||
| 166 | &cmpult($R,$r23,($t23)=&NR(1)); &FR($r23); | ||
| 167 | &add($R,$r24,$R); | ||
| 168 | &add($H1,$t23,$H1) &FR($t23); | ||
| 169 | &mul($a[3],$b[2],($r27)=&NR(1)); | ||
| 170 | &cmpult($R,$r24,($t24)=&NR(1)); &FR($r24); | ||
| 171 | &add($R,$r25,$R); | ||
| 172 | &add($H1,$t24,$H1) &FR($t24); | ||
| 173 | &muh($a[2],$b[3],($r28)=&NR(1)); | ||
| 174 | &cmpult($R,$r25,($t25)=&NR(1)); &FR($r25); | ||
| 175 | &add($R,$r26,$R); | ||
| 176 | &add($H1,$t25,$H1) &FR($t25); | ||
| 177 | &muh($a[3],$b[2],($r29)=&NR(1)); | ||
| 178 | &cmpult($R,$r26,($t26)=&NR(1)); &FR($r26); | ||
| 179 | &add($R,$r27,$R); | ||
| 180 | &add($H1,$t26,$H1) &FR($t26); | ||
| 181 | &mul($a[3],$b[3],($r30)=&NR(1)); | ||
| 182 | &cmpult($R,$r27,($t27)=&NR(1)); &FR($r27); | ||
| 183 | &add($H1,$t27,$H1) &FR($t27); | ||
| 184 | &st($R,&QWPw(5,$rp)); | ||
| 185 | &add($H1,$H2,$R); | ||
| 186 | |||
| 187 | &mov("zero",$H1); | ||
| 188 | &add($R,$r28,$R); | ||
| 189 | &mov("zero",$H2); | ||
| 190 | &muh($a[3],$b[3],($r31)=&NR(1)); | ||
| 191 | &cmpult($R,$r28,($t28)=&NR(1)); &FR($r28); | ||
| 192 | &add($R,$r29,$R); | ||
| 193 | &add($H1,$t28,$H1) &FR($t28); | ||
| 194 | ############ | ||
| 195 | &cmpult($R,$r29,($t29)=&NR(1)); &FR($r29); | ||
| 196 | &add($R,$r30,$R); | ||
| 197 | &add($H1,$t29,$H1) &FR($t29); | ||
| 198 | ############ | ||
| 199 | &cmpult($R,$r30,($t30)=&NR(1)); &FR($r30); | ||
| 200 | &add($H1,$t30,$H1) &FR($t30); | ||
| 201 | &st($R,&QWPw(6,$rp)); | ||
| 202 | &add($H1,$H2,$R); | ||
| 203 | |||
| 204 | &add($R,$r31,$R); &FR($r31); | ||
| 205 | &st($R,&QWPw(7,$rp)); | ||
| 206 | |||
| 207 | &FR($R,$H1,$H2); | ||
| 208 | &function_end($name); | ||
| 209 | |||
| 210 | &fin_pool; | ||
| 211 | } | ||
| 212 | |||
| 213 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.works.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.works.pl deleted file mode 100644 index 79d86dd25c..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.works.pl +++ /dev/null | |||
| @@ -1,98 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub mul_add_c | ||
| 5 | { | ||
| 6 | local($a,$b,$c0,$c1,$c2)=@_; | ||
| 7 | local($l1,$h1,$t1,$t2); | ||
| 8 | |||
| 9 | print STDERR "count=$cnt\n"; $cnt++; | ||
| 10 | &mul($a,$b,($l1)=&NR(1)); | ||
| 11 | &muh($a,$b,($h1)=&NR(1)); | ||
| 12 | &add($c0,$l1,$c0); | ||
| 13 | &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1); | ||
| 14 | &add($t1,$h1,$h1); &FR($t1); | ||
| 15 | &add($c1,$h1,$c1); | ||
| 16 | &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1); | ||
| 17 | &add($c2,$t2,$c2); &FR($t2); | ||
| 18 | } | ||
| 19 | |||
| 20 | sub bn_mul_comba4 | ||
| 21 | { | ||
| 22 | local($name)=@_; | ||
| 23 | local(@a,@b,$r,$c0,$c1,$c2); | ||
| 24 | |||
| 25 | $cnt=1; | ||
| 26 | &init_pool(3); | ||
| 27 | |||
| 28 | $rp=&wparam(0); | ||
| 29 | $ap=&wparam(1); | ||
| 30 | $bp=&wparam(2); | ||
| 31 | |||
| 32 | &function_begin($name,""); | ||
| 33 | |||
| 34 | &comment(""); | ||
| 35 | |||
| 36 | &ld(($a[0])=&NR(1),&QWPw(0,$ap)); | ||
| 37 | &ld(($b[0])=&NR(1),&QWPw(0,$bp)); | ||
| 38 | &ld(($a[1])=&NR(1),&QWPw(1,$ap)); | ||
| 39 | &ld(($b[1])=&NR(1),&QWPw(1,$bp)); | ||
| 40 | &ld(($a[2])=&NR(1),&QWPw(2,$ap)); | ||
| 41 | &ld(($b[2])=&NR(1),&QWPw(2,$bp)); | ||
| 42 | &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap); | ||
| 43 | &ld(($b[3])=&NR(1),&QWPw(3,$bp)); &FR($bp); | ||
| 44 | |||
| 45 | ($c0,$c1,$c2)=&NR(3); | ||
| 46 | &mov("zero",$c2); | ||
| 47 | &mul($a[0],$b[0],$c0); | ||
| 48 | &muh($a[0],$b[0],$c1); | ||
| 49 | &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 50 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 51 | &mov("zero",$c2); | ||
| 52 | |||
| 53 | &mul_add_c($a[0],$b[1],$c0,$c1,$c2); | ||
| 54 | &mul_add_c($a[1],$b[0],$c0,$c1,$c2); | ||
| 55 | &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 56 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 57 | &mov("zero",$c2); | ||
| 58 | |||
| 59 | &mul_add_c($a[1],$b[1],$c0,$c1,$c2); | ||
| 60 | &mul_add_c($a[0],$b[2],$c0,$c1,$c2); | ||
| 61 | &mul_add_c($a[2],$b[0],$c0,$c1,$c2); | ||
| 62 | &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 63 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 64 | &mov("zero",$c2); | ||
| 65 | |||
| 66 | &mul_add_c($a[0],$b[3],$c0,$c1,$c2); &FR($a[0]); | ||
| 67 | &mul_add_c($a[1],$b[2],$c0,$c1,$c2); | ||
| 68 | &mul_add_c($a[2],$b[1],$c0,$c1,$c2); | ||
| 69 | &mul_add_c($a[3],$b[0],$c0,$c1,$c2); &FR($b[0]); | ||
| 70 | &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 71 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 72 | &mov("zero",$c2); | ||
| 73 | |||
| 74 | &mul_add_c($a[1],$b[3],$c0,$c1,$c2); &FR($a[1]); | ||
| 75 | &mul_add_c($a[2],$b[2],$c0,$c1,$c2); | ||
| 76 | &mul_add_c($a[3],$b[1],$c0,$c1,$c2); &FR($b[1]); | ||
| 77 | &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 78 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 79 | &mov("zero",$c2); | ||
| 80 | |||
| 81 | &mul_add_c($a[2],$b[3],$c0,$c1,$c2); &FR($a[2]); | ||
| 82 | &mul_add_c($a[3],$b[2],$c0,$c1,$c2); &FR($b[2]); | ||
| 83 | &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 84 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 85 | &mov("zero",$c2); | ||
| 86 | |||
| 87 | &mul_add_c($a[3],$b[3],$c0,$c1,$c2); &FR($a[3],$b[3]); | ||
| 88 | &st($c0,&QWPw(6,$rp)); | ||
| 89 | &st($c1,&QWPw(7,$rp)); | ||
| 90 | |||
| 91 | &FR($c0,$c1,$c2); | ||
| 92 | |||
| 93 | &function_end($name); | ||
| 94 | |||
| 95 | &fin_pool; | ||
| 96 | } | ||
| 97 | |||
| 98 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_c8.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_c8.pl deleted file mode 100644 index 525ca7494b..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.works/mul_c8.pl +++ /dev/null | |||
| @@ -1,177 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_mul_comba8 | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local(@a,@b,$r,$c0,$c1,$c2); | ||
| 8 | |||
| 9 | $cnt=1; | ||
| 10 | &init_pool(3); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $bp=&wparam(2); | ||
| 15 | |||
| 16 | &function_begin($name,""); | ||
| 17 | |||
| 18 | &comment(""); | ||
| 19 | |||
| 20 | &stack_push(2); | ||
| 21 | &ld(($a[0])=&NR(1),&QWPw(0,$ap)); | ||
| 22 | &ld(($b[0])=&NR(1),&QWPw(0,$bp)); | ||
| 23 | &st($reg_s0,&swtmp(0)); &FR($reg_s0); | ||
| 24 | &st($reg_s1,&swtmp(1)); &FR($reg_s1); | ||
| 25 | &ld(($a[1])=&NR(1),&QWPw(1,$ap)); | ||
| 26 | &ld(($b[1])=&NR(1),&QWPw(1,$bp)); | ||
| 27 | &ld(($a[2])=&NR(1),&QWPw(2,$ap)); | ||
| 28 | &ld(($b[2])=&NR(1),&QWPw(2,$bp)); | ||
| 29 | &ld(($a[3])=&NR(1),&QWPw(3,$ap)); | ||
| 30 | &ld(($b[3])=&NR(1),&QWPw(3,$bp)); | ||
| 31 | &ld(($a[4])=&NR(1),&QWPw(1,$ap)); | ||
| 32 | &ld(($b[4])=&NR(1),&QWPw(1,$bp)); | ||
| 33 | &ld(($a[5])=&NR(1),&QWPw(1,$ap)); | ||
| 34 | &ld(($b[5])=&NR(1),&QWPw(1,$bp)); | ||
| 35 | &ld(($a[6])=&NR(1),&QWPw(1,$ap)); | ||
| 36 | &ld(($b[6])=&NR(1),&QWPw(1,$bp)); | ||
| 37 | &ld(($a[7])=&NR(1),&QWPw(1,$ap)); &FR($ap); | ||
| 38 | &ld(($b[7])=&NR(1),&QWPw(1,$bp)); &FR($bp); | ||
| 39 | |||
| 40 | ($c0,$c1,$c2)=&NR(3); | ||
| 41 | &mov("zero",$c2); | ||
| 42 | &mul($a[0],$b[0],$c0); | ||
| 43 | &muh($a[0],$b[0],$c1); | ||
| 44 | &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 45 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 46 | &mov("zero",$c2); | ||
| 47 | |||
| 48 | &mul_add_c($a[0],$b[1],$c0,$c1,$c2); | ||
| 49 | &mul_add_c($a[1],$b[0],$c0,$c1,$c2); | ||
| 50 | &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 51 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 52 | &mov("zero",$c2); | ||
| 53 | |||
| 54 | &mul_add_c($a[0],$b[2],$c0,$c1,$c2); | ||
| 55 | &mul_add_c($a[1],$b[1],$c0,$c1,$c2); | ||
| 56 | &mul_add_c($a[2],$b[0],$c0,$c1,$c2); | ||
| 57 | &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 58 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 59 | &mov("zero",$c2); | ||
| 60 | |||
| 61 | &mul_add_c($a[0],$b[3],$c0,$c1,$c2); | ||
| 62 | &mul_add_c($a[1],$b[2],$c0,$c1,$c2); | ||
| 63 | &mul_add_c($a[2],$b[1],$c0,$c1,$c2); | ||
| 64 | &mul_add_c($a[3],$b[0],$c0,$c1,$c2); | ||
| 65 | &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 66 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 67 | &mov("zero",$c2); | ||
| 68 | |||
| 69 | &mul_add_c($a[0],$b[4],$c0,$c1,$c2); | ||
| 70 | &mul_add_c($a[1],$b[3],$c0,$c1,$c2); | ||
| 71 | &mul_add_c($a[2],$b[2],$c0,$c1,$c2); | ||
| 72 | &mul_add_c($a[3],$b[1],$c0,$c1,$c2); | ||
| 73 | &mul_add_c($a[4],$b[0],$c0,$c1,$c2); | ||
| 74 | &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 75 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 76 | &mov("zero",$c2); | ||
| 77 | |||
| 78 | &mul_add_c($a[0],$b[5],$c0,$c1,$c2); | ||
| 79 | &mul_add_c($a[1],$b[4],$c0,$c1,$c2); | ||
| 80 | &mul_add_c($a[2],$b[3],$c0,$c1,$c2); | ||
| 81 | &mul_add_c($a[3],$b[2],$c0,$c1,$c2); | ||
| 82 | &mul_add_c($a[4],$b[1],$c0,$c1,$c2); | ||
| 83 | &mul_add_c($a[5],$b[0],$c0,$c1,$c2); | ||
| 84 | &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 85 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 86 | &mov("zero",$c2); | ||
| 87 | |||
| 88 | &mul_add_c($a[0],$b[6],$c0,$c1,$c2); | ||
| 89 | &mul_add_c($a[1],$b[5],$c0,$c1,$c2); | ||
| 90 | &mul_add_c($a[2],$b[4],$c0,$c1,$c2); | ||
| 91 | &mul_add_c($a[3],$b[3],$c0,$c1,$c2); | ||
| 92 | &mul_add_c($a[4],$b[2],$c0,$c1,$c2); | ||
| 93 | &mul_add_c($a[5],$b[1],$c0,$c1,$c2); | ||
| 94 | &mul_add_c($a[6],$b[0],$c0,$c1,$c2); | ||
| 95 | &st($c0,&QWPw(6,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 96 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 97 | &mov("zero",$c2); | ||
| 98 | |||
| 99 | &mul_add_c($a[0],$b[7],$c0,$c1,$c2); &FR($a[0]); | ||
| 100 | &mul_add_c($a[1],$b[6],$c0,$c1,$c2); | ||
| 101 | &mul_add_c($a[2],$b[5],$c0,$c1,$c2); | ||
| 102 | &mul_add_c($a[3],$b[4],$c0,$c1,$c2); | ||
| 103 | &mul_add_c($a[4],$b[3],$c0,$c1,$c2); | ||
| 104 | &mul_add_c($a[5],$b[2],$c0,$c1,$c2); | ||
| 105 | &mul_add_c($a[6],$b[1],$c0,$c1,$c2); | ||
| 106 | &mul_add_c($a[7],$b[0],$c0,$c1,$c2); &FR($b[0]); | ||
| 107 | &st($c0,&QWPw(7,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 108 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 109 | &mov("zero",$c2); | ||
| 110 | |||
| 111 | &mul_add_c($a[1],$b[7],$c0,$c1,$c2); &FR($a[1]); | ||
| 112 | &mul_add_c($a[2],$b[6],$c0,$c1,$c2); | ||
| 113 | &mul_add_c($a[3],$b[5],$c0,$c1,$c2); | ||
| 114 | &mul_add_c($a[4],$b[4],$c0,$c1,$c2); | ||
| 115 | &mul_add_c($a[5],$b[3],$c0,$c1,$c2); | ||
| 116 | &mul_add_c($a[6],$b[2],$c0,$c1,$c2); | ||
| 117 | &mul_add_c($a[7],$b[1],$c0,$c1,$c2); &FR($b[1]); | ||
| 118 | &st($c0,&QWPw(8,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 119 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 120 | &mov("zero",$c2); | ||
| 121 | |||
| 122 | &mul_add_c($a[2],$b[7],$c0,$c1,$c2); &FR($a[2]); | ||
| 123 | &mul_add_c($a[3],$b[6],$c0,$c1,$c2); | ||
| 124 | &mul_add_c($a[4],$b[5],$c0,$c1,$c2); | ||
| 125 | &mul_add_c($a[5],$b[4],$c0,$c1,$c2); | ||
| 126 | &mul_add_c($a[6],$b[3],$c0,$c1,$c2); | ||
| 127 | &mul_add_c($a[7],$b[2],$c0,$c1,$c2); &FR($b[2]); | ||
| 128 | &st($c0,&QWPw(9,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 129 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 130 | &mov("zero",$c2); | ||
| 131 | |||
| 132 | &mul_add_c($a[3],$b[7],$c0,$c1,$c2); &FR($a[3]); | ||
| 133 | &mul_add_c($a[4],$b[6],$c0,$c1,$c2); | ||
| 134 | &mul_add_c($a[5],$b[5],$c0,$c1,$c2); | ||
| 135 | &mul_add_c($a[6],$b[4],$c0,$c1,$c2); | ||
| 136 | &mul_add_c($a[7],$b[3],$c0,$c1,$c2); &FR($b[3]); | ||
| 137 | &st($c0,&QWPw(10,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 138 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 139 | &mov("zero",$c2); | ||
| 140 | |||
| 141 | &mul_add_c($a[4],$b[7],$c0,$c1,$c2); &FR($a[4]); | ||
| 142 | &mul_add_c($a[5],$b[6],$c0,$c1,$c2); | ||
| 143 | &mul_add_c($a[6],$b[5],$c0,$c1,$c2); | ||
| 144 | &mul_add_c($a[7],$b[4],$c0,$c1,$c2); &FR($b[4]); | ||
| 145 | &st($c0,&QWPw(11,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 146 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 147 | &mov("zero",$c2); | ||
| 148 | |||
| 149 | &mul_add_c($a[5],$b[7],$c0,$c1,$c2); &FR($a[5]); | ||
| 150 | &mul_add_c($a[6],$b[6],$c0,$c1,$c2); | ||
| 151 | &mul_add_c($a[7],$b[5],$c0,$c1,$c2); &FR($b[5]); | ||
| 152 | &st($c0,&QWPw(12,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 153 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 154 | &mov("zero",$c2); | ||
| 155 | |||
| 156 | &mul_add_c($a[6],$b[7],$c0,$c1,$c2); &FR($a[6]); | ||
| 157 | &mul_add_c($a[7],$b[6],$c0,$c1,$c2); &FR($b[6]); | ||
| 158 | &st($c0,&QWPw(13,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 159 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 160 | &mov("zero",$c2); | ||
| 161 | |||
| 162 | &mul_add_c($a[7],$b[7],$c0,$c1,$c2); &FR($a[7],$b[7]); | ||
| 163 | &st($c0,&QWPw(14,$rp)); | ||
| 164 | &st($c1,&QWPw(15,$rp)); | ||
| 165 | |||
| 166 | &FR($c0,$c1,$c2); | ||
| 167 | |||
| 168 | &ld($reg_s0,&swtmp(0)); | ||
| 169 | &ld($reg_s1,&swtmp(1)); | ||
| 170 | &stack_pop(2); | ||
| 171 | |||
| 172 | &function_end($name); | ||
| 173 | |||
| 174 | &fin_pool; | ||
| 175 | } | ||
| 176 | |||
| 177 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sqr.pl b/src/lib/libcrypto/bn/asm/alpha.works/sqr.pl deleted file mode 100644 index a55b696906..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.works/sqr.pl +++ /dev/null | |||
| @@ -1,113 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_sqr_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local($cc,$a,$b,$r,$couny); | ||
| 8 | |||
| 9 | &init_pool(3); | ||
| 10 | ($cc)=GR("r0"); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $count=&wparam(2); | ||
| 15 | |||
| 16 | &function_begin($name,""); | ||
| 17 | |||
| 18 | &comment(""); | ||
| 19 | &sub($count,4,$count); | ||
| 20 | &mov("zero",$cc); | ||
| 21 | &br(&label("finish")); | ||
| 22 | &blt($count,&label("finish")); | ||
| 23 | |||
| 24 | ($a0,$r0)=&NR(2); | ||
| 25 | &ld($a0,&QWPw(0,$ap)); | ||
| 26 | &ld($r0,&QWPw(0,$rp)); | ||
| 27 | |||
| 28 | $a=<<'EOF'; | ||
| 29 | ########################################################## | ||
| 30 | &set_label("loop"); | ||
| 31 | |||
| 32 | ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap)); | ||
| 33 | ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp)); | ||
| 34 | ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap)); | ||
| 35 | ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp)); | ||
| 36 | ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap)); | ||
| 37 | ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp)); | ||
| 38 | |||
| 39 | ($o0,$t0)=&NR(2); | ||
| 40 | &add($a0,$b0,$o0); | ||
| 41 | &cmpult($o0,$b0,$t0); | ||
| 42 | &add($o0,$cc,$o0); | ||
| 43 | &cmpult($o0,$cc,$cc); | ||
| 44 | &add($cc,$t0,$cc); &FR($t0); | ||
| 45 | |||
| 46 | ($t1,$o1)=&NR(2); | ||
| 47 | |||
| 48 | &add($a1,$b1,$o1); &FR($a1); | ||
| 49 | &cmpult($o1,$b1,$t1); &FR($b1); | ||
| 50 | &add($o1,$cc,$o1); | ||
| 51 | &cmpult($o1,$cc,$cc); | ||
| 52 | &add($cc,$t1,$cc); &FR($t1); | ||
| 53 | |||
| 54 | ($t2,$o2)=&NR(2); | ||
| 55 | |||
| 56 | &add($a2,$b2,$o2); &FR($a2); | ||
| 57 | &cmpult($o2,$b2,$t2); &FR($b2); | ||
| 58 | &add($o2,$cc,$o2); | ||
| 59 | &cmpult($o2,$cc,$cc); | ||
| 60 | &add($cc,$t2,$cc); &FR($t2); | ||
| 61 | |||
| 62 | ($t3,$o3)=&NR(2); | ||
| 63 | |||
| 64 | &add($a3,$b3,$o3); &FR($a3); | ||
| 65 | &cmpult($o3,$b3,$t3); &FR($b3); | ||
| 66 | &add($o3,$cc,$o3); | ||
| 67 | &cmpult($o3,$cc,$cc); | ||
| 68 | &add($cc,$t3,$cc); &FR($t3); | ||
| 69 | |||
| 70 | &st($o0,&QWPw(0,$rp)); &FR($o0); | ||
| 71 | &st($o1,&QWPw(0,$rp)); &FR($o1); | ||
| 72 | &st($o2,&QWPw(0,$rp)); &FR($o2); | ||
| 73 | &st($o3,&QWPw(0,$rp)); &FR($o3); | ||
| 74 | |||
| 75 | &sub($count,4,$count); # count-=4 | ||
| 76 | &add($ap,4*$QWS,$ap); # count+=4 | ||
| 77 | &add($bp,4*$QWS,$bp); # count+=4 | ||
| 78 | &add($rp,4*$QWS,$rp); # count+=4 | ||
| 79 | |||
| 80 | &blt($count,&label("finish")); | ||
| 81 | &ld($a0,&QWPw(0,$ap)); | ||
| 82 | &ld($b0,&QWPw(0,$bp)); | ||
| 83 | &br(&label("loop")); | ||
| 84 | EOF | ||
| 85 | ################################################## | ||
| 86 | # Do the last 0..3 words | ||
| 87 | |||
| 88 | &set_label("last_loop"); | ||
| 89 | |||
| 90 | &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a | ||
| 91 | &mul($a0,$a0,($l0)=&NR(1)); | ||
| 92 | &add($ap,$QWS,$ap); | ||
| 93 | &add($rp,2*$QWS,$rp); | ||
| 94 | &sub($count,1,$count); | ||
| 95 | &muh($a0,$a0,($h0)=&NR(1)); &FR($a0); | ||
| 96 | &st($l0,&QWPw(-2,$rp)); &FR($l0); | ||
| 97 | &st($h0,&QWPw(-1,$rp)); &FR($h0); | ||
| 98 | |||
| 99 | &bgt($count,&label("last_loop")); | ||
| 100 | &function_end_A($name); | ||
| 101 | |||
| 102 | ###################################################### | ||
| 103 | &set_label("finish"); | ||
| 104 | &add($count,4,$count); | ||
| 105 | &bgt($count,&label("last_loop")); | ||
| 106 | |||
| 107 | &set_label("end"); | ||
| 108 | &function_end($name); | ||
| 109 | |||
| 110 | &fin_pool; | ||
| 111 | } | ||
| 112 | |||
| 113 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sqr_c4.pl b/src/lib/libcrypto/bn/asm/alpha.works/sqr_c4.pl deleted file mode 100644 index bf33f5b503..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.works/sqr_c4.pl +++ /dev/null | |||
| @@ -1,109 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub sqr_add_c | ||
| 5 | { | ||
| 6 | local($a,$c0,$c1,$c2)=@_; | ||
| 7 | local($l1,$h1,$t1,$t2); | ||
| 8 | |||
| 9 | &mul($a,$a,($l1)=&NR(1)); | ||
| 10 | &muh($a,$a,($h1)=&NR(1)); | ||
| 11 | &add($c0,$l1,$c0); | ||
| 12 | &add($c1,$h1,$c1); | ||
| 13 | &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1); | ||
| 14 | &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1); | ||
| 15 | &add($c1,$t1,$c1); &FR($t1); | ||
| 16 | &add($c2,$t2,$c2); &FR($t2); | ||
| 17 | } | ||
| 18 | |||
| 19 | sub sqr_add_c2 | ||
| 20 | { | ||
| 21 | local($a,$b,$c0,$c1,$c2)=@_; | ||
| 22 | local($l1,$h1,$t1,$t2); | ||
| 23 | |||
| 24 | &mul($a,$b,($l1)=&NR(1)); | ||
| 25 | &muh($a,$b,($h1)=&NR(1)); | ||
| 26 | &cmplt($l1,"zero",($lc1)=&NR(1)); | ||
| 27 | &cmplt($h1,"zero",($hc1)=&NR(1)); | ||
| 28 | &add($l1,$l1,$l1); | ||
| 29 | &add($h1,$h1,$h1); | ||
| 30 | &add($h1,$lc1,$h1); &FR($lc1); | ||
| 31 | &add($c2,$hc1,$c2); &FR($hc1); | ||
| 32 | |||
| 33 | &add($c0,$l1,$c0); | ||
| 34 | &add($c1,$h1,$c1); | ||
| 35 | &cmpult($c0,$l1,($lc1)=&NR(1)); &FR($l1); | ||
| 36 | &cmpult($c1,$h1,($hc1)=&NR(1)); &FR($h1); | ||
| 37 | |||
| 38 | &add($c1,$lc1,$c1); &FR($lc1); | ||
| 39 | &add($c2,$hc1,$c2); &FR($hc1); | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | sub bn_sqr_comba4 | ||
| 44 | { | ||
| 45 | local($name)=@_; | ||
| 46 | local(@a,@b,$r,$c0,$c1,$c2); | ||
| 47 | |||
| 48 | $cnt=1; | ||
| 49 | &init_pool(2); | ||
| 50 | |||
| 51 | $rp=&wparam(0); | ||
| 52 | $ap=&wparam(1); | ||
| 53 | |||
| 54 | &function_begin($name,""); | ||
| 55 | |||
| 56 | &comment(""); | ||
| 57 | |||
| 58 | &ld(($a[0])=&NR(1),&QWPw(0,$ap)); | ||
| 59 | &ld(($a[1])=&NR(1),&QWPw(1,$ap)); | ||
| 60 | &ld(($a[2])=&NR(1),&QWPw(2,$ap)); | ||
| 61 | &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap); | ||
| 62 | |||
| 63 | ($c0,$c1,$c2)=&NR(3); | ||
| 64 | |||
| 65 | &mov("zero",$c2); | ||
| 66 | &mul($a[0],$a[0],$c0); | ||
| 67 | &muh($a[0],$a[0],$c1); | ||
| 68 | &st($c0,&QWPw(0,$rp)); | ||
| 69 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 70 | &mov("zero",$c2); | ||
| 71 | |||
| 72 | &sqr_add_c2($a[0],$a[1],$c0,$c1,$c2); | ||
| 73 | &st($c0,&QWPw(1,$rp)); | ||
| 74 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 75 | &mov("zero",$c2); | ||
| 76 | |||
| 77 | &sqr_add_c($a[1],$c0,$c1,$c2); | ||
| 78 | &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2); | ||
| 79 | &st($c0,&QWPw(2,$rp)); | ||
| 80 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 81 | &mov("zero",$c2); | ||
| 82 | |||
| 83 | &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2); | ||
| 84 | &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2); | ||
| 85 | &st($c0,&QWPw(3,$rp)); | ||
| 86 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 87 | &mov("zero",$c2); | ||
| 88 | |||
| 89 | &sqr_add_c($a[2],$c0,$c1,$c2); | ||
| 90 | &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2); | ||
| 91 | &st($c0,&QWPw(4,$rp)); | ||
| 92 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 93 | &mov("zero",$c2); | ||
| 94 | |||
| 95 | &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2); | ||
| 96 | &st($c0,&QWPw(5,$rp)); | ||
| 97 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 98 | &mov("zero",$c2); | ||
| 99 | |||
| 100 | &sqr_add_c($a[3],$c0,$c1,$c2); | ||
| 101 | &st($c0,&QWPw(6,$rp)); | ||
| 102 | &st($c1,&QWPw(7,$rp)); | ||
| 103 | |||
| 104 | &function_end($name); | ||
| 105 | |||
| 106 | &fin_pool; | ||
| 107 | } | ||
| 108 | |||
| 109 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sqr_c8.pl b/src/lib/libcrypto/bn/asm/alpha.works/sqr_c8.pl deleted file mode 100644 index b4afe085f1..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.works/sqr_c8.pl +++ /dev/null | |||
| @@ -1,132 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_sqr_comba8 | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local(@a,@b,$r,$c0,$c1,$c2); | ||
| 8 | |||
| 9 | $cnt=1; | ||
| 10 | &init_pool(2); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | |||
| 15 | &function_begin($name,""); | ||
| 16 | |||
| 17 | &comment(""); | ||
| 18 | |||
| 19 | &ld(($a[0])=&NR(1),&QWPw(0,$ap)); | ||
| 20 | &ld(($a[1])=&NR(1),&QWPw(1,$ap)); | ||
| 21 | &ld(($a[2])=&NR(1),&QWPw(2,$ap)); | ||
| 22 | &ld(($a[3])=&NR(1),&QWPw(3,$ap)); | ||
| 23 | &ld(($a[4])=&NR(1),&QWPw(4,$ap)); | ||
| 24 | &ld(($a[5])=&NR(1),&QWPw(5,$ap)); | ||
| 25 | &ld(($a[6])=&NR(1),&QWPw(6,$ap)); | ||
| 26 | &ld(($a[7])=&NR(1),&QWPw(7,$ap)); &FR($ap); | ||
| 27 | |||
| 28 | ($c0,$c1,$c2)=&NR(3); | ||
| 29 | |||
| 30 | &mov("zero",$c2); | ||
| 31 | &mul($a[0],$a[0],$c0); | ||
| 32 | &muh($a[0],$a[0],$c1); | ||
| 33 | &st($c0,&QWPw(0,$rp)); | ||
| 34 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 35 | &mov("zero",$c2); | ||
| 36 | |||
| 37 | &sqr_add_c2($a[1],$a[0],$c0,$c1,$c2); | ||
| 38 | &st($c0,&QWPw(1,$rp)); | ||
| 39 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 40 | &mov("zero",$c2); | ||
| 41 | |||
| 42 | &sqr_add_c($a[1],$c0,$c1,$c2); | ||
| 43 | &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2); | ||
| 44 | &st($c0,&QWPw(2,$rp)); | ||
| 45 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 46 | &mov("zero",$c2); | ||
| 47 | |||
| 48 | &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2); | ||
| 49 | &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2); | ||
| 50 | &st($c0,&QWPw(3,$rp)); | ||
| 51 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 52 | &mov("zero",$c2); | ||
| 53 | |||
| 54 | &sqr_add_c($a[2],$c0,$c1,$c2); | ||
| 55 | &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2); | ||
| 56 | &sqr_add_c2($a[4],$a[0],$c0,$c1,$c2); | ||
| 57 | &st($c0,&QWPw(4,$rp)); | ||
| 58 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 59 | &mov("zero",$c2); | ||
| 60 | |||
| 61 | &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2); | ||
| 62 | &sqr_add_c2($a[4],$a[1],$c0,$c1,$c2); | ||
| 63 | &sqr_add_c2($a[5],$a[0],$c0,$c1,$c2); | ||
| 64 | &st($c0,&QWPw(5,$rp)); | ||
| 65 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 66 | &mov("zero",$c2); | ||
| 67 | |||
| 68 | &sqr_add_c($a[3],$c0,$c1,$c2); | ||
| 69 | &sqr_add_c2($a[4],$a[2],$c0,$c1,$c2); | ||
| 70 | &sqr_add_c2($a[5],$a[1],$c0,$c1,$c2); | ||
| 71 | &sqr_add_c2($a[6],$a[0],$c0,$c1,$c2); | ||
| 72 | &st($c0,&QWPw(6,$rp)); | ||
| 73 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 74 | &mov("zero",$c2); | ||
| 75 | |||
| 76 | &sqr_add_c2($a[4],$a[3],$c0,$c1,$c2); | ||
| 77 | &sqr_add_c2($a[5],$a[2],$c0,$c1,$c2); | ||
| 78 | &sqr_add_c2($a[6],$a[1],$c0,$c1,$c2); | ||
| 79 | &sqr_add_c2($a[7],$a[0],$c0,$c1,$c2); | ||
| 80 | &st($c0,&QWPw(7,$rp)); | ||
| 81 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 82 | &mov("zero",$c2); | ||
| 83 | |||
| 84 | &sqr_add_c($a[4],$c0,$c1,$c2); | ||
| 85 | &sqr_add_c2($a[5],$a[3],$c0,$c1,$c2); | ||
| 86 | &sqr_add_c2($a[6],$a[2],$c0,$c1,$c2); | ||
| 87 | &sqr_add_c2($a[7],$a[1],$c0,$c1,$c2); | ||
| 88 | &st($c0,&QWPw(8,$rp)); | ||
| 89 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 90 | &mov("zero",$c2); | ||
| 91 | |||
| 92 | &sqr_add_c2($a[5],$a[4],$c0,$c1,$c2); | ||
| 93 | &sqr_add_c2($a[6],$a[3],$c0,$c1,$c2); | ||
| 94 | &sqr_add_c2($a[7],$a[2],$c0,$c1,$c2); | ||
| 95 | &st($c0,&QWPw(9,$rp)); | ||
| 96 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 97 | &mov("zero",$c2); | ||
| 98 | |||
| 99 | &sqr_add_c($a[5],$c0,$c1,$c2); | ||
| 100 | &sqr_add_c2($a[6],$a[4],$c0,$c1,$c2); | ||
| 101 | &sqr_add_c2($a[7],$a[3],$c0,$c1,$c2); | ||
| 102 | &st($c0,&QWPw(10,$rp)); | ||
| 103 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 104 | &mov("zero",$c2); | ||
| 105 | |||
| 106 | &sqr_add_c2($a[6],$a[5],$c0,$c1,$c2); | ||
| 107 | &sqr_add_c2($a[7],$a[4],$c0,$c1,$c2); | ||
| 108 | &st($c0,&QWPw(11,$rp)); | ||
| 109 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 110 | &mov("zero",$c2); | ||
| 111 | |||
| 112 | &sqr_add_c($a[6],$c0,$c1,$c2); | ||
| 113 | &sqr_add_c2($a[7],$a[5],$c0,$c1,$c2); | ||
| 114 | &st($c0,&QWPw(12,$rp)); | ||
| 115 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 116 | &mov("zero",$c2); | ||
| 117 | |||
| 118 | &sqr_add_c2($a[7],$a[6],$c0,$c1,$c2); | ||
| 119 | &st($c0,&QWPw(13,$rp)); | ||
| 120 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 121 | &mov("zero",$c2); | ||
| 122 | |||
| 123 | &sqr_add_c($a[7],$c0,$c1,$c2); | ||
| 124 | &st($c0,&QWPw(14,$rp)); | ||
| 125 | &st($c1,&QWPw(15,$rp)); | ||
| 126 | |||
| 127 | &function_end($name); | ||
| 128 | |||
| 129 | &fin_pool; | ||
| 130 | } | ||
| 131 | |||
| 132 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sub.pl b/src/lib/libcrypto/bn/asm/alpha.works/sub.pl deleted file mode 100644 index d998da5c21..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha.works/sub.pl +++ /dev/null | |||
| @@ -1,108 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_sub_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local($cc,$a,$b,$r); | ||
| 8 | |||
| 9 | &init_pool(4); | ||
| 10 | ($cc)=GR("r0"); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $bp=&wparam(2); | ||
| 15 | $count=&wparam(3); | ||
| 16 | |||
| 17 | &function_begin($name,""); | ||
| 18 | |||
| 19 | &comment(""); | ||
| 20 | &sub($count,4,$count); | ||
| 21 | &mov("zero",$cc); | ||
| 22 | &blt($count,&label("finish")); | ||
| 23 | |||
| 24 | ($a0,$b0)=&NR(2); | ||
| 25 | &ld($a0,&QWPw(0,$ap)); | ||
| 26 | &ld($b0,&QWPw(0,$bp)); | ||
| 27 | |||
| 28 | ########################################################## | ||
| 29 | &set_label("loop"); | ||
| 30 | |||
| 31 | ($a1,$tmp,$b1,$a2,$b2,$a3,$b3,$o0)=&NR(8); | ||
| 32 | &ld($a1,&QWPw(1,$ap)); | ||
| 33 | &cmpult($a0,$b0,$tmp); # will we borrow? | ||
| 34 | &ld($b1,&QWPw(1,$bp)); | ||
| 35 | &sub($a0,$b0,$a0); # do the subtract | ||
| 36 | &ld($a2,&QWPw(2,$ap)); | ||
| 37 | &cmpult($a0,$cc,$b0); # will we borrow? | ||
| 38 | &ld($b2,&QWPw(2,$bp)); | ||
| 39 | &sub($a0,$cc,$o0); # will we borrow? | ||
| 40 | &ld($a3,&QWPw(3,$ap)); | ||
| 41 | &add($b0,$tmp,$cc); ($t1,$o1)=&NR(2); &FR($tmp); | ||
| 42 | |||
| 43 | &cmpult($a1,$b1,$t1); # will we borrow? | ||
| 44 | &sub($a1,$b1,$a1); # do the subtract | ||
| 45 | &ld($b3,&QWPw(3,$bp)); | ||
| 46 | &cmpult($a1,$cc,$b1); # will we borrow? | ||
| 47 | &sub($a1,$cc,$o1); # will we borrow? | ||
| 48 | &add($b1,$t1,$cc); ($tmp,$o2)=&NR(2); &FR($t1,$a1,$b1); | ||
| 49 | |||
| 50 | &cmpult($a2,$b2,$tmp); # will we borrow? | ||
| 51 | &sub($a2,$b2,$a2); # do the subtract | ||
| 52 | &st($o0,&QWPw(0,$rp)); &FR($o0); # save | ||
| 53 | &cmpult($a2,$cc,$b2); # will we borrow? | ||
| 54 | &sub($a2,$cc,$o2); # will we borrow? | ||
| 55 | &add($b2,$tmp,$cc); ($t3,$o3)=&NR(2); &FR($tmp,$a2,$b2); | ||
| 56 | |||
| 57 | &cmpult($a3,$b3,$t3); # will we borrow? | ||
| 58 | &sub($a3,$b3,$a3); # do the subtract | ||
| 59 | &st($o1,&QWPw(1,$rp)); &FR($o1); | ||
| 60 | &cmpult($a3,$cc,$b3); # will we borrow? | ||
| 61 | &sub($a3,$cc,$o3); # will we borrow? | ||
| 62 | &add($b3,$t3,$cc); &FR($t3,$a3,$b3); | ||
| 63 | |||
| 64 | &st($o2,&QWPw(2,$rp)); &FR($o2); | ||
| 65 | &sub($count,4,$count); # count-=4 | ||
| 66 | &st($o3,&QWPw(3,$rp)); &FR($o3); | ||
| 67 | &add($ap,4*$QWS,$ap); # count+=4 | ||
| 68 | &add($bp,4*$QWS,$bp); # count+=4 | ||
| 69 | &add($rp,4*$QWS,$rp); # count+=4 | ||
| 70 | |||
| 71 | &blt($count,&label("finish")); | ||
| 72 | &ld($a0,&QWPw(0,$ap)); | ||
| 73 | &ld($b0,&QWPw(0,$bp)); | ||
| 74 | &br(&label("loop")); | ||
| 75 | ################################################## | ||
| 76 | # Do the last 0..3 words | ||
| 77 | |||
| 78 | &set_label("last_loop"); | ||
| 79 | |||
| 80 | &ld($a0,&QWPw(0,$ap)); # get a | ||
| 81 | &ld($b0,&QWPw(0,$bp)); # get b | ||
| 82 | &cmpult($a0,$b0,$tmp); # will we borrow? | ||
| 83 | &sub($a0,$b0,$a0); # do the subtract | ||
| 84 | &cmpult($a0,$cc,$b0); # will we borrow? | ||
| 85 | &sub($a0,$cc,$a0); # will we borrow? | ||
| 86 | &st($a0,&QWPw(0,$rp)); # save | ||
| 87 | &add($b0,$tmp,$cc); # add the borrows | ||
| 88 | |||
| 89 | &add($ap,$QWS,$ap); | ||
| 90 | &add($bp,$QWS,$bp); | ||
| 91 | &add($rp,$QWS,$rp); | ||
| 92 | &sub($count,1,$count); | ||
| 93 | &bgt($count,&label("last_loop")); | ||
| 94 | &function_end_A($name); | ||
| 95 | |||
| 96 | ###################################################### | ||
| 97 | &set_label("finish"); | ||
| 98 | &add($count,4,$count); | ||
| 99 | &bgt($count,&label("last_loop")); | ||
| 100 | |||
| 101 | &FR($a0,$b0); | ||
| 102 | &set_label("end"); | ||
| 103 | &function_end($name); | ||
| 104 | |||
| 105 | &fin_pool; | ||
| 106 | } | ||
| 107 | |||
| 108 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha/add.pl b/src/lib/libcrypto/bn/asm/alpha/add.pl deleted file mode 100644 index 13bf516428..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha/add.pl +++ /dev/null | |||
| @@ -1,118 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_add_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local($cc,$a,$b,$r); | ||
| 8 | |||
| 9 | &init_pool(4); | ||
| 10 | ($cc)=GR("r0"); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $bp=&wparam(2); | ||
| 15 | $count=&wparam(3); | ||
| 16 | |||
| 17 | &function_begin($name,""); | ||
| 18 | |||
| 19 | &comment(""); | ||
| 20 | &sub($count,4,$count); | ||
| 21 | &mov("zero",$cc); | ||
| 22 | &blt($count,&label("finish")); | ||
| 23 | |||
| 24 | ($a0,$b0)=&NR(2); | ||
| 25 | |||
| 26 | ########################################################## | ||
| 27 | &set_label("loop"); | ||
| 28 | |||
| 29 | &ld(($a0)=&NR(1),&QWPw(0,$ap)); | ||
| 30 | &ld(($b0)=&NR(1),&QWPw(0,$bp)); | ||
| 31 | &ld(($a1)=&NR(1),&QWPw(1,$ap)); | ||
| 32 | &ld(($b1)=&NR(1),&QWPw(1,$bp)); | ||
| 33 | |||
| 34 | ($o0,$t0)=&NR(2); | ||
| 35 | &add($a0,$b0,$o0); | ||
| 36 | &ld(($a2)=&NR(1),&QWPw(2,$ap)); | ||
| 37 | &cmpult($o0,$b0,$t0); | ||
| 38 | &add($o0,$cc,$o0); | ||
| 39 | &cmpult($o0,$cc,$cc); | ||
| 40 | &ld(($b2)=&NR(1),&QWPw(2,$bp)); | ||
| 41 | &add($cc,$t0,$cc); &FR($t0); | ||
| 42 | |||
| 43 | ($t1,$o1)=&NR(2); | ||
| 44 | |||
| 45 | &add($a1,$b1,$o1); &FR($a1); | ||
| 46 | &cmpult($o1,$b1,$t1); &FR($b1); | ||
| 47 | &add($o1,$cc,$o1); | ||
| 48 | &cmpult($o1,$cc,$cc); | ||
| 49 | &ld(($a3)=&NR(1),&QWPw(3,$ap)); | ||
| 50 | &add($cc,$t1,$cc); &FR($t1); | ||
| 51 | |||
| 52 | ($t2,$o2)=&NR(2); | ||
| 53 | |||
| 54 | &add($a2,$b2,$o2); &FR($a2); | ||
| 55 | &cmpult($o2,$b2,$t2); &FR($b2); | ||
| 56 | &add($o2,$cc,$o2); | ||
| 57 | &cmpult($o2,$cc,$cc); | ||
| 58 | &ld(($b3)=&NR(1),&QWPw(3,$bp)); | ||
| 59 | &st($o0,&QWPw(0,$rp)); &FR($o0); | ||
| 60 | &add($cc,$t2,$cc); &FR($t2); | ||
| 61 | |||
| 62 | ($t3,$o3)=&NR(2); | ||
| 63 | |||
| 64 | &st($o1,&QWPw(0,$rp)); &FR($o1); | ||
| 65 | &add($a3,$b3,$o3); &FR($a3); | ||
| 66 | &cmpult($o3,$b3,$t3); &FR($b3); | ||
| 67 | &add($o3,$cc,$o3); | ||
| 68 | &st($o2,&QWPw(0,$rp)); &FR($o2); | ||
| 69 | &cmpult($o3,$cc,$cc); | ||
| 70 | &st($o3,&QWPw(0,$rp)); &FR($o3); | ||
| 71 | &add($cc,$t3,$cc); &FR($t3); | ||
| 72 | |||
| 73 | |||
| 74 | &sub($count,4,$count); # count-=4 | ||
| 75 | &add($ap,4*$QWS,$ap); # count+=4 | ||
| 76 | &add($bp,4*$QWS,$bp); # count+=4 | ||
| 77 | &add($rp,4*$QWS,$rp); # count+=4 | ||
| 78 | |||
| 79 | ### | ||
| 80 | &bge($count,&label("loop")); | ||
| 81 | ### | ||
| 82 | &br(&label("finish")); | ||
| 83 | ################################################## | ||
| 84 | # Do the last 0..3 words | ||
| 85 | |||
| 86 | ($t0,$o0)=&NR(2); | ||
| 87 | &set_label("last_loop"); | ||
| 88 | |||
| 89 | &ld($a0,&QWPw(0,$ap)); # get a | ||
| 90 | &ld($b0,&QWPw(0,$bp)); # get b | ||
| 91 | &add($ap,$QWS,$ap); | ||
| 92 | &add($bp,$QWS,$bp); | ||
| 93 | &add($a0,$b0,$o0); | ||
| 94 | &sub($count,1,$count); | ||
| 95 | &cmpult($o0,$b0,$t0); # will we borrow? | ||
| 96 | &add($o0,$cc,$o0); # will we borrow? | ||
| 97 | &cmpult($o0,$cc,$cc); # will we borrow? | ||
| 98 | &add($rp,$QWS,$rp); | ||
| 99 | &st($o0,&QWPw(-1,$rp)); # save | ||
| 100 | &add($cc,$t0,$cc); # add the borrows | ||
| 101 | |||
| 102 | ### | ||
| 103 | &bgt($count,&label("last_loop")); | ||
| 104 | &function_end_A($name); | ||
| 105 | |||
| 106 | ###################################################### | ||
| 107 | &set_label("finish"); | ||
| 108 | &add($count,4,$count); | ||
| 109 | &bgt($count,&label("last_loop")); | ||
| 110 | |||
| 111 | &FR($o0,$t0,$a0,$b0); | ||
| 112 | &set_label("end"); | ||
| 113 | &function_end($name); | ||
| 114 | |||
| 115 | &fin_pool; | ||
| 116 | } | ||
| 117 | |||
| 118 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha/div.pl b/src/lib/libcrypto/bn/asm/alpha/div.pl deleted file mode 100644 index e9e680897a..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha/div.pl +++ /dev/null | |||
| @@ -1,144 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | sub bn_div_words | ||
| 4 | { | ||
| 5 | local($data)=<<'EOF'; | ||
| 6 | # | ||
| 7 | # What follows was taken directly from the C compiler with a few | ||
| 8 | # hacks to redo the lables. | ||
| 9 | # | ||
| 10 | .text | ||
| 11 | .set noreorder | ||
| 12 | .set volatile | ||
| 13 | .align 3 | ||
| 14 | .globl bn_div_words | ||
| 15 | .ent bn_div_words | ||
| 16 | bn_div_words | ||
| 17 | ldgp $29,0($27) | ||
| 18 | bn_div_words.ng: | ||
| 19 | lda $30,-48($30) | ||
| 20 | .frame $30,48,$26,0 | ||
| 21 | stq $26,0($30) | ||
| 22 | stq $9,8($30) | ||
| 23 | stq $10,16($30) | ||
| 24 | stq $11,24($30) | ||
| 25 | stq $12,32($30) | ||
| 26 | stq $13,40($30) | ||
| 27 | .mask 0x4003e00,-48 | ||
| 28 | .prologue 1 | ||
| 29 | bis $16,$16,$9 | ||
| 30 | bis $17,$17,$10 | ||
| 31 | bis $18,$18,$11 | ||
| 32 | bis $31,$31,$13 | ||
| 33 | bis $31,2,$12 | ||
| 34 | bne $11,$9119 | ||
| 35 | lda $0,-1 | ||
| 36 | br $31,$9136 | ||
| 37 | .align 4 | ||
| 38 | $9119: | ||
| 39 | bis $11,$11,$16 | ||
| 40 | jsr $26,BN_num_bits_word | ||
| 41 | ldgp $29,0($26) | ||
| 42 | subq $0,64,$1 | ||
| 43 | beq $1,$9120 | ||
| 44 | bis $31,1,$1 | ||
| 45 | sll $1,$0,$1 | ||
| 46 | cmpule $9,$1,$1 | ||
| 47 | bne $1,$9120 | ||
| 48 | # lda $16,_IO_stderr_ | ||
| 49 | # lda $17,$C32 | ||
| 50 | # bis $0,$0,$18 | ||
| 51 | # jsr $26,fprintf | ||
| 52 | # ldgp $29,0($26) | ||
| 53 | jsr $26,abort | ||
| 54 | ldgp $29,0($26) | ||
| 55 | .align 4 | ||
| 56 | $9120: | ||
| 57 | bis $31,64,$3 | ||
| 58 | cmpult $9,$11,$2 | ||
| 59 | subq $3,$0,$1 | ||
| 60 | addl $1,$31,$0 | ||
| 61 | subq $9,$11,$1 | ||
| 62 | cmoveq $2,$1,$9 | ||
| 63 | beq $0,$9122 | ||
| 64 | zapnot $0,15,$2 | ||
| 65 | subq $3,$0,$1 | ||
| 66 | sll $11,$2,$11 | ||
| 67 | sll $9,$2,$3 | ||
| 68 | srl $10,$1,$1 | ||
| 69 | sll $10,$2,$10 | ||
| 70 | bis $3,$1,$9 | ||
| 71 | $9122: | ||
| 72 | srl $11,32,$5 | ||
| 73 | zapnot $11,15,$6 | ||
| 74 | lda $7,-1 | ||
| 75 | .align 5 | ||
| 76 | $9123: | ||
| 77 | srl $9,32,$1 | ||
| 78 | subq $1,$5,$1 | ||
| 79 | bne $1,$9126 | ||
| 80 | zapnot $7,15,$27 | ||
| 81 | br $31,$9127 | ||
| 82 | .align 4 | ||
| 83 | $9126: | ||
| 84 | bis $9,$9,$24 | ||
| 85 | bis $5,$5,$25 | ||
| 86 | divqu $24,$25,$27 | ||
| 87 | $9127: | ||
| 88 | srl $10,32,$4 | ||
| 89 | .align 5 | ||
| 90 | $9128: | ||
| 91 | mulq $27,$5,$1 | ||
| 92 | subq $9,$1,$3 | ||
| 93 | zapnot $3,240,$1 | ||
| 94 | bne $1,$9129 | ||
| 95 | mulq $6,$27,$2 | ||
| 96 | sll $3,32,$1 | ||
| 97 | addq $1,$4,$1 | ||
| 98 | cmpule $2,$1,$2 | ||
| 99 | bne $2,$9129 | ||
| 100 | subq $27,1,$27 | ||
| 101 | br $31,$9128 | ||
| 102 | .align 4 | ||
| 103 | $9129: | ||
| 104 | mulq $27,$6,$1 | ||
| 105 | mulq $27,$5,$4 | ||
| 106 | srl $1,32,$3 | ||
| 107 | sll $1,32,$1 | ||
| 108 | addq $4,$3,$4 | ||
| 109 | cmpult $10,$1,$2 | ||
| 110 | subq $10,$1,$10 | ||
| 111 | addq $2,$4,$2 | ||
| 112 | cmpult $9,$2,$1 | ||
| 113 | bis $2,$2,$4 | ||
| 114 | beq $1,$9134 | ||
| 115 | addq $9,$11,$9 | ||
| 116 | subq $27,1,$27 | ||
| 117 | $9134: | ||
| 118 | subl $12,1,$12 | ||
| 119 | subq $9,$4,$9 | ||
| 120 | beq $12,$9124 | ||
| 121 | sll $27,32,$13 | ||
| 122 | sll $9,32,$2 | ||
| 123 | srl $10,32,$1 | ||
| 124 | sll $10,32,$10 | ||
| 125 | bis $2,$1,$9 | ||
| 126 | br $31,$9123 | ||
| 127 | .align 4 | ||
| 128 | $9124: | ||
| 129 | bis $13,$27,$0 | ||
| 130 | $9136: | ||
| 131 | ldq $26,0($30) | ||
| 132 | ldq $9,8($30) | ||
| 133 | ldq $10,16($30) | ||
| 134 | ldq $11,24($30) | ||
| 135 | ldq $12,32($30) | ||
| 136 | ldq $13,40($30) | ||
| 137 | addq $30,48,$30 | ||
| 138 | ret $31,($26),1 | ||
| 139 | .end bn_div_words | ||
| 140 | EOF | ||
| 141 | &asm_add($data); | ||
| 142 | } | ||
| 143 | |||
| 144 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul.pl b/src/lib/libcrypto/bn/asm/alpha/mul.pl deleted file mode 100644 index 76c926566c..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha/mul.pl +++ /dev/null | |||
| @@ -1,104 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_mul_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local($cc,$a,$b,$r,$couny); | ||
| 8 | |||
| 9 | &init_pool(4); | ||
| 10 | ($cc)=GR("r0"); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $count=&wparam(2); | ||
| 15 | $word=&wparam(3); | ||
| 16 | |||
| 17 | &function_begin($name,""); | ||
| 18 | |||
| 19 | &comment(""); | ||
| 20 | &sub($count,4,$count); | ||
| 21 | &mov("zero",$cc); | ||
| 22 | ### | ||
| 23 | &blt($count,&label("finish")); | ||
| 24 | |||
| 25 | ($a0)=&NR(1); &ld($a0,&QWPw(0,$ap)); | ||
| 26 | |||
| 27 | &set_label("loop"); | ||
| 28 | |||
| 29 | ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap)); | ||
| 30 | ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap)); | ||
| 31 | |||
| 32 | &muh($a0,$word,($h0)=&NR(1)); &FR($a0); | ||
| 33 | ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap)); | ||
| 34 | ### wait 8 | ||
| 35 | &mul($a0,$word,($l0)=&NR(1)); &FR($a0); | ||
| 36 | ### wait 8 | ||
| 37 | &muh($a1,$word,($h1)=&NR(1)); &FR($a1); | ||
| 38 | &add($l0,$cc,$l0); ### wait 8 | ||
| 39 | &mul($a1,$word,($l1)=&NR(1)); &FR($a1); | ||
| 40 | &cmpult($l0,$cc,$cc); ### wait 8 | ||
| 41 | &muh($a2,$word,($h2)=&NR(1)); &FR($a2); | ||
| 42 | &add($h0,$cc,$cc); &FR($h0); ### wait 8 | ||
| 43 | &mul($a2,$word,($l2)=&NR(1)); &FR($a2); | ||
| 44 | &add($l1,$cc,$l1); ### wait 8 | ||
| 45 | &st($l0,&QWPw(0,$rp)); &FR($l0); | ||
| 46 | &cmpult($l1,$cc,$cc); ### wait 8 | ||
| 47 | &muh($a3,$word,($h3)=&NR(1)); &FR($a3); | ||
| 48 | &add($h1,$cc,$cc); &FR($h1); | ||
| 49 | &mul($a3,$word,($l3)=&NR(1)); &FR($a3); | ||
| 50 | &add($l2,$cc,$l2); | ||
| 51 | &st($l1,&QWPw(1,$rp)); &FR($l1); | ||
| 52 | &cmpult($l2,$cc,$cc); | ||
| 53 | &add($h2,$cc,$cc); &FR($h2); | ||
| 54 | &sub($count,4,$count); # count-=4 | ||
| 55 | &st($l2,&QWPw(2,$rp)); &FR($l2); | ||
| 56 | &add($l3,$cc,$l3); | ||
| 57 | &cmpult($l3,$cc,$cc); | ||
| 58 | &add($bp,4*$QWS,$bp); # count+=4 | ||
| 59 | &add($h3,$cc,$cc); &FR($h3); | ||
| 60 | &add($ap,4*$QWS,$ap); # count+=4 | ||
| 61 | &st($l3,&QWPw(3,$rp)); &FR($l3); | ||
| 62 | &add($rp,4*$QWS,$rp); # count+=4 | ||
| 63 | ### | ||
| 64 | &blt($count,&label("finish")); | ||
| 65 | ($a0)=&NR(1); &ld($a0,&QWPw(0,$ap)); | ||
| 66 | &br(&label("finish")); | ||
| 67 | ################################################## | ||
| 68 | |||
| 69 | ################################################## | ||
| 70 | # Do the last 0..3 words | ||
| 71 | |||
| 72 | &set_label("last_loop"); | ||
| 73 | |||
| 74 | &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a | ||
| 75 | ### | ||
| 76 | ### | ||
| 77 | ### | ||
| 78 | &muh($a0,$word,($h0)=&NR(1)); | ||
| 79 | ### Wait 8 for next mul issue | ||
| 80 | &mul($a0,$word,($l0)=&NR(1)); &FR($a0) | ||
| 81 | &add($ap,$QWS,$ap); | ||
| 82 | ### Loose 12 until result is available | ||
| 83 | &add($rp,$QWS,$rp); | ||
| 84 | &sub($count,1,$count); | ||
| 85 | &add($l0,$cc,$l0); | ||
| 86 | ### | ||
| 87 | &st($l0,&QWPw(-1,$rp)); &FR($l0); | ||
| 88 | &cmpult($l0,$cc,$cc); | ||
| 89 | &add($h0,$cc,$cc); &FR($h0); | ||
| 90 | &bgt($count,&label("last_loop")); | ||
| 91 | &function_end_A($name); | ||
| 92 | |||
| 93 | ###################################################### | ||
| 94 | &set_label("finish"); | ||
| 95 | &add($count,4,$count); | ||
| 96 | &bgt($count,&label("last_loop")); | ||
| 97 | |||
| 98 | &set_label("end"); | ||
| 99 | &function_end($name); | ||
| 100 | |||
| 101 | &fin_pool; | ||
| 102 | } | ||
| 103 | |||
| 104 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_add.pl b/src/lib/libcrypto/bn/asm/alpha/mul_add.pl deleted file mode 100644 index 0d6df69bc4..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha/mul_add.pl +++ /dev/null | |||
| @@ -1,123 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_mul_add_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local($cc,$a,$b,$r,$couny); | ||
| 8 | |||
| 9 | &init_pool(4); | ||
| 10 | ($cc)=GR("r0"); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $count=&wparam(2); | ||
| 15 | $word=&wparam(3); | ||
| 16 | |||
| 17 | &function_begin($name,""); | ||
| 18 | |||
| 19 | &comment(""); | ||
| 20 | &sub($count,4,$count); | ||
| 21 | &mov("zero",$cc); | ||
| 22 | ### | ||
| 23 | &blt($count,&label("finish")); | ||
| 24 | |||
| 25 | &ld(($a0)=&NR(1),&QWPw(0,$ap)); | ||
| 26 | |||
| 27 | $a=<<'EOF'; | ||
| 28 | ########################################################## | ||
| 29 | &set_label("loop"); | ||
| 30 | |||
| 31 | &ld(($r0)=&NR(1),&QWPw(0,$rp)); | ||
| 32 | &ld(($a1)=&NR(1),&QWPw(1,$ap)); | ||
| 33 | &muh($a0,$word,($h0)=&NR(1)); | ||
| 34 | &ld(($r1)=&NR(1),&QWPw(1,$rp)); | ||
| 35 | &ld(($a2)=&NR(1),&QWPw(2,$ap)); | ||
| 36 | ### | ||
| 37 | &mul($a0,$word,($l0)=&NR(1)); &FR($a0); | ||
| 38 | &ld(($r2)=&NR(1),&QWPw(2,$rp)); | ||
| 39 | &muh($a1,$word,($h1)=&NR(1)); | ||
| 40 | &ld(($a3)=&NR(1),&QWPw(3,$ap)); | ||
| 41 | &mul($a1,$word,($l1)=&NR(1)); &FR($a1); | ||
| 42 | &ld(($r3)=&NR(1),&QWPw(3,$rp)); | ||
| 43 | &add($r0,$l0,$r0); | ||
| 44 | &add($r1,$l1,$r1); | ||
| 45 | &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0); | ||
| 46 | &cmpult($r1,$l1,($t1)=&NR(1)); &FR($l1); | ||
| 47 | &muh($a2,$word,($h2)=&NR(1)); | ||
| 48 | &add($r0,$cc,$r0); | ||
| 49 | &add($h0,$t0,$h0); &FR($t0); | ||
| 50 | &cmpult($r0,$cc,$cc); | ||
| 51 | &add($h1,$t1,$h1); &FR($t1); | ||
| 52 | &add($h0,$cc,$cc); &FR($h0); | ||
| 53 | &mul($a2,$word,($l2)=&NR(1)); &FR($a2); | ||
| 54 | &add($r1,$cc,$r1); | ||
| 55 | &cmpult($r1,$cc,$cc); | ||
| 56 | &add($r2,$l2,$r2); | ||
| 57 | &add($h1,$cc,$cc); &FR($h1); | ||
| 58 | &cmpult($r2,$l2,($t2)=&NR(1)); &FR($l2); | ||
| 59 | &muh($a3,$word,($h3)=&NR(1)); | ||
| 60 | &add($r2,$cc,$r2); | ||
| 61 | &st($r0,&QWPw(0,$rp)); &FR($r0); | ||
| 62 | &add($h2,$t2,$h2); &FR($t2); | ||
| 63 | &st($r1,&QWPw(1,$rp)); &FR($r1); | ||
| 64 | &cmpult($r2,$cc,$cc); | ||
| 65 | &mul($a3,$word,($l3)=&NR(1)); &FR($a3); | ||
| 66 | &add($h2,$cc,$cc); &FR($h2); | ||
| 67 | &st($r2,&QWPw(2,$rp)); &FR($r2); | ||
| 68 | &sub($count,4,$count); # count-=4 | ||
| 69 | &add($rp,4*$QWS,$rp); # count+=4 | ||
| 70 | &add($r3,$l3,$r3); | ||
| 71 | &add($ap,4*$QWS,$ap); # count+=4 | ||
| 72 | &cmpult($r3,$l3,($t3)=&NR(1)); &FR($l3); | ||
| 73 | &add($r3,$cc,$r3); | ||
| 74 | &add($h3,$t3,$h3); &FR($t3); | ||
| 75 | &cmpult($r3,$cc,$cc); | ||
| 76 | &st($r3,&QWPw(-1,$rp)); &FR($r3); | ||
| 77 | &add($h3,$cc,$cc); &FR($h3); | ||
| 78 | |||
| 79 | ### | ||
| 80 | &blt($count,&label("finish")); | ||
| 81 | &ld(($a0)=&NR(1),&QWPw(0,$ap)); | ||
| 82 | &br(&label("loop")); | ||
| 83 | EOF | ||
| 84 | ################################################## | ||
| 85 | # Do the last 0..3 words | ||
| 86 | |||
| 87 | &set_label("last_loop"); | ||
| 88 | |||
| 89 | &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a | ||
| 90 | &ld(($r0)=&NR(1),&QWPw(0,$rp)); # get b | ||
| 91 | ### | ||
| 92 | ### | ||
| 93 | &muh($a0,$word,($h0)=&NR(1)); &FR($a0); | ||
| 94 | ### wait 8 | ||
| 95 | &mul($a0,$word,($l0)=&NR(1)); &FR($a0); | ||
| 96 | &add($rp,$QWS,$rp); | ||
| 97 | &add($ap,$QWS,$ap); | ||
| 98 | &sub($count,1,$count); | ||
| 99 | ### wait 3 until l0 is available | ||
| 100 | &add($r0,$l0,$r0); | ||
| 101 | ### | ||
| 102 | &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0); | ||
| 103 | &add($r0,$cc,$r0); | ||
| 104 | &add($h0,$t0,$h0); &FR($t0); | ||
| 105 | &cmpult($r0,$cc,$cc); | ||
| 106 | &add($h0,$cc,$cc); &FR($h0); | ||
| 107 | |||
| 108 | &st($r0,&QWPw(-1,$rp)); &FR($r0); | ||
| 109 | &bgt($count,&label("last_loop")); | ||
| 110 | &function_end_A($name); | ||
| 111 | |||
| 112 | ###################################################### | ||
| 113 | &set_label("finish"); | ||
| 114 | &add($count,4,$count); | ||
| 115 | &bgt($count,&label("last_loop")); | ||
| 116 | |||
| 117 | &set_label("end"); | ||
| 118 | &function_end($name); | ||
| 119 | |||
| 120 | &fin_pool; | ||
| 121 | } | ||
| 122 | |||
| 123 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_c4.pl b/src/lib/libcrypto/bn/asm/alpha/mul_c4.pl deleted file mode 100644 index 9cc876ded4..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha/mul_c4.pl +++ /dev/null | |||
| @@ -1,215 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | # upto | ||
| 5 | |||
| 6 | sub mul_add_c | ||
| 7 | { | ||
| 8 | local($a,$b,$c0,$c1,$c2)=@_; | ||
| 9 | local($l1,$h1,$t1,$t2); | ||
| 10 | |||
| 11 | &mul($a,$b,($l1)=&NR(1)); | ||
| 12 | &muh($a,$b,($h1)=&NR(1)); | ||
| 13 | &add($c0,$l1,$c0); | ||
| 14 | &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1); | ||
| 15 | &add($t1,$h1,$h1); &FR($t1); | ||
| 16 | &add($c1,$h1,$c1); | ||
| 17 | &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1); | ||
| 18 | &add($c2,$t2,$c2); &FR($t2); | ||
| 19 | } | ||
| 20 | |||
| 21 | sub bn_mul_comba4 | ||
| 22 | { | ||
| 23 | local($name)=@_; | ||
| 24 | local(@a,@b,$r,$c0,$c1,$c2); | ||
| 25 | |||
| 26 | $cnt=1; | ||
| 27 | &init_pool(3); | ||
| 28 | |||
| 29 | $rp=&wparam(0); | ||
| 30 | $ap=&wparam(1); | ||
| 31 | $bp=&wparam(2); | ||
| 32 | |||
| 33 | &function_begin($name,""); | ||
| 34 | |||
| 35 | &comment(""); | ||
| 36 | |||
| 37 | &ld(($a[0])=&NR(1),&QWPw(0,$ap)); | ||
| 38 | &ld(($b[0])=&NR(1),&QWPw(0,$bp)); | ||
| 39 | &ld(($a[1])=&NR(1),&QWPw(1,$ap)); | ||
| 40 | &ld(($b[1])=&NR(1),&QWPw(1,$bp)); | ||
| 41 | &mul($a[0],$b[0],($r00)=&NR(1)); | ||
| 42 | &ld(($a[2])=&NR(1),&QWPw(2,$ap)); | ||
| 43 | &ld(($b[2])=&NR(1),&QWPw(2,$bp)); | ||
| 44 | &muh($a[0],$b[0],($r01)=&NR(1)); | ||
| 45 | &FR($ap); &ld(($a[3])=&NR(1),&QWPw(3,$ap)); | ||
| 46 | &FR($bp); &ld(($b[3])=&NR(1),&QWPw(3,$bp)); | ||
| 47 | &mul($a[0],$b[1],($r02)=&NR(1)); | ||
| 48 | |||
| 49 | ($R,$H1,$H2)=&NR(3); | ||
| 50 | |||
| 51 | &st($r00,&QWPw(0,$rp)); &FR($r00); | ||
| 52 | |||
| 53 | &mov("zero",$R); | ||
| 54 | &mul($a[1],$b[0],($r03)=&NR(1)); | ||
| 55 | |||
| 56 | &mov("zero",$H1); | ||
| 57 | &mov("zero",$H0); | ||
| 58 | &add($R,$r01,$R); | ||
| 59 | &muh($a[0],$b[1],($r04)=&NR(1)); | ||
| 60 | &cmpult($R,$r01,($t01)=&NR(1)); &FR($r01); | ||
| 61 | &add($R,$r02,$R); | ||
| 62 | &add($H1,$t01,$H1) &FR($t01); | ||
| 63 | &muh($a[1],$b[0],($r05)=&NR(1)); | ||
| 64 | &cmpult($R,$r02,($t02)=&NR(1)); &FR($r02); | ||
| 65 | &add($R,$r03,$R); | ||
| 66 | &add($H2,$t02,$H2) &FR($t02); | ||
| 67 | &mul($a[0],$b[2],($r06)=&NR(1)); | ||
| 68 | &cmpult($R,$r03,($t03)=&NR(1)); &FR($r03); | ||
| 69 | &add($H1,$t03,$H1) &FR($t03); | ||
| 70 | &st($R,&QWPw(1,$rp)); | ||
| 71 | &add($H1,$H2,$R); | ||
| 72 | |||
| 73 | &mov("zero",$H1); | ||
| 74 | &add($R,$r04,$R); | ||
| 75 | &mov("zero",$H2); | ||
| 76 | &mul($a[1],$b[1],($r07)=&NR(1)); | ||
| 77 | &cmpult($R,$r04,($t04)=&NR(1)); &FR($r04); | ||
| 78 | &add($R,$r05,$R); | ||
| 79 | &add($H1,$t04,$H1) &FR($t04); | ||
| 80 | &mul($a[2],$b[0],($r08)=&NR(1)); | ||
| 81 | &cmpult($R,$r05,($t05)=&NR(1)); &FR($r05); | ||
| 82 | &add($R,$r01,$R); | ||
| 83 | &add($H2,$t05,$H2) &FR($t05); | ||
| 84 | &muh($a[0],$b[2],($r09)=&NR(1)); | ||
| 85 | &cmpult($R,$r06,($t06)=&NR(1)); &FR($r06); | ||
| 86 | &add($R,$r07,$R); | ||
| 87 | &add($H1,$t06,$H1) &FR($t06); | ||
| 88 | &muh($a[1],$b[1],($r10)=&NR(1)); | ||
| 89 | &cmpult($R,$r07,($t07)=&NR(1)); &FR($r07); | ||
| 90 | &add($R,$r08,$R); | ||
| 91 | &add($H2,$t07,$H2) &FR($t07); | ||
| 92 | &muh($a[2],$b[0],($r11)=&NR(1)); | ||
| 93 | &cmpult($R,$r08,($t08)=&NR(1)); &FR($r08); | ||
| 94 | &add($H1,$t08,$H1) &FR($t08); | ||
| 95 | &st($R,&QWPw(2,$rp)); | ||
| 96 | &add($H1,$H2,$R); | ||
| 97 | |||
| 98 | &mov("zero",$H1); | ||
| 99 | &add($R,$r09,$R); | ||
| 100 | &mov("zero",$H2); | ||
| 101 | &mul($a[0],$b[3],($r12)=&NR(1)); | ||
| 102 | &cmpult($R,$r09,($t09)=&NR(1)); &FR($r09); | ||
| 103 | &add($R,$r10,$R); | ||
| 104 | &add($H1,$t09,$H1) &FR($t09); | ||
| 105 | &mul($a[1],$b[2],($r13)=&NR(1)); | ||
| 106 | &cmpult($R,$r10,($t10)=&NR(1)); &FR($r10); | ||
| 107 | &add($R,$r11,$R); | ||
| 108 | &add($H1,$t10,$H1) &FR($t10); | ||
| 109 | &mul($a[2],$b[1],($r14)=&NR(1)); | ||
| 110 | &cmpult($R,$r11,($t11)=&NR(1)); &FR($r11); | ||
| 111 | &add($R,$r12,$R); | ||
| 112 | &add($H1,$t11,$H1) &FR($t11); | ||
| 113 | &mul($a[3],$b[0],($r15)=&NR(1)); | ||
| 114 | &cmpult($R,$r12,($t12)=&NR(1)); &FR($r12); | ||
| 115 | &add($R,$r13,$R); | ||
| 116 | &add($H1,$t12,$H1) &FR($t12); | ||
| 117 | &muh($a[0],$b[3],($r16)=&NR(1)); | ||
| 118 | &cmpult($R,$r13,($t13)=&NR(1)); &FR($r13); | ||
| 119 | &add($R,$r14,$R); | ||
| 120 | &add($H1,$t13,$H1) &FR($t13); | ||
| 121 | &muh($a[1],$b[2],($r17)=&NR(1)); | ||
| 122 | &cmpult($R,$r14,($t14)=&NR(1)); &FR($r14); | ||
| 123 | &add($R,$r15,$R); | ||
| 124 | &add($H1,$t14,$H1) &FR($t14); | ||
| 125 | &muh($a[2],$b[1],($r18)=&NR(1)); | ||
| 126 | &cmpult($R,$r15,($t15)=&NR(1)); &FR($r15); | ||
| 127 | &add($H1,$t15,$H1) &FR($t15); | ||
| 128 | &st($R,&QWPw(3,$rp)); | ||
| 129 | &add($H1,$H2,$R); | ||
| 130 | |||
| 131 | &mov("zero",$H1); | ||
| 132 | &add($R,$r16,$R); | ||
| 133 | &mov("zero",$H2); | ||
| 134 | &muh($a[3],$b[0],($r19)=&NR(1)); | ||
| 135 | &cmpult($R,$r16,($t16)=&NR(1)); &FR($r16); | ||
| 136 | &add($R,$r17,$R); | ||
| 137 | &add($H1,$t16,$H1) &FR($t16); | ||
| 138 | &mul($a[1],$b[3],($r20)=&NR(1)); | ||
| 139 | &cmpult($R,$r17,($t17)=&NR(1)); &FR($r17); | ||
| 140 | &add($R,$r18,$R); | ||
| 141 | &add($H1,$t17,$H1) &FR($t17); | ||
| 142 | &mul($a[2],$b[2],($r21)=&NR(1)); | ||
| 143 | &cmpult($R,$r18,($t18)=&NR(1)); &FR($r18); | ||
| 144 | &add($R,$r19,$R); | ||
| 145 | &add($H1,$t18,$H1) &FR($t18); | ||
| 146 | &mul($a[3],$b[1],($r22)=&NR(1)); | ||
| 147 | &cmpult($R,$r19,($t19)=&NR(1)); &FR($r19); | ||
| 148 | &add($R,$r20,$R); | ||
| 149 | &add($H1,$t19,$H1) &FR($t19); | ||
| 150 | &muh($a[1],$b[3],($r23)=&NR(1)); | ||
| 151 | &cmpult($R,$r20,($t20)=&NR(1)); &FR($r20); | ||
| 152 | &add($R,$r21,$R); | ||
| 153 | &add($H1,$t20,$H1) &FR($t20); | ||
| 154 | &muh($a[2],$b[2],($r24)=&NR(1)); | ||
| 155 | &cmpult($R,$r21,($t21)=&NR(1)); &FR($r21); | ||
| 156 | &add($R,$r22,$R); | ||
| 157 | &add($H1,$t21,$H1) &FR($t21); | ||
| 158 | &muh($a[3],$b[1],($r25)=&NR(1)); | ||
| 159 | &cmpult($R,$r22,($t22)=&NR(1)); &FR($r22); | ||
| 160 | &add($H1,$t22,$H1) &FR($t22); | ||
| 161 | &st($R,&QWPw(4,$rp)); | ||
| 162 | &add($H1,$H2,$R); | ||
| 163 | |||
| 164 | &mov("zero",$H1); | ||
| 165 | &add($R,$r23,$R); | ||
| 166 | &mov("zero",$H2); | ||
| 167 | &mul($a[2],$b[3],($r26)=&NR(1)); | ||
| 168 | &cmpult($R,$r23,($t23)=&NR(1)); &FR($r23); | ||
| 169 | &add($R,$r24,$R); | ||
| 170 | &add($H1,$t23,$H1) &FR($t23); | ||
| 171 | &mul($a[3],$b[2],($r27)=&NR(1)); | ||
| 172 | &cmpult($R,$r24,($t24)=&NR(1)); &FR($r24); | ||
| 173 | &add($R,$r25,$R); | ||
| 174 | &add($H1,$t24,$H1) &FR($t24); | ||
| 175 | &muh($a[2],$b[3],($r28)=&NR(1)); | ||
| 176 | &cmpult($R,$r25,($t25)=&NR(1)); &FR($r25); | ||
| 177 | &add($R,$r26,$R); | ||
| 178 | &add($H1,$t25,$H1) &FR($t25); | ||
| 179 | &muh($a[3],$b[2],($r29)=&NR(1)); | ||
| 180 | &cmpult($R,$r26,($t26)=&NR(1)); &FR($r26); | ||
| 181 | &add($R,$r27,$R); | ||
| 182 | &add($H1,$t26,$H1) &FR($t26); | ||
| 183 | &mul($a[3],$b[3],($r30)=&NR(1)); | ||
| 184 | &cmpult($R,$r27,($t27)=&NR(1)); &FR($r27); | ||
| 185 | &add($H1,$t27,$H1) &FR($t27); | ||
| 186 | &st($R,&QWPw(5,$rp)); | ||
| 187 | &add($H1,$H2,$R); | ||
| 188 | |||
| 189 | &mov("zero",$H1); | ||
| 190 | &add($R,$r28,$R); | ||
| 191 | &mov("zero",$H2); | ||
| 192 | &muh($a[3],$b[3],($r31)=&NR(1)); | ||
| 193 | &cmpult($R,$r28,($t28)=&NR(1)); &FR($r28); | ||
| 194 | &add($R,$r29,$R); | ||
| 195 | &add($H1,$t28,$H1) &FR($t28); | ||
| 196 | ############ | ||
| 197 | &cmpult($R,$r29,($t29)=&NR(1)); &FR($r29); | ||
| 198 | &add($R,$r30,$R); | ||
| 199 | &add($H1,$t29,$H1) &FR($t29); | ||
| 200 | ############ | ||
| 201 | &cmpult($R,$r30,($t30)=&NR(1)); &FR($r30); | ||
| 202 | &add($H1,$t30,$H1) &FR($t30); | ||
| 203 | &st($R,&QWPw(6,$rp)); | ||
| 204 | &add($H1,$H2,$R); | ||
| 205 | |||
| 206 | &add($R,$r31,$R); &FR($r31); | ||
| 207 | &st($R,&QWPw(7,$rp)); | ||
| 208 | |||
| 209 | &FR($R,$H1,$H2); | ||
| 210 | &function_end($name); | ||
| 211 | |||
| 212 | &fin_pool; | ||
| 213 | } | ||
| 214 | |||
| 215 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_c4.works.pl b/src/lib/libcrypto/bn/asm/alpha/mul_c4.works.pl deleted file mode 100644 index 79d86dd25c..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha/mul_c4.works.pl +++ /dev/null | |||
| @@ -1,98 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub mul_add_c | ||
| 5 | { | ||
| 6 | local($a,$b,$c0,$c1,$c2)=@_; | ||
| 7 | local($l1,$h1,$t1,$t2); | ||
| 8 | |||
| 9 | print STDERR "count=$cnt\n"; $cnt++; | ||
| 10 | &mul($a,$b,($l1)=&NR(1)); | ||
| 11 | &muh($a,$b,($h1)=&NR(1)); | ||
| 12 | &add($c0,$l1,$c0); | ||
| 13 | &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1); | ||
| 14 | &add($t1,$h1,$h1); &FR($t1); | ||
| 15 | &add($c1,$h1,$c1); | ||
| 16 | &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1); | ||
| 17 | &add($c2,$t2,$c2); &FR($t2); | ||
| 18 | } | ||
| 19 | |||
| 20 | sub bn_mul_comba4 | ||
| 21 | { | ||
| 22 | local($name)=@_; | ||
| 23 | local(@a,@b,$r,$c0,$c1,$c2); | ||
| 24 | |||
| 25 | $cnt=1; | ||
| 26 | &init_pool(3); | ||
| 27 | |||
| 28 | $rp=&wparam(0); | ||
| 29 | $ap=&wparam(1); | ||
| 30 | $bp=&wparam(2); | ||
| 31 | |||
| 32 | &function_begin($name,""); | ||
| 33 | |||
| 34 | &comment(""); | ||
| 35 | |||
| 36 | &ld(($a[0])=&NR(1),&QWPw(0,$ap)); | ||
| 37 | &ld(($b[0])=&NR(1),&QWPw(0,$bp)); | ||
| 38 | &ld(($a[1])=&NR(1),&QWPw(1,$ap)); | ||
| 39 | &ld(($b[1])=&NR(1),&QWPw(1,$bp)); | ||
| 40 | &ld(($a[2])=&NR(1),&QWPw(2,$ap)); | ||
| 41 | &ld(($b[2])=&NR(1),&QWPw(2,$bp)); | ||
| 42 | &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap); | ||
| 43 | &ld(($b[3])=&NR(1),&QWPw(3,$bp)); &FR($bp); | ||
| 44 | |||
| 45 | ($c0,$c1,$c2)=&NR(3); | ||
| 46 | &mov("zero",$c2); | ||
| 47 | &mul($a[0],$b[0],$c0); | ||
| 48 | &muh($a[0],$b[0],$c1); | ||
| 49 | &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 50 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 51 | &mov("zero",$c2); | ||
| 52 | |||
| 53 | &mul_add_c($a[0],$b[1],$c0,$c1,$c2); | ||
| 54 | &mul_add_c($a[1],$b[0],$c0,$c1,$c2); | ||
| 55 | &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 56 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 57 | &mov("zero",$c2); | ||
| 58 | |||
| 59 | &mul_add_c($a[1],$b[1],$c0,$c1,$c2); | ||
| 60 | &mul_add_c($a[0],$b[2],$c0,$c1,$c2); | ||
| 61 | &mul_add_c($a[2],$b[0],$c0,$c1,$c2); | ||
| 62 | &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 63 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 64 | &mov("zero",$c2); | ||
| 65 | |||
| 66 | &mul_add_c($a[0],$b[3],$c0,$c1,$c2); &FR($a[0]); | ||
| 67 | &mul_add_c($a[1],$b[2],$c0,$c1,$c2); | ||
| 68 | &mul_add_c($a[2],$b[1],$c0,$c1,$c2); | ||
| 69 | &mul_add_c($a[3],$b[0],$c0,$c1,$c2); &FR($b[0]); | ||
| 70 | &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 71 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 72 | &mov("zero",$c2); | ||
| 73 | |||
| 74 | &mul_add_c($a[1],$b[3],$c0,$c1,$c2); &FR($a[1]); | ||
| 75 | &mul_add_c($a[2],$b[2],$c0,$c1,$c2); | ||
| 76 | &mul_add_c($a[3],$b[1],$c0,$c1,$c2); &FR($b[1]); | ||
| 77 | &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 78 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 79 | &mov("zero",$c2); | ||
| 80 | |||
| 81 | &mul_add_c($a[2],$b[3],$c0,$c1,$c2); &FR($a[2]); | ||
| 82 | &mul_add_c($a[3],$b[2],$c0,$c1,$c2); &FR($b[2]); | ||
| 83 | &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR($c0); | ||
| 84 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 85 | &mov("zero",$c2); | ||
| 86 | |||
| 87 | &mul_add_c($a[3],$b[3],$c0,$c1,$c2); &FR($a[3],$b[3]); | ||
| 88 | &st($c0,&QWPw(6,$rp)); | ||
| 89 | &st($c1,&QWPw(7,$rp)); | ||
| 90 | |||
| 91 | &FR($c0,$c1,$c2); | ||
| 92 | |||
| 93 | &function_end($name); | ||
| 94 | |||
| 95 | &fin_pool; | ||
| 96 | } | ||
| 97 | |||
| 98 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_c8.pl b/src/lib/libcrypto/bn/asm/alpha/mul_c8.pl deleted file mode 100644 index 525ca7494b..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha/mul_c8.pl +++ /dev/null | |||
| @@ -1,177 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_mul_comba8 | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local(@a,@b,$r,$c0,$c1,$c2); | ||
| 8 | |||
| 9 | $cnt=1; | ||
| 10 | &init_pool(3); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $bp=&wparam(2); | ||
| 15 | |||
| 16 | &function_begin($name,""); | ||
| 17 | |||
| 18 | &comment(""); | ||
| 19 | |||
| 20 | &stack_push(2); | ||
| 21 | &ld(($a[0])=&NR(1),&QWPw(0,$ap)); | ||
| 22 | &ld(($b[0])=&NR(1),&QWPw(0,$bp)); | ||
| 23 | &st($reg_s0,&swtmp(0)); &FR($reg_s0); | ||
| 24 | &st($reg_s1,&swtmp(1)); &FR($reg_s1); | ||
| 25 | &ld(($a[1])=&NR(1),&QWPw(1,$ap)); | ||
| 26 | &ld(($b[1])=&NR(1),&QWPw(1,$bp)); | ||
| 27 | &ld(($a[2])=&NR(1),&QWPw(2,$ap)); | ||
| 28 | &ld(($b[2])=&NR(1),&QWPw(2,$bp)); | ||
| 29 | &ld(($a[3])=&NR(1),&QWPw(3,$ap)); | ||
| 30 | &ld(($b[3])=&NR(1),&QWPw(3,$bp)); | ||
| 31 | &ld(($a[4])=&NR(1),&QWPw(1,$ap)); | ||
| 32 | &ld(($b[4])=&NR(1),&QWPw(1,$bp)); | ||
| 33 | &ld(($a[5])=&NR(1),&QWPw(1,$ap)); | ||
| 34 | &ld(($b[5])=&NR(1),&QWPw(1,$bp)); | ||
| 35 | &ld(($a[6])=&NR(1),&QWPw(1,$ap)); | ||
| 36 | &ld(($b[6])=&NR(1),&QWPw(1,$bp)); | ||
| 37 | &ld(($a[7])=&NR(1),&QWPw(1,$ap)); &FR($ap); | ||
| 38 | &ld(($b[7])=&NR(1),&QWPw(1,$bp)); &FR($bp); | ||
| 39 | |||
| 40 | ($c0,$c1,$c2)=&NR(3); | ||
| 41 | &mov("zero",$c2); | ||
| 42 | &mul($a[0],$b[0],$c0); | ||
| 43 | &muh($a[0],$b[0],$c1); | ||
| 44 | &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 45 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 46 | &mov("zero",$c2); | ||
| 47 | |||
| 48 | &mul_add_c($a[0],$b[1],$c0,$c1,$c2); | ||
| 49 | &mul_add_c($a[1],$b[0],$c0,$c1,$c2); | ||
| 50 | &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 51 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 52 | &mov("zero",$c2); | ||
| 53 | |||
| 54 | &mul_add_c($a[0],$b[2],$c0,$c1,$c2); | ||
| 55 | &mul_add_c($a[1],$b[1],$c0,$c1,$c2); | ||
| 56 | &mul_add_c($a[2],$b[0],$c0,$c1,$c2); | ||
| 57 | &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 58 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 59 | &mov("zero",$c2); | ||
| 60 | |||
| 61 | &mul_add_c($a[0],$b[3],$c0,$c1,$c2); | ||
| 62 | &mul_add_c($a[1],$b[2],$c0,$c1,$c2); | ||
| 63 | &mul_add_c($a[2],$b[1],$c0,$c1,$c2); | ||
| 64 | &mul_add_c($a[3],$b[0],$c0,$c1,$c2); | ||
| 65 | &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 66 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 67 | &mov("zero",$c2); | ||
| 68 | |||
| 69 | &mul_add_c($a[0],$b[4],$c0,$c1,$c2); | ||
| 70 | &mul_add_c($a[1],$b[3],$c0,$c1,$c2); | ||
| 71 | &mul_add_c($a[2],$b[2],$c0,$c1,$c2); | ||
| 72 | &mul_add_c($a[3],$b[1],$c0,$c1,$c2); | ||
| 73 | &mul_add_c($a[4],$b[0],$c0,$c1,$c2); | ||
| 74 | &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 75 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 76 | &mov("zero",$c2); | ||
| 77 | |||
| 78 | &mul_add_c($a[0],$b[5],$c0,$c1,$c2); | ||
| 79 | &mul_add_c($a[1],$b[4],$c0,$c1,$c2); | ||
| 80 | &mul_add_c($a[2],$b[3],$c0,$c1,$c2); | ||
| 81 | &mul_add_c($a[3],$b[2],$c0,$c1,$c2); | ||
| 82 | &mul_add_c($a[4],$b[1],$c0,$c1,$c2); | ||
| 83 | &mul_add_c($a[5],$b[0],$c0,$c1,$c2); | ||
| 84 | &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 85 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 86 | &mov("zero",$c2); | ||
| 87 | |||
| 88 | &mul_add_c($a[0],$b[6],$c0,$c1,$c2); | ||
| 89 | &mul_add_c($a[1],$b[5],$c0,$c1,$c2); | ||
| 90 | &mul_add_c($a[2],$b[4],$c0,$c1,$c2); | ||
| 91 | &mul_add_c($a[3],$b[3],$c0,$c1,$c2); | ||
| 92 | &mul_add_c($a[4],$b[2],$c0,$c1,$c2); | ||
| 93 | &mul_add_c($a[5],$b[1],$c0,$c1,$c2); | ||
| 94 | &mul_add_c($a[6],$b[0],$c0,$c1,$c2); | ||
| 95 | &st($c0,&QWPw(6,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 96 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 97 | &mov("zero",$c2); | ||
| 98 | |||
| 99 | &mul_add_c($a[0],$b[7],$c0,$c1,$c2); &FR($a[0]); | ||
| 100 | &mul_add_c($a[1],$b[6],$c0,$c1,$c2); | ||
| 101 | &mul_add_c($a[2],$b[5],$c0,$c1,$c2); | ||
| 102 | &mul_add_c($a[3],$b[4],$c0,$c1,$c2); | ||
| 103 | &mul_add_c($a[4],$b[3],$c0,$c1,$c2); | ||
| 104 | &mul_add_c($a[5],$b[2],$c0,$c1,$c2); | ||
| 105 | &mul_add_c($a[6],$b[1],$c0,$c1,$c2); | ||
| 106 | &mul_add_c($a[7],$b[0],$c0,$c1,$c2); &FR($b[0]); | ||
| 107 | &st($c0,&QWPw(7,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 108 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 109 | &mov("zero",$c2); | ||
| 110 | |||
| 111 | &mul_add_c($a[1],$b[7],$c0,$c1,$c2); &FR($a[1]); | ||
| 112 | &mul_add_c($a[2],$b[6],$c0,$c1,$c2); | ||
| 113 | &mul_add_c($a[3],$b[5],$c0,$c1,$c2); | ||
| 114 | &mul_add_c($a[4],$b[4],$c0,$c1,$c2); | ||
| 115 | &mul_add_c($a[5],$b[3],$c0,$c1,$c2); | ||
| 116 | &mul_add_c($a[6],$b[2],$c0,$c1,$c2); | ||
| 117 | &mul_add_c($a[7],$b[1],$c0,$c1,$c2); &FR($b[1]); | ||
| 118 | &st($c0,&QWPw(8,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 119 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 120 | &mov("zero",$c2); | ||
| 121 | |||
| 122 | &mul_add_c($a[2],$b[7],$c0,$c1,$c2); &FR($a[2]); | ||
| 123 | &mul_add_c($a[3],$b[6],$c0,$c1,$c2); | ||
| 124 | &mul_add_c($a[4],$b[5],$c0,$c1,$c2); | ||
| 125 | &mul_add_c($a[5],$b[4],$c0,$c1,$c2); | ||
| 126 | &mul_add_c($a[6],$b[3],$c0,$c1,$c2); | ||
| 127 | &mul_add_c($a[7],$b[2],$c0,$c1,$c2); &FR($b[2]); | ||
| 128 | &st($c0,&QWPw(9,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 129 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 130 | &mov("zero",$c2); | ||
| 131 | |||
| 132 | &mul_add_c($a[3],$b[7],$c0,$c1,$c2); &FR($a[3]); | ||
| 133 | &mul_add_c($a[4],$b[6],$c0,$c1,$c2); | ||
| 134 | &mul_add_c($a[5],$b[5],$c0,$c1,$c2); | ||
| 135 | &mul_add_c($a[6],$b[4],$c0,$c1,$c2); | ||
| 136 | &mul_add_c($a[7],$b[3],$c0,$c1,$c2); &FR($b[3]); | ||
| 137 | &st($c0,&QWPw(10,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 138 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 139 | &mov("zero",$c2); | ||
| 140 | |||
| 141 | &mul_add_c($a[4],$b[7],$c0,$c1,$c2); &FR($a[4]); | ||
| 142 | &mul_add_c($a[5],$b[6],$c0,$c1,$c2); | ||
| 143 | &mul_add_c($a[6],$b[5],$c0,$c1,$c2); | ||
| 144 | &mul_add_c($a[7],$b[4],$c0,$c1,$c2); &FR($b[4]); | ||
| 145 | &st($c0,&QWPw(11,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 146 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 147 | &mov("zero",$c2); | ||
| 148 | |||
| 149 | &mul_add_c($a[5],$b[7],$c0,$c1,$c2); &FR($a[5]); | ||
| 150 | &mul_add_c($a[6],$b[6],$c0,$c1,$c2); | ||
| 151 | &mul_add_c($a[7],$b[5],$c0,$c1,$c2); &FR($b[5]); | ||
| 152 | &st($c0,&QWPw(12,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 153 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 154 | &mov("zero",$c2); | ||
| 155 | |||
| 156 | &mul_add_c($a[6],$b[7],$c0,$c1,$c2); &FR($a[6]); | ||
| 157 | &mul_add_c($a[7],$b[6],$c0,$c1,$c2); &FR($b[6]); | ||
| 158 | &st($c0,&QWPw(13,$rp)); &FR($c0); ($c0)=&NR(1); | ||
| 159 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 160 | &mov("zero",$c2); | ||
| 161 | |||
| 162 | &mul_add_c($a[7],$b[7],$c0,$c1,$c2); &FR($a[7],$b[7]); | ||
| 163 | &st($c0,&QWPw(14,$rp)); | ||
| 164 | &st($c1,&QWPw(15,$rp)); | ||
| 165 | |||
| 166 | &FR($c0,$c1,$c2); | ||
| 167 | |||
| 168 | &ld($reg_s0,&swtmp(0)); | ||
| 169 | &ld($reg_s1,&swtmp(1)); | ||
| 170 | &stack_pop(2); | ||
| 171 | |||
| 172 | &function_end($name); | ||
| 173 | |||
| 174 | &fin_pool; | ||
| 175 | } | ||
| 176 | |||
| 177 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha/sqr.pl b/src/lib/libcrypto/bn/asm/alpha/sqr.pl deleted file mode 100644 index a55b696906..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha/sqr.pl +++ /dev/null | |||
| @@ -1,113 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_sqr_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local($cc,$a,$b,$r,$couny); | ||
| 8 | |||
| 9 | &init_pool(3); | ||
| 10 | ($cc)=GR("r0"); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $count=&wparam(2); | ||
| 15 | |||
| 16 | &function_begin($name,""); | ||
| 17 | |||
| 18 | &comment(""); | ||
| 19 | &sub($count,4,$count); | ||
| 20 | &mov("zero",$cc); | ||
| 21 | &br(&label("finish")); | ||
| 22 | &blt($count,&label("finish")); | ||
| 23 | |||
| 24 | ($a0,$r0)=&NR(2); | ||
| 25 | &ld($a0,&QWPw(0,$ap)); | ||
| 26 | &ld($r0,&QWPw(0,$rp)); | ||
| 27 | |||
| 28 | $a=<<'EOF'; | ||
| 29 | ########################################################## | ||
| 30 | &set_label("loop"); | ||
| 31 | |||
| 32 | ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap)); | ||
| 33 | ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp)); | ||
| 34 | ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap)); | ||
| 35 | ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp)); | ||
| 36 | ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap)); | ||
| 37 | ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp)); | ||
| 38 | |||
| 39 | ($o0,$t0)=&NR(2); | ||
| 40 | &add($a0,$b0,$o0); | ||
| 41 | &cmpult($o0,$b0,$t0); | ||
| 42 | &add($o0,$cc,$o0); | ||
| 43 | &cmpult($o0,$cc,$cc); | ||
| 44 | &add($cc,$t0,$cc); &FR($t0); | ||
| 45 | |||
| 46 | ($t1,$o1)=&NR(2); | ||
| 47 | |||
| 48 | &add($a1,$b1,$o1); &FR($a1); | ||
| 49 | &cmpult($o1,$b1,$t1); &FR($b1); | ||
| 50 | &add($o1,$cc,$o1); | ||
| 51 | &cmpult($o1,$cc,$cc); | ||
| 52 | &add($cc,$t1,$cc); &FR($t1); | ||
| 53 | |||
| 54 | ($t2,$o2)=&NR(2); | ||
| 55 | |||
| 56 | &add($a2,$b2,$o2); &FR($a2); | ||
| 57 | &cmpult($o2,$b2,$t2); &FR($b2); | ||
| 58 | &add($o2,$cc,$o2); | ||
| 59 | &cmpult($o2,$cc,$cc); | ||
| 60 | &add($cc,$t2,$cc); &FR($t2); | ||
| 61 | |||
| 62 | ($t3,$o3)=&NR(2); | ||
| 63 | |||
| 64 | &add($a3,$b3,$o3); &FR($a3); | ||
| 65 | &cmpult($o3,$b3,$t3); &FR($b3); | ||
| 66 | &add($o3,$cc,$o3); | ||
| 67 | &cmpult($o3,$cc,$cc); | ||
| 68 | &add($cc,$t3,$cc); &FR($t3); | ||
| 69 | |||
| 70 | &st($o0,&QWPw(0,$rp)); &FR($o0); | ||
| 71 | &st($o1,&QWPw(0,$rp)); &FR($o1); | ||
| 72 | &st($o2,&QWPw(0,$rp)); &FR($o2); | ||
| 73 | &st($o3,&QWPw(0,$rp)); &FR($o3); | ||
| 74 | |||
| 75 | &sub($count,4,$count); # count-=4 | ||
| 76 | &add($ap,4*$QWS,$ap); # count+=4 | ||
| 77 | &add($bp,4*$QWS,$bp); # count+=4 | ||
| 78 | &add($rp,4*$QWS,$rp); # count+=4 | ||
| 79 | |||
| 80 | &blt($count,&label("finish")); | ||
| 81 | &ld($a0,&QWPw(0,$ap)); | ||
| 82 | &ld($b0,&QWPw(0,$bp)); | ||
| 83 | &br(&label("loop")); | ||
| 84 | EOF | ||
| 85 | ################################################## | ||
| 86 | # Do the last 0..3 words | ||
| 87 | |||
| 88 | &set_label("last_loop"); | ||
| 89 | |||
| 90 | &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a | ||
| 91 | &mul($a0,$a0,($l0)=&NR(1)); | ||
| 92 | &add($ap,$QWS,$ap); | ||
| 93 | &add($rp,2*$QWS,$rp); | ||
| 94 | &sub($count,1,$count); | ||
| 95 | &muh($a0,$a0,($h0)=&NR(1)); &FR($a0); | ||
| 96 | &st($l0,&QWPw(-2,$rp)); &FR($l0); | ||
| 97 | &st($h0,&QWPw(-1,$rp)); &FR($h0); | ||
| 98 | |||
| 99 | &bgt($count,&label("last_loop")); | ||
| 100 | &function_end_A($name); | ||
| 101 | |||
| 102 | ###################################################### | ||
| 103 | &set_label("finish"); | ||
| 104 | &add($count,4,$count); | ||
| 105 | &bgt($count,&label("last_loop")); | ||
| 106 | |||
| 107 | &set_label("end"); | ||
| 108 | &function_end($name); | ||
| 109 | |||
| 110 | &fin_pool; | ||
| 111 | } | ||
| 112 | |||
| 113 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha/sqr_c4.pl b/src/lib/libcrypto/bn/asm/alpha/sqr_c4.pl deleted file mode 100644 index bf33f5b503..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha/sqr_c4.pl +++ /dev/null | |||
| @@ -1,109 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub sqr_add_c | ||
| 5 | { | ||
| 6 | local($a,$c0,$c1,$c2)=@_; | ||
| 7 | local($l1,$h1,$t1,$t2); | ||
| 8 | |||
| 9 | &mul($a,$a,($l1)=&NR(1)); | ||
| 10 | &muh($a,$a,($h1)=&NR(1)); | ||
| 11 | &add($c0,$l1,$c0); | ||
| 12 | &add($c1,$h1,$c1); | ||
| 13 | &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1); | ||
| 14 | &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1); | ||
| 15 | &add($c1,$t1,$c1); &FR($t1); | ||
| 16 | &add($c2,$t2,$c2); &FR($t2); | ||
| 17 | } | ||
| 18 | |||
| 19 | sub sqr_add_c2 | ||
| 20 | { | ||
| 21 | local($a,$b,$c0,$c1,$c2)=@_; | ||
| 22 | local($l1,$h1,$t1,$t2); | ||
| 23 | |||
| 24 | &mul($a,$b,($l1)=&NR(1)); | ||
| 25 | &muh($a,$b,($h1)=&NR(1)); | ||
| 26 | &cmplt($l1,"zero",($lc1)=&NR(1)); | ||
| 27 | &cmplt($h1,"zero",($hc1)=&NR(1)); | ||
| 28 | &add($l1,$l1,$l1); | ||
| 29 | &add($h1,$h1,$h1); | ||
| 30 | &add($h1,$lc1,$h1); &FR($lc1); | ||
| 31 | &add($c2,$hc1,$c2); &FR($hc1); | ||
| 32 | |||
| 33 | &add($c0,$l1,$c0); | ||
| 34 | &add($c1,$h1,$c1); | ||
| 35 | &cmpult($c0,$l1,($lc1)=&NR(1)); &FR($l1); | ||
| 36 | &cmpult($c1,$h1,($hc1)=&NR(1)); &FR($h1); | ||
| 37 | |||
| 38 | &add($c1,$lc1,$c1); &FR($lc1); | ||
| 39 | &add($c2,$hc1,$c2); &FR($hc1); | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | sub bn_sqr_comba4 | ||
| 44 | { | ||
| 45 | local($name)=@_; | ||
| 46 | local(@a,@b,$r,$c0,$c1,$c2); | ||
| 47 | |||
| 48 | $cnt=1; | ||
| 49 | &init_pool(2); | ||
| 50 | |||
| 51 | $rp=&wparam(0); | ||
| 52 | $ap=&wparam(1); | ||
| 53 | |||
| 54 | &function_begin($name,""); | ||
| 55 | |||
| 56 | &comment(""); | ||
| 57 | |||
| 58 | &ld(($a[0])=&NR(1),&QWPw(0,$ap)); | ||
| 59 | &ld(($a[1])=&NR(1),&QWPw(1,$ap)); | ||
| 60 | &ld(($a[2])=&NR(1),&QWPw(2,$ap)); | ||
| 61 | &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap); | ||
| 62 | |||
| 63 | ($c0,$c1,$c2)=&NR(3); | ||
| 64 | |||
| 65 | &mov("zero",$c2); | ||
| 66 | &mul($a[0],$a[0],$c0); | ||
| 67 | &muh($a[0],$a[0],$c1); | ||
| 68 | &st($c0,&QWPw(0,$rp)); | ||
| 69 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 70 | &mov("zero",$c2); | ||
| 71 | |||
| 72 | &sqr_add_c2($a[0],$a[1],$c0,$c1,$c2); | ||
| 73 | &st($c0,&QWPw(1,$rp)); | ||
| 74 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 75 | &mov("zero",$c2); | ||
| 76 | |||
| 77 | &sqr_add_c($a[1],$c0,$c1,$c2); | ||
| 78 | &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2); | ||
| 79 | &st($c0,&QWPw(2,$rp)); | ||
| 80 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 81 | &mov("zero",$c2); | ||
| 82 | |||
| 83 | &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2); | ||
| 84 | &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2); | ||
| 85 | &st($c0,&QWPw(3,$rp)); | ||
| 86 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 87 | &mov("zero",$c2); | ||
| 88 | |||
| 89 | &sqr_add_c($a[2],$c0,$c1,$c2); | ||
| 90 | &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2); | ||
| 91 | &st($c0,&QWPw(4,$rp)); | ||
| 92 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 93 | &mov("zero",$c2); | ||
| 94 | |||
| 95 | &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2); | ||
| 96 | &st($c0,&QWPw(5,$rp)); | ||
| 97 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 98 | &mov("zero",$c2); | ||
| 99 | |||
| 100 | &sqr_add_c($a[3],$c0,$c1,$c2); | ||
| 101 | &st($c0,&QWPw(6,$rp)); | ||
| 102 | &st($c1,&QWPw(7,$rp)); | ||
| 103 | |||
| 104 | &function_end($name); | ||
| 105 | |||
| 106 | &fin_pool; | ||
| 107 | } | ||
| 108 | |||
| 109 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha/sqr_c8.pl b/src/lib/libcrypto/bn/asm/alpha/sqr_c8.pl deleted file mode 100644 index b4afe085f1..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha/sqr_c8.pl +++ /dev/null | |||
| @@ -1,132 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_sqr_comba8 | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local(@a,@b,$r,$c0,$c1,$c2); | ||
| 8 | |||
| 9 | $cnt=1; | ||
| 10 | &init_pool(2); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | |||
| 15 | &function_begin($name,""); | ||
| 16 | |||
| 17 | &comment(""); | ||
| 18 | |||
| 19 | &ld(($a[0])=&NR(1),&QWPw(0,$ap)); | ||
| 20 | &ld(($a[1])=&NR(1),&QWPw(1,$ap)); | ||
| 21 | &ld(($a[2])=&NR(1),&QWPw(2,$ap)); | ||
| 22 | &ld(($a[3])=&NR(1),&QWPw(3,$ap)); | ||
| 23 | &ld(($a[4])=&NR(1),&QWPw(4,$ap)); | ||
| 24 | &ld(($a[5])=&NR(1),&QWPw(5,$ap)); | ||
| 25 | &ld(($a[6])=&NR(1),&QWPw(6,$ap)); | ||
| 26 | &ld(($a[7])=&NR(1),&QWPw(7,$ap)); &FR($ap); | ||
| 27 | |||
| 28 | ($c0,$c1,$c2)=&NR(3); | ||
| 29 | |||
| 30 | &mov("zero",$c2); | ||
| 31 | &mul($a[0],$a[0],$c0); | ||
| 32 | &muh($a[0],$a[0],$c1); | ||
| 33 | &st($c0,&QWPw(0,$rp)); | ||
| 34 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 35 | &mov("zero",$c2); | ||
| 36 | |||
| 37 | &sqr_add_c2($a[1],$a[0],$c0,$c1,$c2); | ||
| 38 | &st($c0,&QWPw(1,$rp)); | ||
| 39 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 40 | &mov("zero",$c2); | ||
| 41 | |||
| 42 | &sqr_add_c($a[1],$c0,$c1,$c2); | ||
| 43 | &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2); | ||
| 44 | &st($c0,&QWPw(2,$rp)); | ||
| 45 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 46 | &mov("zero",$c2); | ||
| 47 | |||
| 48 | &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2); | ||
| 49 | &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2); | ||
| 50 | &st($c0,&QWPw(3,$rp)); | ||
| 51 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 52 | &mov("zero",$c2); | ||
| 53 | |||
| 54 | &sqr_add_c($a[2],$c0,$c1,$c2); | ||
| 55 | &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2); | ||
| 56 | &sqr_add_c2($a[4],$a[0],$c0,$c1,$c2); | ||
| 57 | &st($c0,&QWPw(4,$rp)); | ||
| 58 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 59 | &mov("zero",$c2); | ||
| 60 | |||
| 61 | &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2); | ||
| 62 | &sqr_add_c2($a[4],$a[1],$c0,$c1,$c2); | ||
| 63 | &sqr_add_c2($a[5],$a[0],$c0,$c1,$c2); | ||
| 64 | &st($c0,&QWPw(5,$rp)); | ||
| 65 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 66 | &mov("zero",$c2); | ||
| 67 | |||
| 68 | &sqr_add_c($a[3],$c0,$c1,$c2); | ||
| 69 | &sqr_add_c2($a[4],$a[2],$c0,$c1,$c2); | ||
| 70 | &sqr_add_c2($a[5],$a[1],$c0,$c1,$c2); | ||
| 71 | &sqr_add_c2($a[6],$a[0],$c0,$c1,$c2); | ||
| 72 | &st($c0,&QWPw(6,$rp)); | ||
| 73 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 74 | &mov("zero",$c2); | ||
| 75 | |||
| 76 | &sqr_add_c2($a[4],$a[3],$c0,$c1,$c2); | ||
| 77 | &sqr_add_c2($a[5],$a[2],$c0,$c1,$c2); | ||
| 78 | &sqr_add_c2($a[6],$a[1],$c0,$c1,$c2); | ||
| 79 | &sqr_add_c2($a[7],$a[0],$c0,$c1,$c2); | ||
| 80 | &st($c0,&QWPw(7,$rp)); | ||
| 81 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 82 | &mov("zero",$c2); | ||
| 83 | |||
| 84 | &sqr_add_c($a[4],$c0,$c1,$c2); | ||
| 85 | &sqr_add_c2($a[5],$a[3],$c0,$c1,$c2); | ||
| 86 | &sqr_add_c2($a[6],$a[2],$c0,$c1,$c2); | ||
| 87 | &sqr_add_c2($a[7],$a[1],$c0,$c1,$c2); | ||
| 88 | &st($c0,&QWPw(8,$rp)); | ||
| 89 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 90 | &mov("zero",$c2); | ||
| 91 | |||
| 92 | &sqr_add_c2($a[5],$a[4],$c0,$c1,$c2); | ||
| 93 | &sqr_add_c2($a[6],$a[3],$c0,$c1,$c2); | ||
| 94 | &sqr_add_c2($a[7],$a[2],$c0,$c1,$c2); | ||
| 95 | &st($c0,&QWPw(9,$rp)); | ||
| 96 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 97 | &mov("zero",$c2); | ||
| 98 | |||
| 99 | &sqr_add_c($a[5],$c0,$c1,$c2); | ||
| 100 | &sqr_add_c2($a[6],$a[4],$c0,$c1,$c2); | ||
| 101 | &sqr_add_c2($a[7],$a[3],$c0,$c1,$c2); | ||
| 102 | &st($c0,&QWPw(10,$rp)); | ||
| 103 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 104 | &mov("zero",$c2); | ||
| 105 | |||
| 106 | &sqr_add_c2($a[6],$a[5],$c0,$c1,$c2); | ||
| 107 | &sqr_add_c2($a[7],$a[4],$c0,$c1,$c2); | ||
| 108 | &st($c0,&QWPw(11,$rp)); | ||
| 109 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 110 | &mov("zero",$c2); | ||
| 111 | |||
| 112 | &sqr_add_c($a[6],$c0,$c1,$c2); | ||
| 113 | &sqr_add_c2($a[7],$a[5],$c0,$c1,$c2); | ||
| 114 | &st($c0,&QWPw(12,$rp)); | ||
| 115 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 116 | &mov("zero",$c2); | ||
| 117 | |||
| 118 | &sqr_add_c2($a[7],$a[6],$c0,$c1,$c2); | ||
| 119 | &st($c0,&QWPw(13,$rp)); | ||
| 120 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 121 | &mov("zero",$c2); | ||
| 122 | |||
| 123 | &sqr_add_c($a[7],$c0,$c1,$c2); | ||
| 124 | &st($c0,&QWPw(14,$rp)); | ||
| 125 | &st($c1,&QWPw(15,$rp)); | ||
| 126 | |||
| 127 | &function_end($name); | ||
| 128 | |||
| 129 | &fin_pool; | ||
| 130 | } | ||
| 131 | |||
| 132 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha/sub.pl b/src/lib/libcrypto/bn/asm/alpha/sub.pl deleted file mode 100644 index d998da5c21..0000000000 --- a/src/lib/libcrypto/bn/asm/alpha/sub.pl +++ /dev/null | |||
| @@ -1,108 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # alpha assember | ||
| 3 | |||
| 4 | sub bn_sub_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | local($cc,$a,$b,$r); | ||
| 8 | |||
| 9 | &init_pool(4); | ||
| 10 | ($cc)=GR("r0"); | ||
| 11 | |||
| 12 | $rp=&wparam(0); | ||
| 13 | $ap=&wparam(1); | ||
| 14 | $bp=&wparam(2); | ||
| 15 | $count=&wparam(3); | ||
| 16 | |||
| 17 | &function_begin($name,""); | ||
| 18 | |||
| 19 | &comment(""); | ||
| 20 | &sub($count,4,$count); | ||
| 21 | &mov("zero",$cc); | ||
| 22 | &blt($count,&label("finish")); | ||
| 23 | |||
| 24 | ($a0,$b0)=&NR(2); | ||
| 25 | &ld($a0,&QWPw(0,$ap)); | ||
| 26 | &ld($b0,&QWPw(0,$bp)); | ||
| 27 | |||
| 28 | ########################################################## | ||
| 29 | &set_label("loop"); | ||
| 30 | |||
| 31 | ($a1,$tmp,$b1,$a2,$b2,$a3,$b3,$o0)=&NR(8); | ||
| 32 | &ld($a1,&QWPw(1,$ap)); | ||
| 33 | &cmpult($a0,$b0,$tmp); # will we borrow? | ||
| 34 | &ld($b1,&QWPw(1,$bp)); | ||
| 35 | &sub($a0,$b0,$a0); # do the subtract | ||
| 36 | &ld($a2,&QWPw(2,$ap)); | ||
| 37 | &cmpult($a0,$cc,$b0); # will we borrow? | ||
| 38 | &ld($b2,&QWPw(2,$bp)); | ||
| 39 | &sub($a0,$cc,$o0); # will we borrow? | ||
| 40 | &ld($a3,&QWPw(3,$ap)); | ||
| 41 | &add($b0,$tmp,$cc); ($t1,$o1)=&NR(2); &FR($tmp); | ||
| 42 | |||
| 43 | &cmpult($a1,$b1,$t1); # will we borrow? | ||
| 44 | &sub($a1,$b1,$a1); # do the subtract | ||
| 45 | &ld($b3,&QWPw(3,$bp)); | ||
| 46 | &cmpult($a1,$cc,$b1); # will we borrow? | ||
| 47 | &sub($a1,$cc,$o1); # will we borrow? | ||
| 48 | &add($b1,$t1,$cc); ($tmp,$o2)=&NR(2); &FR($t1,$a1,$b1); | ||
| 49 | |||
| 50 | &cmpult($a2,$b2,$tmp); # will we borrow? | ||
| 51 | &sub($a2,$b2,$a2); # do the subtract | ||
| 52 | &st($o0,&QWPw(0,$rp)); &FR($o0); # save | ||
| 53 | &cmpult($a2,$cc,$b2); # will we borrow? | ||
| 54 | &sub($a2,$cc,$o2); # will we borrow? | ||
| 55 | &add($b2,$tmp,$cc); ($t3,$o3)=&NR(2); &FR($tmp,$a2,$b2); | ||
| 56 | |||
| 57 | &cmpult($a3,$b3,$t3); # will we borrow? | ||
| 58 | &sub($a3,$b3,$a3); # do the subtract | ||
| 59 | &st($o1,&QWPw(1,$rp)); &FR($o1); | ||
| 60 | &cmpult($a3,$cc,$b3); # will we borrow? | ||
| 61 | &sub($a3,$cc,$o3); # will we borrow? | ||
| 62 | &add($b3,$t3,$cc); &FR($t3,$a3,$b3); | ||
| 63 | |||
| 64 | &st($o2,&QWPw(2,$rp)); &FR($o2); | ||
| 65 | &sub($count,4,$count); # count-=4 | ||
| 66 | &st($o3,&QWPw(3,$rp)); &FR($o3); | ||
| 67 | &add($ap,4*$QWS,$ap); # count+=4 | ||
| 68 | &add($bp,4*$QWS,$bp); # count+=4 | ||
| 69 | &add($rp,4*$QWS,$rp); # count+=4 | ||
| 70 | |||
| 71 | &blt($count,&label("finish")); | ||
| 72 | &ld($a0,&QWPw(0,$ap)); | ||
| 73 | &ld($b0,&QWPw(0,$bp)); | ||
| 74 | &br(&label("loop")); | ||
| 75 | ################################################## | ||
| 76 | # Do the last 0..3 words | ||
| 77 | |||
| 78 | &set_label("last_loop"); | ||
| 79 | |||
| 80 | &ld($a0,&QWPw(0,$ap)); # get a | ||
| 81 | &ld($b0,&QWPw(0,$bp)); # get b | ||
| 82 | &cmpult($a0,$b0,$tmp); # will we borrow? | ||
| 83 | &sub($a0,$b0,$a0); # do the subtract | ||
| 84 | &cmpult($a0,$cc,$b0); # will we borrow? | ||
| 85 | &sub($a0,$cc,$a0); # will we borrow? | ||
| 86 | &st($a0,&QWPw(0,$rp)); # save | ||
| 87 | &add($b0,$tmp,$cc); # add the borrows | ||
| 88 | |||
| 89 | &add($ap,$QWS,$ap); | ||
| 90 | &add($bp,$QWS,$bp); | ||
| 91 | &add($rp,$QWS,$rp); | ||
| 92 | &sub($count,1,$count); | ||
| 93 | &bgt($count,&label("last_loop")); | ||
| 94 | &function_end_A($name); | ||
| 95 | |||
| 96 | ###################################################### | ||
| 97 | &set_label("finish"); | ||
| 98 | &add($count,4,$count); | ||
| 99 | &bgt($count,&label("last_loop")); | ||
| 100 | |||
| 101 | &FR($a0,$b0); | ||
| 102 | &set_label("end"); | ||
| 103 | &function_end($name); | ||
| 104 | |||
| 105 | &fin_pool; | ||
| 106 | } | ||
| 107 | |||
| 108 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/bn-alpha.pl b/src/lib/libcrypto/bn/asm/bn-alpha.pl deleted file mode 100644 index 302edf2376..0000000000 --- a/src/lib/libcrypto/bn/asm/bn-alpha.pl +++ /dev/null | |||
| @@ -1,571 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # I have this in perl so I can use more usefull register names and then convert | ||
| 3 | # them into alpha registers. | ||
| 4 | # | ||
| 5 | |||
| 6 | $d=&data(); | ||
| 7 | $d =~ s/CC/0/g; | ||
| 8 | $d =~ s/R1/1/g; | ||
| 9 | $d =~ s/R2/2/g; | ||
| 10 | $d =~ s/R3/3/g; | ||
| 11 | $d =~ s/R4/4/g; | ||
| 12 | $d =~ s/L1/5/g; | ||
| 13 | $d =~ s/L2/6/g; | ||
| 14 | $d =~ s/L3/7/g; | ||
| 15 | $d =~ s/L4/8/g; | ||
| 16 | $d =~ s/O1/22/g; | ||
| 17 | $d =~ s/O2/23/g; | ||
| 18 | $d =~ s/O3/24/g; | ||
| 19 | $d =~ s/O4/25/g; | ||
| 20 | $d =~ s/A1/20/g; | ||
| 21 | $d =~ s/A2/21/g; | ||
| 22 | $d =~ s/A3/27/g; | ||
| 23 | $d =~ s/A4/28/g; | ||
| 24 | if (0){ | ||
| 25 | } | ||
| 26 | |||
| 27 | print $d; | ||
| 28 | |||
| 29 | sub data | ||
| 30 | { | ||
| 31 | local($data)=<<'EOF'; | ||
| 32 | |||
| 33 | # DEC Alpha assember | ||
| 34 | # The bn_div_words is actually gcc output but the other parts are hand done. | ||
| 35 | # Thanks to tzeruch@ceddec.com for sending me the gcc output for | ||
| 36 | # bn_div_words. | ||
| 37 | # I've gone back and re-done most of routines. | ||
| 38 | # The key thing to remeber for the 164 CPU is that while a | ||
| 39 | # multiply operation takes 8 cycles, another one can only be issued | ||
| 40 | # after 4 cycles have elapsed. I've done modification to help | ||
| 41 | # improve this. Also, normally, a ld instruction will not be available | ||
| 42 | # for about 3 cycles. | ||
| 43 | .file 1 "bn_asm.c" | ||
| 44 | .set noat | ||
| 45 | gcc2_compiled.: | ||
| 46 | __gnu_compiled_c: | ||
| 47 | .text | ||
| 48 | .align 3 | ||
| 49 | .globl bn_mul_add_words | ||
| 50 | .ent bn_mul_add_words | ||
| 51 | bn_mul_add_words: | ||
| 52 | bn_mul_add_words..ng: | ||
| 53 | .frame $30,0,$26,0 | ||
| 54 | .prologue 0 | ||
| 55 | .align 5 | ||
| 56 | subq $18,4,$18 | ||
| 57 | bis $31,$31,$CC | ||
| 58 | blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code | ||
| 59 | ldq $A1,0($17) # 1 1 | ||
| 60 | ldq $R1,0($16) # 1 1 | ||
| 61 | .align 3 | ||
| 62 | $42: | ||
| 63 | mulq $A1,$19,$L1 # 1 2 1 ###### | ||
| 64 | ldq $A2,8($17) # 2 1 | ||
| 65 | ldq $R2,8($16) # 2 1 | ||
| 66 | umulh $A1,$19,$A1 # 1 2 ###### | ||
| 67 | ldq $A3,16($17) # 3 1 | ||
| 68 | ldq $R3,16($16) # 3 1 | ||
| 69 | mulq $A2,$19,$L2 # 2 2 1 ###### | ||
| 70 | ldq $A4,24($17) # 4 1 | ||
| 71 | addq $R1,$L1,$R1 # 1 2 2 | ||
| 72 | ldq $R4,24($16) # 4 1 | ||
| 73 | umulh $A2,$19,$A2 # 2 2 ###### | ||
| 74 | cmpult $R1,$L1,$O1 # 1 2 3 1 | ||
| 75 | addq $A1,$O1,$A1 # 1 3 1 | ||
| 76 | addq $R1,$CC,$R1 # 1 2 3 1 | ||
| 77 | mulq $A3,$19,$L3 # 3 2 1 ###### | ||
| 78 | cmpult $R1,$CC,$CC # 1 2 3 2 | ||
| 79 | addq $R2,$L2,$R2 # 2 2 2 | ||
| 80 | addq $A1,$CC,$CC # 1 3 2 | ||
| 81 | cmpult $R2,$L2,$O2 # 2 2 3 1 | ||
| 82 | addq $A2,$O2,$A2 # 2 3 1 | ||
| 83 | umulh $A3,$19,$A3 # 3 2 ###### | ||
| 84 | addq $R2,$CC,$R2 # 2 2 3 1 | ||
| 85 | cmpult $R2,$CC,$CC # 2 2 3 2 | ||
| 86 | subq $18,4,$18 | ||
| 87 | mulq $A4,$19,$L4 # 4 2 1 ###### | ||
| 88 | addq $A2,$CC,$CC # 2 3 2 | ||
| 89 | addq $R3,$L3,$R3 # 3 2 2 | ||
| 90 | addq $16,32,$16 | ||
| 91 | cmpult $R3,$L3,$O3 # 3 2 3 1 | ||
| 92 | stq $R1,-32($16) # 1 2 4 | ||
| 93 | umulh $A4,$19,$A4 # 4 2 ###### | ||
| 94 | addq $A3,$O3,$A3 # 3 3 1 | ||
| 95 | addq $R3,$CC,$R3 # 3 2 3 1 | ||
| 96 | stq $R2,-24($16) # 2 2 4 | ||
| 97 | cmpult $R3,$CC,$CC # 3 2 3 2 | ||
| 98 | stq $R3,-16($16) # 3 2 4 | ||
| 99 | addq $R4,$L4,$R4 # 4 2 2 | ||
| 100 | addq $A3,$CC,$CC # 3 3 2 | ||
| 101 | cmpult $R4,$L4,$O4 # 4 2 3 1 | ||
| 102 | addq $17,32,$17 | ||
| 103 | addq $A4,$O4,$A4 # 4 3 1 | ||
| 104 | addq $R4,$CC,$R4 # 4 2 3 1 | ||
| 105 | cmpult $R4,$CC,$CC # 4 2 3 2 | ||
| 106 | stq $R4,-8($16) # 4 2 4 | ||
| 107 | addq $A4,$CC,$CC # 4 3 2 | ||
| 108 | blt $18,$43 | ||
| 109 | |||
| 110 | ldq $A1,0($17) # 1 1 | ||
| 111 | ldq $R1,0($16) # 1 1 | ||
| 112 | |||
| 113 | br $42 | ||
| 114 | |||
| 115 | .align 4 | ||
| 116 | $45: | ||
| 117 | ldq $A1,0($17) # 4 1 | ||
| 118 | ldq $R1,0($16) # 4 1 | ||
| 119 | mulq $A1,$19,$L1 # 4 2 1 | ||
| 120 | subq $18,1,$18 | ||
| 121 | addq $16,8,$16 | ||
| 122 | addq $17,8,$17 | ||
| 123 | umulh $A1,$19,$A1 # 4 2 | ||
| 124 | addq $R1,$L1,$R1 # 4 2 2 | ||
| 125 | cmpult $R1,$L1,$O1 # 4 2 3 1 | ||
| 126 | addq $A1,$O1,$A1 # 4 3 1 | ||
| 127 | addq $R1,$CC,$R1 # 4 2 3 1 | ||
| 128 | cmpult $R1,$CC,$CC # 4 2 3 2 | ||
| 129 | addq $A1,$CC,$CC # 4 3 2 | ||
| 130 | stq $R1,-8($16) # 4 2 4 | ||
| 131 | bgt $18,$45 | ||
| 132 | ret $31,($26),1 # else exit | ||
| 133 | |||
| 134 | .align 4 | ||
| 135 | $43: | ||
| 136 | addq $18,4,$18 | ||
| 137 | bgt $18,$45 # goto tail code | ||
| 138 | ret $31,($26),1 # else exit | ||
| 139 | |||
| 140 | .end bn_mul_add_words | ||
| 141 | .align 3 | ||
| 142 | .globl bn_mul_words | ||
| 143 | .ent bn_mul_words | ||
| 144 | bn_mul_words: | ||
| 145 | bn_mul_words..ng: | ||
| 146 | .frame $30,0,$26,0 | ||
| 147 | .prologue 0 | ||
| 148 | .align 5 | ||
| 149 | subq $18,4,$18 | ||
| 150 | bis $31,$31,$CC | ||
| 151 | blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code | ||
| 152 | ldq $A1,0($17) # 1 1 | ||
| 153 | .align 3 | ||
| 154 | $142: | ||
| 155 | |||
| 156 | mulq $A1,$19,$L1 # 1 2 1 ##### | ||
| 157 | ldq $A2,8($17) # 2 1 | ||
| 158 | ldq $A3,16($17) # 3 1 | ||
| 159 | umulh $A1,$19,$A1 # 1 2 ##### | ||
| 160 | ldq $A4,24($17) # 4 1 | ||
| 161 | mulq $A2,$19,$L2 # 2 2 1 ##### | ||
| 162 | addq $L1,$CC,$L1 # 1 2 3 1 | ||
| 163 | subq $18,4,$18 | ||
| 164 | cmpult $L1,$CC,$CC # 1 2 3 2 | ||
| 165 | umulh $A2,$19,$A2 # 2 2 ##### | ||
| 166 | addq $A1,$CC,$CC # 1 3 2 | ||
| 167 | addq $17,32,$17 | ||
| 168 | addq $L2,$CC,$L2 # 2 2 3 1 | ||
| 169 | mulq $A3,$19,$L3 # 3 2 1 ##### | ||
| 170 | cmpult $L2,$CC,$CC # 2 2 3 2 | ||
| 171 | addq $A2,$CC,$CC # 2 3 2 | ||
| 172 | addq $16,32,$16 | ||
| 173 | umulh $A3,$19,$A3 # 3 2 ##### | ||
| 174 | stq $L1,-32($16) # 1 2 4 | ||
| 175 | mulq $A4,$19,$L4 # 4 2 1 ##### | ||
| 176 | addq $L3,$CC,$L3 # 3 2 3 1 | ||
| 177 | stq $L2,-24($16) # 2 2 4 | ||
| 178 | cmpult $L3,$CC,$CC # 3 2 3 2 | ||
| 179 | umulh $A4,$19,$A4 # 4 2 ##### | ||
| 180 | addq $A3,$CC,$CC # 3 3 2 | ||
| 181 | stq $L3,-16($16) # 3 2 4 | ||
| 182 | addq $L4,$CC,$L4 # 4 2 3 1 | ||
| 183 | cmpult $L4,$CC,$CC # 4 2 3 2 | ||
| 184 | |||
| 185 | addq $A4,$CC,$CC # 4 3 2 | ||
| 186 | |||
| 187 | stq $L4,-8($16) # 4 2 4 | ||
| 188 | |||
| 189 | blt $18,$143 | ||
| 190 | |||
| 191 | ldq $A1,0($17) # 1 1 | ||
| 192 | |||
| 193 | br $142 | ||
| 194 | |||
| 195 | .align 4 | ||
| 196 | $145: | ||
| 197 | ldq $A1,0($17) # 4 1 | ||
| 198 | mulq $A1,$19,$L1 # 4 2 1 | ||
| 199 | subq $18,1,$18 | ||
| 200 | umulh $A1,$19,$A1 # 4 2 | ||
| 201 | addq $L1,$CC,$L1 # 4 2 3 1 | ||
| 202 | addq $16,8,$16 | ||
| 203 | cmpult $L1,$CC,$CC # 4 2 3 2 | ||
| 204 | addq $17,8,$17 | ||
| 205 | addq $A1,$CC,$CC # 4 3 2 | ||
| 206 | stq $L1,-8($16) # 4 2 4 | ||
| 207 | |||
| 208 | bgt $18,$145 | ||
| 209 | ret $31,($26),1 # else exit | ||
| 210 | |||
| 211 | .align 4 | ||
| 212 | $143: | ||
| 213 | addq $18,4,$18 | ||
| 214 | bgt $18,$145 # goto tail code | ||
| 215 | ret $31,($26),1 # else exit | ||
| 216 | |||
| 217 | .end bn_mul_words | ||
| 218 | .align 3 | ||
| 219 | .globl bn_sqr_words | ||
| 220 | .ent bn_sqr_words | ||
| 221 | bn_sqr_words: | ||
| 222 | bn_sqr_words..ng: | ||
| 223 | .frame $30,0,$26,0 | ||
| 224 | .prologue 0 | ||
| 225 | |||
| 226 | subq $18,4,$18 | ||
| 227 | blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code | ||
| 228 | ldq $A1,0($17) # 1 1 | ||
| 229 | .align 3 | ||
| 230 | $542: | ||
| 231 | mulq $A1,$A1,$L1 ###### | ||
| 232 | ldq $A2,8($17) # 1 1 | ||
| 233 | subq $18,4 | ||
| 234 | umulh $A1,$A1,$R1 ###### | ||
| 235 | ldq $A3,16($17) # 1 1 | ||
| 236 | mulq $A2,$A2,$L2 ###### | ||
| 237 | ldq $A4,24($17) # 1 1 | ||
| 238 | stq $L1,0($16) # r[0] | ||
| 239 | umulh $A2,$A2,$R2 ###### | ||
| 240 | stq $R1,8($16) # r[1] | ||
| 241 | mulq $A3,$A3,$L3 ###### | ||
| 242 | stq $L2,16($16) # r[0] | ||
| 243 | umulh $A3,$A3,$R3 ###### | ||
| 244 | stq $R2,24($16) # r[1] | ||
| 245 | mulq $A4,$A4,$L4 ###### | ||
| 246 | stq $L3,32($16) # r[0] | ||
| 247 | umulh $A4,$A4,$R4 ###### | ||
| 248 | stq $R3,40($16) # r[1] | ||
| 249 | |||
| 250 | addq $16,64,$16 | ||
| 251 | addq $17,32,$17 | ||
| 252 | stq $L4,-16($16) # r[0] | ||
| 253 | stq $R4,-8($16) # r[1] | ||
| 254 | |||
| 255 | blt $18,$543 | ||
| 256 | ldq $A1,0($17) # 1 1 | ||
| 257 | br $542 | ||
| 258 | |||
| 259 | $442: | ||
| 260 | ldq $A1,0($17) # a[0] | ||
| 261 | mulq $A1,$A1,$L1 # a[0]*w low part r2 | ||
| 262 | addq $16,16,$16 | ||
| 263 | addq $17,8,$17 | ||
| 264 | subq $18,1,$18 | ||
| 265 | umulh $A1,$A1,$R1 # a[0]*w high part r3 | ||
| 266 | stq $L1,-16($16) # r[0] | ||
| 267 | stq $R1,-8($16) # r[1] | ||
| 268 | |||
| 269 | bgt $18,$442 | ||
| 270 | ret $31,($26),1 # else exit | ||
| 271 | |||
| 272 | .align 4 | ||
| 273 | $543: | ||
| 274 | addq $18,4,$18 | ||
| 275 | bgt $18,$442 # goto tail code | ||
| 276 | ret $31,($26),1 # else exit | ||
| 277 | .end bn_sqr_words | ||
| 278 | |||
| 279 | .align 3 | ||
| 280 | .globl bn_add_words | ||
| 281 | .ent bn_add_words | ||
| 282 | bn_add_words: | ||
| 283 | bn_add_words..ng: | ||
| 284 | .frame $30,0,$26,0 | ||
| 285 | .prologue 0 | ||
| 286 | |||
| 287 | subq $19,4,$19 | ||
| 288 | bis $31,$31,$CC # carry = 0 | ||
| 289 | blt $19,$900 | ||
| 290 | ldq $L1,0($17) # a[0] | ||
| 291 | ldq $R1,0($18) # b[1] | ||
| 292 | .align 3 | ||
| 293 | $901: | ||
| 294 | addq $R1,$L1,$R1 # r=a+b; | ||
| 295 | ldq $L2,8($17) # a[1] | ||
| 296 | cmpult $R1,$L1,$O1 # did we overflow? | ||
| 297 | ldq $R2,8($18) # b[1] | ||
| 298 | addq $R1,$CC,$R1 # c+= overflow | ||
| 299 | ldq $L3,16($17) # a[2] | ||
| 300 | cmpult $R1,$CC,$CC # overflow? | ||
| 301 | ldq $R3,16($18) # b[2] | ||
| 302 | addq $CC,$O1,$CC | ||
| 303 | ldq $L4,24($17) # a[3] | ||
| 304 | addq $R2,$L2,$R2 # r=a+b; | ||
| 305 | ldq $R4,24($18) # b[3] | ||
| 306 | cmpult $R2,$L2,$O2 # did we overflow? | ||
| 307 | addq $R3,$L3,$R3 # r=a+b; | ||
| 308 | addq $R2,$CC,$R2 # c+= overflow | ||
| 309 | cmpult $R3,$L3,$O3 # did we overflow? | ||
| 310 | cmpult $R2,$CC,$CC # overflow? | ||
| 311 | addq $R4,$L4,$R4 # r=a+b; | ||
| 312 | addq $CC,$O2,$CC | ||
| 313 | cmpult $R4,$L4,$O4 # did we overflow? | ||
| 314 | addq $R3,$CC,$R3 # c+= overflow | ||
| 315 | stq $R1,0($16) # r[0]=c | ||
| 316 | cmpult $R3,$CC,$CC # overflow? | ||
| 317 | stq $R2,8($16) # r[1]=c | ||
| 318 | addq $CC,$O3,$CC | ||
| 319 | stq $R3,16($16) # r[2]=c | ||
| 320 | addq $R4,$CC,$R4 # c+= overflow | ||
| 321 | subq $19,4,$19 # loop-- | ||
| 322 | cmpult $R4,$CC,$CC # overflow? | ||
| 323 | addq $17,32,$17 # a++ | ||
| 324 | addq $CC,$O4,$CC | ||
| 325 | stq $R4,24($16) # r[3]=c | ||
| 326 | addq $18,32,$18 # b++ | ||
| 327 | addq $16,32,$16 # r++ | ||
| 328 | |||
| 329 | blt $19,$900 | ||
| 330 | ldq $L1,0($17) # a[0] | ||
| 331 | ldq $R1,0($18) # b[1] | ||
| 332 | br $901 | ||
| 333 | .align 4 | ||
| 334 | $945: | ||
| 335 | ldq $L1,0($17) # a[0] | ||
| 336 | ldq $R1,0($18) # b[1] | ||
| 337 | addq $R1,$L1,$R1 # r=a+b; | ||
| 338 | subq $19,1,$19 # loop-- | ||
| 339 | addq $R1,$CC,$R1 # c+= overflow | ||
| 340 | addq $17,8,$17 # a++ | ||
| 341 | cmpult $R1,$L1,$O1 # did we overflow? | ||
| 342 | cmpult $R1,$CC,$CC # overflow? | ||
| 343 | addq $18,8,$18 # b++ | ||
| 344 | stq $R1,0($16) # r[0]=c | ||
| 345 | addq $CC,$O1,$CC | ||
| 346 | addq $16,8,$16 # r++ | ||
| 347 | |||
| 348 | bgt $19,$945 | ||
| 349 | ret $31,($26),1 # else exit | ||
| 350 | |||
| 351 | $900: | ||
| 352 | addq $19,4,$19 | ||
| 353 | bgt $19,$945 # goto tail code | ||
| 354 | ret $31,($26),1 # else exit | ||
| 355 | .end bn_add_words | ||
| 356 | |||
| 357 | .align 3 | ||
| 358 | .globl bn_sub_words | ||
| 359 | .ent bn_sub_words | ||
| 360 | bn_sub_words: | ||
| 361 | bn_sub_words..ng: | ||
| 362 | .frame $30,0,$26,0 | ||
| 363 | .prologue 0 | ||
| 364 | |||
| 365 | subq $19,4,$19 | ||
| 366 | bis $31,$31,$CC # carry = 0 | ||
| 367 | br $800 | ||
| 368 | blt $19,$800 | ||
| 369 | ldq $L1,0($17) # a[0] | ||
| 370 | ldq $R1,0($18) # b[1] | ||
| 371 | .align 3 | ||
| 372 | $801: | ||
| 373 | addq $R1,$L1,$R1 # r=a+b; | ||
| 374 | ldq $L2,8($17) # a[1] | ||
| 375 | cmpult $R1,$L1,$O1 # did we overflow? | ||
| 376 | ldq $R2,8($18) # b[1] | ||
| 377 | addq $R1,$CC,$R1 # c+= overflow | ||
| 378 | ldq $L3,16($17) # a[2] | ||
| 379 | cmpult $R1,$CC,$CC # overflow? | ||
| 380 | ldq $R3,16($18) # b[2] | ||
| 381 | addq $CC,$O1,$CC | ||
| 382 | ldq $L4,24($17) # a[3] | ||
| 383 | addq $R2,$L2,$R2 # r=a+b; | ||
| 384 | ldq $R4,24($18) # b[3] | ||
| 385 | cmpult $R2,$L2,$O2 # did we overflow? | ||
| 386 | addq $R3,$L3,$R3 # r=a+b; | ||
| 387 | addq $R2,$CC,$R2 # c+= overflow | ||
| 388 | cmpult $R3,$L3,$O3 # did we overflow? | ||
| 389 | cmpult $R2,$CC,$CC # overflow? | ||
| 390 | addq $R4,$L4,$R4 # r=a+b; | ||
| 391 | addq $CC,$O2,$CC | ||
| 392 | cmpult $R4,$L4,$O4 # did we overflow? | ||
| 393 | addq $R3,$CC,$R3 # c+= overflow | ||
| 394 | stq $R1,0($16) # r[0]=c | ||
| 395 | cmpult $R3,$CC,$CC # overflow? | ||
| 396 | stq $R2,8($16) # r[1]=c | ||
| 397 | addq $CC,$O3,$CC | ||
| 398 | stq $R3,16($16) # r[2]=c | ||
| 399 | addq $R4,$CC,$R4 # c+= overflow | ||
| 400 | subq $19,4,$19 # loop-- | ||
| 401 | cmpult $R4,$CC,$CC # overflow? | ||
| 402 | addq $17,32,$17 # a++ | ||
| 403 | addq $CC,$O4,$CC | ||
| 404 | stq $R4,24($16) # r[3]=c | ||
| 405 | addq $18,32,$18 # b++ | ||
| 406 | addq $16,32,$16 # r++ | ||
| 407 | |||
| 408 | blt $19,$800 | ||
| 409 | ldq $L1,0($17) # a[0] | ||
| 410 | ldq $R1,0($18) # b[1] | ||
| 411 | br $801 | ||
| 412 | .align 4 | ||
| 413 | $845: | ||
| 414 | ldq $L1,0($17) # a[0] | ||
| 415 | ldq $R1,0($18) # b[1] | ||
| 416 | cmpult $L1,$R1,$O1 # will we borrow? | ||
| 417 | subq $L1,$R1,$R1 # r=a-b; | ||
| 418 | subq $19,1,$19 # loop-- | ||
| 419 | cmpult $R1,$CC,$O2 # will we borrow? | ||
| 420 | subq $R1,$CC,$R1 # c+= overflow | ||
| 421 | addq $17,8,$17 # a++ | ||
| 422 | addq $18,8,$18 # b++ | ||
| 423 | stq $R1,0($16) # r[0]=c | ||
| 424 | addq $O2,$O1,$CC | ||
| 425 | addq $16,8,$16 # r++ | ||
| 426 | |||
| 427 | bgt $19,$845 | ||
| 428 | ret $31,($26),1 # else exit | ||
| 429 | |||
| 430 | $800: | ||
| 431 | addq $19,4,$19 | ||
| 432 | bgt $19,$845 # goto tail code | ||
| 433 | ret $31,($26),1 # else exit | ||
| 434 | .end bn_sub_words | ||
| 435 | |||
| 436 | # | ||
| 437 | # What follows was taken directly from the C compiler with a few | ||
| 438 | # hacks to redo the lables. | ||
| 439 | # | ||
| 440 | .text | ||
| 441 | .align 3 | ||
| 442 | .globl bn_div_words | ||
| 443 | .ent bn_div_words | ||
| 444 | bn_div_words: | ||
| 445 | ldgp $29,0($27) | ||
| 446 | bn_div_words..ng: | ||
| 447 | lda $30,-48($30) | ||
| 448 | .frame $30,48,$26,0 | ||
| 449 | stq $26,0($30) | ||
| 450 | stq $9,8($30) | ||
| 451 | stq $10,16($30) | ||
| 452 | stq $11,24($30) | ||
| 453 | stq $12,32($30) | ||
| 454 | stq $13,40($30) | ||
| 455 | .mask 0x4003e00,-48 | ||
| 456 | .prologue 1 | ||
| 457 | bis $16,$16,$9 | ||
| 458 | bis $17,$17,$10 | ||
| 459 | bis $18,$18,$11 | ||
| 460 | bis $31,$31,$13 | ||
| 461 | bis $31,2,$12 | ||
| 462 | bne $11,$119 | ||
| 463 | lda $0,-1 | ||
| 464 | br $31,$136 | ||
| 465 | .align 4 | ||
| 466 | $119: | ||
| 467 | bis $11,$11,$16 | ||
| 468 | jsr $26,BN_num_bits_word | ||
| 469 | ldgp $29,0($26) | ||
| 470 | subq $0,64,$1 | ||
| 471 | beq $1,$120 | ||
| 472 | bis $31,1,$1 | ||
| 473 | sll $1,$0,$1 | ||
| 474 | cmpule $9,$1,$1 | ||
| 475 | bne $1,$120 | ||
| 476 | # lda $16,_IO_stderr_ | ||
| 477 | # lda $17,$C32 | ||
| 478 | # bis $0,$0,$18 | ||
| 479 | # jsr $26,fprintf | ||
| 480 | # ldgp $29,0($26) | ||
| 481 | jsr $26,abort | ||
| 482 | ldgp $29,0($26) | ||
| 483 | .align 4 | ||
| 484 | $120: | ||
| 485 | bis $31,64,$3 | ||
| 486 | cmpult $9,$11,$2 | ||
| 487 | subq $3,$0,$1 | ||
| 488 | addl $1,$31,$0 | ||
| 489 | subq $9,$11,$1 | ||
| 490 | cmoveq $2,$1,$9 | ||
| 491 | beq $0,$122 | ||
| 492 | zapnot $0,15,$2 | ||
| 493 | subq $3,$0,$1 | ||
| 494 | sll $11,$2,$11 | ||
| 495 | sll $9,$2,$3 | ||
| 496 | srl $10,$1,$1 | ||
| 497 | sll $10,$2,$10 | ||
| 498 | bis $3,$1,$9 | ||
| 499 | $122: | ||
| 500 | srl $11,32,$5 | ||
| 501 | zapnot $11,15,$6 | ||
| 502 | lda $7,-1 | ||
| 503 | .align 5 | ||
| 504 | $123: | ||
| 505 | srl $9,32,$1 | ||
| 506 | subq $1,$5,$1 | ||
| 507 | bne $1,$126 | ||
| 508 | zapnot $7,15,$27 | ||
| 509 | br $31,$127 | ||
| 510 | .align 4 | ||
| 511 | $126: | ||
| 512 | bis $9,$9,$24 | ||
| 513 | bis $5,$5,$25 | ||
| 514 | divqu $24,$25,$27 | ||
| 515 | $127: | ||
| 516 | srl $10,32,$4 | ||
| 517 | .align 5 | ||
| 518 | $128: | ||
| 519 | mulq $27,$5,$1 | ||
| 520 | subq $9,$1,$3 | ||
| 521 | zapnot $3,240,$1 | ||
| 522 | bne $1,$129 | ||
| 523 | mulq $6,$27,$2 | ||
| 524 | sll $3,32,$1 | ||
| 525 | addq $1,$4,$1 | ||
| 526 | cmpule $2,$1,$2 | ||
| 527 | bne $2,$129 | ||
| 528 | subq $27,1,$27 | ||
| 529 | br $31,$128 | ||
| 530 | .align 4 | ||
| 531 | $129: | ||
| 532 | mulq $27,$6,$1 | ||
| 533 | mulq $27,$5,$4 | ||
| 534 | srl $1,32,$3 | ||
| 535 | sll $1,32,$1 | ||
| 536 | addq $4,$3,$4 | ||
| 537 | cmpult $10,$1,$2 | ||
| 538 | subq $10,$1,$10 | ||
| 539 | addq $2,$4,$2 | ||
| 540 | cmpult $9,$2,$1 | ||
| 541 | bis $2,$2,$4 | ||
| 542 | beq $1,$134 | ||
| 543 | addq $9,$11,$9 | ||
| 544 | subq $27,1,$27 | ||
| 545 | $134: | ||
| 546 | subl $12,1,$12 | ||
| 547 | subq $9,$4,$9 | ||
| 548 | beq $12,$124 | ||
| 549 | sll $27,32,$13 | ||
| 550 | sll $9,32,$2 | ||
| 551 | srl $10,32,$1 | ||
| 552 | sll $10,32,$10 | ||
| 553 | bis $2,$1,$9 | ||
| 554 | br $31,$123 | ||
| 555 | .align 4 | ||
| 556 | $124: | ||
| 557 | bis $13,$27,$0 | ||
| 558 | $136: | ||
| 559 | ldq $26,0($30) | ||
| 560 | ldq $9,8($30) | ||
| 561 | ldq $10,16($30) | ||
| 562 | ldq $11,24($30) | ||
| 563 | ldq $12,32($30) | ||
| 564 | ldq $13,40($30) | ||
| 565 | addq $30,48,$30 | ||
| 566 | ret $31,($26),1 | ||
| 567 | .end bn_div_words | ||
| 568 | EOF | ||
| 569 | return($data); | ||
| 570 | } | ||
| 571 | |||
diff --git a/src/lib/libcrypto/bn/asm/ca.pl b/src/lib/libcrypto/bn/asm/ca.pl deleted file mode 100644 index c1ce67a6b4..0000000000 --- a/src/lib/libcrypto/bn/asm/ca.pl +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # I have this in perl so I can use more usefull register names and then convert | ||
| 3 | # them into alpha registers. | ||
| 4 | # | ||
| 5 | |||
| 6 | push(@INC,"perlasm","../../perlasm"); | ||
| 7 | require "alpha.pl"; | ||
| 8 | require "alpha/mul_add.pl"; | ||
| 9 | require "alpha/mul.pl"; | ||
| 10 | require "alpha/sqr.pl"; | ||
| 11 | require "alpha/add.pl"; | ||
| 12 | require "alpha/sub.pl"; | ||
| 13 | require "alpha/mul_c8.pl"; | ||
| 14 | require "alpha/mul_c4.pl"; | ||
| 15 | require "alpha/sqr_c4.pl"; | ||
| 16 | require "alpha/sqr_c8.pl"; | ||
| 17 | require "alpha/div.pl"; | ||
| 18 | |||
| 19 | &asm_init($ARGV[0],$0); | ||
| 20 | |||
| 21 | &bn_mul_words("bn_mul_words"); | ||
| 22 | &bn_sqr_words("bn_sqr_words"); | ||
| 23 | &bn_mul_add_words("bn_mul_add_words"); | ||
| 24 | &bn_add_words("bn_add_words"); | ||
| 25 | &bn_sub_words("bn_sub_words"); | ||
| 26 | &bn_div_words("bn_div_words"); | ||
| 27 | &bn_mul_comba8("bn_mul_comba8"); | ||
| 28 | &bn_mul_comba4("bn_mul_comba4"); | ||
| 29 | &bn_sqr_comba4("bn_sqr_comba4"); | ||
| 30 | &bn_sqr_comba8("bn_sqr_comba8"); | ||
| 31 | |||
| 32 | &asm_finish(); | ||
| 33 | |||
diff --git a/src/lib/libcrypto/bn/asm/co-alpha.pl b/src/lib/libcrypto/bn/asm/co-alpha.pl deleted file mode 100644 index 67dad3e3d5..0000000000 --- a/src/lib/libcrypto/bn/asm/co-alpha.pl +++ /dev/null | |||
| @@ -1,116 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # I have this in perl so I can use more usefull register names and then convert | ||
| 3 | # them into alpha registers. | ||
| 4 | # | ||
| 5 | |||
| 6 | push(@INC,"perlasm","../../perlasm"); | ||
| 7 | require "alpha.pl"; | ||
| 8 | |||
| 9 | &asm_init($ARGV[0],$0); | ||
| 10 | |||
| 11 | print &bn_sub_words("bn_sub_words"); | ||
| 12 | |||
| 13 | &asm_finish(); | ||
| 14 | |||
| 15 | sub bn_sub_words | ||
| 16 | { | ||
| 17 | local($name)=@_; | ||
| 18 | local($cc,$a,$b,$r); | ||
| 19 | |||
| 20 | $cc="r0"; | ||
| 21 | $a0="r1"; $b0="r5"; $r0="r9"; $tmp="r13"; | ||
| 22 | $a1="r2"; $b1="r6"; $r1="r10"; $t1="r14"; | ||
| 23 | $a2="r3"; $b2="r7"; $r2="r11"; | ||
| 24 | $a3="r4"; $b3="r8"; $r3="r12"; $t3="r15"; | ||
| 25 | |||
| 26 | $rp=&wparam(0); | ||
| 27 | $ap=&wparam(1); | ||
| 28 | $bp=&wparam(2); | ||
| 29 | $count=&wparam(3); | ||
| 30 | |||
| 31 | &function_begin($name,""); | ||
| 32 | |||
| 33 | &comment(""); | ||
| 34 | &sub($count,4,$count); | ||
| 35 | &mov("zero",$cc); | ||
| 36 | &blt($count,&label("finish")); | ||
| 37 | |||
| 38 | &ld($a0,&QWPw(0,$ap)); | ||
| 39 | &ld($b0,&QWPw(0,$bp)); | ||
| 40 | |||
| 41 | ########################################################## | ||
| 42 | &set_label("loop"); | ||
| 43 | |||
| 44 | &ld($a1,&QWPw(1,$ap)); | ||
| 45 | &cmpult($a0,$b0,$tmp); # will we borrow? | ||
| 46 | &ld($b1,&QWPw(1,$bp)); | ||
| 47 | &sub($a0,$b0,$a0); # do the subtract | ||
| 48 | &ld($a2,&QWPw(2,$ap)); | ||
| 49 | &cmpult($a0,$cc,$b0); # will we borrow? | ||
| 50 | &ld($b2,&QWPw(2,$bp)); | ||
| 51 | &sub($a0,$cc,$a0); # will we borrow? | ||
| 52 | &ld($a3,&QWPw(3,$ap)); | ||
| 53 | &add($b0,$tmp,$cc); # add the borrows | ||
| 54 | |||
| 55 | &cmpult($a1,$b1,$t1); # will we borrow? | ||
| 56 | &sub($a1,$b1,$a1); # do the subtract | ||
| 57 | &ld($b3,&QWPw(3,$bp)); | ||
| 58 | &cmpult($a1,$cc,$b1); # will we borrow? | ||
| 59 | &sub($a1,$cc,$a1); # will we borrow? | ||
| 60 | &add($b1,$t1,$cc); # add the borrows | ||
| 61 | |||
| 62 | &cmpult($a2,$b2,$tmp); # will we borrow? | ||
| 63 | &sub($a2,$b2,$a2); # do the subtract | ||
| 64 | &st($a0,&QWPw(0,$rp)); # save | ||
| 65 | &cmpult($a2,$cc,$b2); # will we borrow? | ||
| 66 | &sub($a2,$cc,$a2); # will we borrow? | ||
| 67 | &add($b2,$tmp,$cc); # add the borrows | ||
| 68 | |||
| 69 | &cmpult($a3,$b3,$t3); # will we borrow? | ||
| 70 | &sub($a3,$b3,$a3); # do the subtract | ||
| 71 | &st($a1,&QWPw(1,$rp)); # save | ||
| 72 | &cmpult($a3,$cc,$b3); # will we borrow? | ||
| 73 | &sub($a3,$cc,$a3); # will we borrow? | ||
| 74 | &add($b3,$t3,$cc); # add the borrows | ||
| 75 | |||
| 76 | &st($a2,&QWPw(2,$rp)); # save | ||
| 77 | &sub($count,4,$count); # count-=4 | ||
| 78 | &st($a3,&QWPw(3,$rp)); # save | ||
| 79 | &add($ap,4*$QWS,$ap); # count+=4 | ||
| 80 | &add($bp,4*$QWS,$bp); # count+=4 | ||
| 81 | &add($rp,4*$QWS,$rp); # count+=4 | ||
| 82 | |||
| 83 | &blt($count,&label("finish")); | ||
| 84 | &ld($a0,&QWPw(0,$ap)); | ||
| 85 | &ld($b0,&QWPw(0,$bp)); | ||
| 86 | &br(&label("loop")); | ||
| 87 | ################################################## | ||
| 88 | # Do the last 0..3 words | ||
| 89 | |||
| 90 | &set_label("last_loop"); | ||
| 91 | |||
| 92 | &ld($a0,&QWPw(0,$ap)); # get a | ||
| 93 | &ld($b0,&QWPw(0,$bp)); # get b | ||
| 94 | &cmpult($a0,$b0,$tmp); # will we borrow? | ||
| 95 | &sub($a0,$b0,$a0); # do the subtract | ||
| 96 | &cmpult($a0,$cc,$b0); # will we borrow? | ||
| 97 | &sub($a0,$cc,$a0); # will we borrow? | ||
| 98 | &st($a0,&QWPw(0,$rp)); # save | ||
| 99 | &add($b0,$tmp,$cc); # add the borrows | ||
| 100 | |||
| 101 | &add($ap,$QWS,$ap); | ||
| 102 | &add($bp,$QWS,$bp); | ||
| 103 | &add($rp,$QWS,$rp); | ||
| 104 | &sub($count,1,$count); | ||
| 105 | &bgt($count,&label("last_loop")); | ||
| 106 | &function_end_A($name); | ||
| 107 | |||
| 108 | ###################################################### | ||
| 109 | &set_label("finish"); | ||
| 110 | &add($count,4,$count); | ||
| 111 | &bgt($count,&label("last_loop")); | ||
| 112 | |||
| 113 | &set_label("end"); | ||
| 114 | &function_end($name); | ||
| 115 | } | ||
| 116 | |||
diff --git a/src/lib/libcrypto/bn/asm/mips1.s b/src/lib/libcrypto/bn/asm/mips1.s deleted file mode 100644 index 44fa1254c7..0000000000 --- a/src/lib/libcrypto/bn/asm/mips1.s +++ /dev/null | |||
| @@ -1,539 +0,0 @@ | |||
| 1 | /* This assember is for R2000/R3000 machines, or higher ones that do | ||
| 2 | * no want to do any 64 bit arithmatic. | ||
| 3 | * Make sure that the SSLeay bignum library is compiled with | ||
| 4 | * THIRTY_TWO_BIT set. | ||
| 5 | * This must either be compiled with the system CC, or, if you use GNU gas, | ||
| 6 | * cc -E mips1.s|gas -o mips1.o | ||
| 7 | */ | ||
| 8 | .set reorder | ||
| 9 | .set noat | ||
| 10 | |||
| 11 | #define R1 $1 | ||
| 12 | #define CC $2 | ||
| 13 | #define R2 $3 | ||
| 14 | #define R3 $8 | ||
| 15 | #define R4 $9 | ||
| 16 | #define L1 $10 | ||
| 17 | #define L2 $11 | ||
| 18 | #define L3 $12 | ||
| 19 | #define L4 $13 | ||
| 20 | #define H1 $14 | ||
| 21 | #define H2 $15 | ||
| 22 | #define H3 $24 | ||
| 23 | #define H4 $25 | ||
| 24 | |||
| 25 | #define P1 $4 | ||
| 26 | #define P2 $5 | ||
| 27 | #define P3 $6 | ||
| 28 | #define P4 $7 | ||
| 29 | |||
| 30 | .align 2 | ||
| 31 | .ent bn_mul_add_words | ||
| 32 | .globl bn_mul_add_words | ||
| 33 | .text | ||
| 34 | bn_mul_add_words: | ||
| 35 | .frame $sp,0,$31 | ||
| 36 | .mask 0x00000000,0 | ||
| 37 | .fmask 0x00000000,0 | ||
| 38 | |||
| 39 | #blt P3,4,$lab34 | ||
| 40 | |||
| 41 | subu R1,P3,4 | ||
| 42 | move CC,$0 | ||
| 43 | bltz R1,$lab34 | ||
| 44 | $lab2: | ||
| 45 | lw R1,0(P1) | ||
| 46 | lw L1,0(P2) | ||
| 47 | lw R2,4(P1) | ||
| 48 | lw L2,4(P2) | ||
| 49 | lw R3,8(P1) | ||
| 50 | lw L3,8(P2) | ||
| 51 | lw R4,12(P1) | ||
| 52 | lw L4,12(P2) | ||
| 53 | multu L1,P4 | ||
| 54 | addu R1,R1,CC | ||
| 55 | mflo L1 | ||
| 56 | sltu CC,R1,CC | ||
| 57 | addu R1,R1,L1 | ||
| 58 | mfhi H1 | ||
| 59 | sltu L1,R1,L1 | ||
| 60 | sw R1,0(P1) | ||
| 61 | addu CC,CC,L1 | ||
| 62 | multu L2,P4 | ||
| 63 | addu CC,H1,CC | ||
| 64 | mflo L2 | ||
| 65 | addu R2,R2,CC | ||
| 66 | sltu CC,R2,CC | ||
| 67 | mfhi H2 | ||
| 68 | addu R2,R2,L2 | ||
| 69 | addu P2,P2,16 | ||
| 70 | sltu L2,R2,L2 | ||
| 71 | sw R2,4(P1) | ||
| 72 | addu CC,CC,L2 | ||
| 73 | multu L3,P4 | ||
| 74 | addu CC,H2,CC | ||
| 75 | mflo L3 | ||
| 76 | addu R3,R3,CC | ||
| 77 | sltu CC,R3,CC | ||
| 78 | mfhi H3 | ||
| 79 | addu R3,R3,L3 | ||
| 80 | addu P1,P1,16 | ||
| 81 | sltu L3,R3,L3 | ||
| 82 | sw R3,-8(P1) | ||
| 83 | addu CC,CC,L3 | ||
| 84 | multu L4,P4 | ||
| 85 | addu CC,H3,CC | ||
| 86 | mflo L4 | ||
| 87 | addu R4,R4,CC | ||
| 88 | sltu CC,R4,CC | ||
| 89 | mfhi H4 | ||
| 90 | addu R4,R4,L4 | ||
| 91 | subu P3,P3,4 | ||
| 92 | sltu L4,R4,L4 | ||
| 93 | addu CC,CC,L4 | ||
| 94 | addu CC,H4,CC | ||
| 95 | |||
| 96 | subu R1,P3,4 | ||
| 97 | sw R4,-4(P1) # delay slot | ||
| 98 | bgez R1,$lab2 | ||
| 99 | |||
| 100 | bleu P3,0,$lab3 | ||
| 101 | .align 2 | ||
| 102 | $lab33: | ||
| 103 | lw L1,0(P2) | ||
| 104 | lw R1,0(P1) | ||
| 105 | multu L1,P4 | ||
| 106 | addu R1,R1,CC | ||
| 107 | sltu CC,R1,CC | ||
| 108 | addu P1,P1,4 | ||
| 109 | mflo L1 | ||
| 110 | mfhi H1 | ||
| 111 | addu R1,R1,L1 | ||
| 112 | addu P2,P2,4 | ||
| 113 | sltu L1,R1,L1 | ||
| 114 | subu P3,P3,1 | ||
| 115 | addu CC,CC,L1 | ||
| 116 | sw R1,-4(P1) | ||
| 117 | addu CC,H1,CC | ||
| 118 | bgtz P3,$lab33 | ||
| 119 | j $31 | ||
| 120 | .align 2 | ||
| 121 | $lab3: | ||
| 122 | j $31 | ||
| 123 | .align 2 | ||
| 124 | $lab34: | ||
| 125 | bgt P3,0,$lab33 | ||
| 126 | j $31 | ||
| 127 | .end bn_mul_add_words | ||
| 128 | |||
| 129 | .align 2 | ||
| 130 | # Program Unit: bn_mul_words | ||
| 131 | .ent bn_mul_words | ||
| 132 | .globl bn_mul_words | ||
| 133 | .text | ||
| 134 | bn_mul_words: | ||
| 135 | .frame $sp,0,$31 | ||
| 136 | .mask 0x00000000,0 | ||
| 137 | .fmask 0x00000000,0 | ||
| 138 | |||
| 139 | subu P3,P3,4 | ||
| 140 | move CC,$0 | ||
| 141 | bltz P3,$lab45 | ||
| 142 | $lab44: | ||
| 143 | lw L1,0(P2) | ||
| 144 | lw L2,4(P2) | ||
| 145 | lw L3,8(P2) | ||
| 146 | lw L4,12(P2) | ||
| 147 | multu L1,P4 | ||
| 148 | subu P3,P3,4 | ||
| 149 | mflo L1 | ||
| 150 | mfhi H1 | ||
| 151 | addu L1,L1,CC | ||
| 152 | multu L2,P4 | ||
| 153 | sltu CC,L1,CC | ||
| 154 | sw L1,0(P1) | ||
| 155 | addu CC,H1,CC | ||
| 156 | mflo L2 | ||
| 157 | mfhi H2 | ||
| 158 | addu L2,L2,CC | ||
| 159 | multu L3,P4 | ||
| 160 | sltu CC,L2,CC | ||
| 161 | sw L2,4(P1) | ||
| 162 | addu CC,H2,CC | ||
| 163 | mflo L3 | ||
| 164 | mfhi H3 | ||
| 165 | addu L3,L3,CC | ||
| 166 | multu L4,P4 | ||
| 167 | sltu CC,L3,CC | ||
| 168 | sw L3,8(P1) | ||
| 169 | addu CC,H3,CC | ||
| 170 | mflo L4 | ||
| 171 | mfhi H4 | ||
| 172 | addu L4,L4,CC | ||
| 173 | addu P1,P1,16 | ||
| 174 | sltu CC,L4,CC | ||
| 175 | addu P2,P2,16 | ||
| 176 | addu CC,H4,CC | ||
| 177 | sw L4,-4(P1) | ||
| 178 | |||
| 179 | bgez P3,$lab44 | ||
| 180 | b $lab45 | ||
| 181 | $lab46: | ||
| 182 | lw L1,0(P2) | ||
| 183 | addu P1,P1,4 | ||
| 184 | multu L1,P4 | ||
| 185 | addu P2,P2,4 | ||
| 186 | mflo L1 | ||
| 187 | mfhi H1 | ||
| 188 | addu L1,L1,CC | ||
| 189 | subu P3,P3,1 | ||
| 190 | sltu CC,L1,CC | ||
| 191 | sw L1,-4(P1) | ||
| 192 | addu CC,H1,CC | ||
| 193 | bgtz P3,$lab46 | ||
| 194 | j $31 | ||
| 195 | $lab45: | ||
| 196 | addu P3,P3,4 | ||
| 197 | bgtz P3,$lab46 | ||
| 198 | j $31 | ||
| 199 | .align 2 | ||
| 200 | .end bn_mul_words | ||
| 201 | |||
| 202 | # Program Unit: bn_sqr_words | ||
| 203 | .ent bn_sqr_words | ||
| 204 | .globl bn_sqr_words | ||
| 205 | .text | ||
| 206 | bn_sqr_words: | ||
| 207 | .frame $sp,0,$31 | ||
| 208 | .mask 0x00000000,0 | ||
| 209 | .fmask 0x00000000,0 | ||
| 210 | |||
| 211 | subu P3,P3,4 | ||
| 212 | bltz P3,$lab55 | ||
| 213 | $lab54: | ||
| 214 | lw L1,0(P2) | ||
| 215 | lw L2,4(P2) | ||
| 216 | lw L3,8(P2) | ||
| 217 | lw L4,12(P2) | ||
| 218 | |||
| 219 | multu L1,L1 | ||
| 220 | subu P3,P3,4 | ||
| 221 | mflo L1 | ||
| 222 | mfhi H1 | ||
| 223 | sw L1,0(P1) | ||
| 224 | sw H1,4(P1) | ||
| 225 | |||
| 226 | multu L2,L2 | ||
| 227 | addu P1,P1,32 | ||
| 228 | mflo L2 | ||
| 229 | mfhi H2 | ||
| 230 | sw L2,-24(P1) | ||
| 231 | sw H2,-20(P1) | ||
| 232 | |||
| 233 | multu L3,L3 | ||
| 234 | addu P2,P2,16 | ||
| 235 | mflo L3 | ||
| 236 | mfhi H3 | ||
| 237 | sw L3,-16(P1) | ||
| 238 | sw H3,-12(P1) | ||
| 239 | |||
| 240 | multu L4,L4 | ||
| 241 | |||
| 242 | mflo L4 | ||
| 243 | mfhi H4 | ||
| 244 | sw L4,-8(P1) | ||
| 245 | sw H4,-4(P1) | ||
| 246 | |||
| 247 | bgtz P3,$lab54 | ||
| 248 | b $lab55 | ||
| 249 | $lab56: | ||
| 250 | lw L1,0(P2) | ||
| 251 | addu P1,P1,8 | ||
| 252 | multu L1,L1 | ||
| 253 | addu P2,P2,4 | ||
| 254 | subu P3,P3,1 | ||
| 255 | mflo L1 | ||
| 256 | mfhi H1 | ||
| 257 | sw L1,-8(P1) | ||
| 258 | sw H1,-4(P1) | ||
| 259 | |||
| 260 | bgtz P3,$lab56 | ||
| 261 | j $31 | ||
| 262 | $lab55: | ||
| 263 | addu P3,P3,4 | ||
| 264 | bgtz P3,$lab56 | ||
| 265 | j $31 | ||
| 266 | .align 2 | ||
| 267 | .end bn_sqr_words | ||
| 268 | |||
| 269 | # Program Unit: bn_add_words | ||
| 270 | .ent bn_add_words | ||
| 271 | .globl bn_add_words | ||
| 272 | .text | ||
| 273 | bn_add_words: # 0x590 | ||
| 274 | .frame $sp,0,$31 | ||
| 275 | .mask 0x00000000,0 | ||
| 276 | .fmask 0x00000000,0 | ||
| 277 | |||
| 278 | subu P4,P4,4 | ||
| 279 | move CC,$0 | ||
| 280 | bltz P4,$lab65 | ||
| 281 | $lab64: | ||
| 282 | lw L1,0(P2) | ||
| 283 | lw R1,0(P3) | ||
| 284 | lw L2,4(P2) | ||
| 285 | lw R2,4(P3) | ||
| 286 | |||
| 287 | addu L1,L1,CC | ||
| 288 | lw L3,8(P2) | ||
| 289 | sltu CC,L1,CC | ||
| 290 | addu L1,L1,R1 | ||
| 291 | sltu R1,L1,R1 | ||
| 292 | lw R3,8(P3) | ||
| 293 | addu CC,CC,R1 | ||
| 294 | lw L4,12(P2) | ||
| 295 | |||
| 296 | addu L2,L2,CC | ||
| 297 | lw R4,12(P3) | ||
| 298 | sltu CC,L2,CC | ||
| 299 | addu L2,L2,R2 | ||
| 300 | sltu R2,L2,R2 | ||
| 301 | sw L1,0(P1) | ||
| 302 | addu CC,CC,R2 | ||
| 303 | addu P1,P1,16 | ||
| 304 | addu L3,L3,CC | ||
| 305 | sw L2,-12(P1) | ||
| 306 | |||
| 307 | sltu CC,L3,CC | ||
| 308 | addu L3,L3,R3 | ||
| 309 | sltu R3,L3,R3 | ||
| 310 | addu P2,P2,16 | ||
| 311 | addu CC,CC,R3 | ||
| 312 | |||
| 313 | addu L4,L4,CC | ||
| 314 | addu P3,P3,16 | ||
| 315 | sltu CC,L4,CC | ||
| 316 | addu L4,L4,R4 | ||
| 317 | subu P4,P4,4 | ||
| 318 | sltu R4,L4,R4 | ||
| 319 | sw L3,-8(P1) | ||
| 320 | addu CC,CC,R4 | ||
| 321 | sw L4,-4(P1) | ||
| 322 | |||
| 323 | bgtz P4,$lab64 | ||
| 324 | b $lab65 | ||
| 325 | $lab66: | ||
| 326 | lw L1,0(P2) | ||
| 327 | lw R1,0(P3) | ||
| 328 | addu L1,L1,CC | ||
| 329 | addu P1,P1,4 | ||
| 330 | sltu CC,L1,CC | ||
| 331 | addu P2,P2,4 | ||
| 332 | addu P3,P3,4 | ||
| 333 | addu L1,L1,R1 | ||
| 334 | subu P4,P4,1 | ||
| 335 | sltu R1,L1,R1 | ||
| 336 | sw L1,-4(P1) | ||
| 337 | addu CC,CC,R1 | ||
| 338 | |||
| 339 | bgtz P4,$lab66 | ||
| 340 | j $31 | ||
| 341 | $lab65: | ||
| 342 | addu P4,P4,4 | ||
| 343 | bgtz P4,$lab66 | ||
| 344 | j $31 | ||
| 345 | .end bn_add_words | ||
| 346 | |||
| 347 | # Program Unit: bn_div64 | ||
| 348 | .set at | ||
| 349 | .set reorder | ||
| 350 | .text | ||
| 351 | .align 2 | ||
| 352 | .globl bn_div64 | ||
| 353 | # 321 { | ||
| 354 | .ent bn_div64 2 | ||
| 355 | bn_div64: | ||
| 356 | subu $sp, 64 | ||
| 357 | sw $31, 56($sp) | ||
| 358 | sw $16, 48($sp) | ||
| 359 | .mask 0x80010000, -56 | ||
| 360 | .frame $sp, 64, $31 | ||
| 361 | move $9, $4 | ||
| 362 | move $12, $5 | ||
| 363 | move $16, $6 | ||
| 364 | # 322 BN_ULONG dh,dl,q,ret=0,th,tl,t; | ||
| 365 | move $31, $0 | ||
| 366 | # 323 int i,count=2; | ||
| 367 | li $13, 2 | ||
| 368 | # 324 | ||
| 369 | # 325 if (d == 0) return(BN_MASK2); | ||
| 370 | bne $16, 0, $80 | ||
| 371 | li $2, -1 | ||
| 372 | b $93 | ||
| 373 | $80: | ||
| 374 | # 326 | ||
| 375 | # 327 i=BN_num_bits_word(d); | ||
| 376 | move $4, $16 | ||
| 377 | sw $31, 16($sp) | ||
| 378 | sw $9, 24($sp) | ||
| 379 | sw $12, 32($sp) | ||
| 380 | sw $13, 40($sp) | ||
| 381 | .livereg 0x800ff0e,0xfff | ||
| 382 | jal BN_num_bits_word | ||
| 383 | li $4, 32 | ||
| 384 | lw $31, 16($sp) | ||
| 385 | lw $9, 24($sp) | ||
| 386 | lw $12, 32($sp) | ||
| 387 | lw $13, 40($sp) | ||
| 388 | move $3, $2 | ||
| 389 | # 328 if ((i != BN_BITS2) && (h > (BN_ULONG)1<<i)) | ||
| 390 | beq $2, $4, $81 | ||
| 391 | li $14, 1 | ||
| 392 | sll $15, $14, $2 | ||
| 393 | bleu $9, $15, $81 | ||
| 394 | # 329 { | ||
| 395 | # 330 #if !defined(NO_STDIO) && !defined(WIN16) | ||
| 396 | # 331 fprintf(stderr,"Division would overflow (%d)\n",i); | ||
| 397 | # 332 #endif | ||
| 398 | # 333 abort(); | ||
| 399 | sw $3, 8($sp) | ||
| 400 | sw $9, 24($sp) | ||
| 401 | sw $12, 32($sp) | ||
| 402 | sw $13, 40($sp) | ||
| 403 | sw $31, 26($sp) | ||
| 404 | .livereg 0xff0e,0xfff | ||
| 405 | jal abort | ||
| 406 | lw $3, 8($sp) | ||
| 407 | li $4, 32 | ||
| 408 | lw $9, 24($sp) | ||
| 409 | lw $12, 32($sp) | ||
| 410 | lw $13, 40($sp) | ||
| 411 | lw $31, 26($sp) | ||
| 412 | # 334 } | ||
| 413 | $81: | ||
| 414 | # 335 i=BN_BITS2-i; | ||
| 415 | subu $3, $4, $3 | ||
| 416 | # 336 if (h >= d) h-=d; | ||
| 417 | bltu $9, $16, $82 | ||
| 418 | subu $9, $9, $16 | ||
| 419 | $82: | ||
| 420 | # 337 | ||
| 421 | # 338 if (i) | ||
| 422 | beq $3, 0, $83 | ||
| 423 | # 339 { | ||
| 424 | # 340 d<<=i; | ||
| 425 | sll $16, $16, $3 | ||
| 426 | # 341 h=(h<<i)|(l>>(BN_BITS2-i)); | ||
| 427 | sll $24, $9, $3 | ||
| 428 | subu $25, $4, $3 | ||
| 429 | srl $14, $12, $25 | ||
| 430 | or $9, $24, $14 | ||
| 431 | # 342 l<<=i; | ||
| 432 | sll $12, $12, $3 | ||
| 433 | # 343 } | ||
| 434 | $83: | ||
| 435 | # 344 dh=(d&BN_MASK2h)>>BN_BITS4; | ||
| 436 | # 345 dl=(d&BN_MASK2l); | ||
| 437 | and $8, $16, -65536 | ||
| 438 | srl $8, $8, 16 | ||
| 439 | and $10, $16, 65535 | ||
| 440 | li $6, -65536 | ||
| 441 | $84: | ||
| 442 | # 346 for (;;) | ||
| 443 | # 347 { | ||
| 444 | # 348 if ((h>>BN_BITS4) == dh) | ||
| 445 | srl $15, $9, 16 | ||
| 446 | bne $8, $15, $85 | ||
| 447 | # 349 q=BN_MASK2l; | ||
| 448 | li $5, 65535 | ||
| 449 | b $86 | ||
| 450 | $85: | ||
| 451 | # 350 else | ||
| 452 | # 351 q=h/dh; | ||
| 453 | divu $5, $9, $8 | ||
| 454 | $86: | ||
| 455 | # 352 | ||
| 456 | # 353 for (;;) | ||
| 457 | # 354 { | ||
| 458 | # 355 t=(h-q*dh); | ||
| 459 | mul $4, $5, $8 | ||
| 460 | subu $2, $9, $4 | ||
| 461 | move $3, $2 | ||
| 462 | # 356 if ((t&BN_MASK2h) || | ||
| 463 | # 357 ((dl*q) <= ( | ||
| 464 | # 358 (t<<BN_BITS4)+ | ||
| 465 | # 359 ((l&BN_MASK2h)>>BN_BITS4)))) | ||
| 466 | and $25, $2, $6 | ||
| 467 | bne $25, $0, $87 | ||
| 468 | mul $24, $10, $5 | ||
| 469 | sll $14, $3, 16 | ||
| 470 | and $15, $12, $6 | ||
| 471 | srl $25, $15, 16 | ||
| 472 | addu $15, $14, $25 | ||
| 473 | bgtu $24, $15, $88 | ||
| 474 | $87: | ||
| 475 | # 360 break; | ||
| 476 | mul $3, $10, $5 | ||
| 477 | b $89 | ||
| 478 | $88: | ||
| 479 | # 361 q--; | ||
| 480 | addu $5, $5, -1 | ||
| 481 | # 362 } | ||
| 482 | b $86 | ||
| 483 | $89: | ||
| 484 | # 363 th=q*dh; | ||
| 485 | # 364 tl=q*dl; | ||
| 486 | # 365 t=(tl>>BN_BITS4); | ||
| 487 | # 366 tl=(tl<<BN_BITS4)&BN_MASK2h; | ||
| 488 | sll $14, $3, 16 | ||
| 489 | and $2, $14, $6 | ||
| 490 | move $11, $2 | ||
| 491 | # 367 th+=t; | ||
| 492 | srl $25, $3, 16 | ||
| 493 | addu $7, $4, $25 | ||
| 494 | # 368 | ||
| 495 | # 369 if (l < tl) th++; | ||
| 496 | bgeu $12, $2, $90 | ||
| 497 | addu $7, $7, 1 | ||
| 498 | $90: | ||
| 499 | # 370 l-=tl; | ||
| 500 | subu $12, $12, $11 | ||
| 501 | # 371 if (h < th) | ||
| 502 | bgeu $9, $7, $91 | ||
| 503 | # 372 { | ||
| 504 | # 373 h+=d; | ||
| 505 | addu $9, $9, $16 | ||
| 506 | # 374 q--; | ||
| 507 | addu $5, $5, -1 | ||
| 508 | # 375 } | ||
| 509 | $91: | ||
| 510 | # 376 h-=th; | ||
| 511 | subu $9, $9, $7 | ||
| 512 | # 377 | ||
| 513 | # 378 if (--count == 0) break; | ||
| 514 | addu $13, $13, -1 | ||
| 515 | beq $13, 0, $92 | ||
| 516 | # 379 | ||
| 517 | # 380 ret=q<<BN_BITS4; | ||
| 518 | sll $31, $5, 16 | ||
| 519 | # 381 h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2; | ||
| 520 | sll $24, $9, 16 | ||
| 521 | srl $15, $12, 16 | ||
| 522 | or $9, $24, $15 | ||
| 523 | # 382 l=(l&BN_MASK2l)<<BN_BITS4; | ||
| 524 | and $12, $12, 65535 | ||
| 525 | sll $12, $12, 16 | ||
| 526 | # 383 } | ||
| 527 | b $84 | ||
| 528 | $92: | ||
| 529 | # 384 ret|=q; | ||
| 530 | or $31, $31, $5 | ||
| 531 | # 385 return(ret); | ||
| 532 | move $2, $31 | ||
| 533 | $93: | ||
| 534 | lw $16, 48($sp) | ||
| 535 | lw $31, 56($sp) | ||
| 536 | addu $sp, 64 | ||
| 537 | j $31 | ||
| 538 | .end bn_div64 | ||
| 539 | |||
diff --git a/src/lib/libcrypto/bn/asm/mips3-mont.pl b/src/lib/libcrypto/bn/asm/mips3-mont.pl new file mode 100644 index 0000000000..8f9156e02a --- /dev/null +++ b/src/lib/libcrypto/bn/asm/mips3-mont.pl | |||
| @@ -0,0 +1,327 @@ | |||
| 1 | #!/usr/bin/env perl | ||
| 2 | # | ||
| 3 | # ==================================================================== | ||
| 4 | # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL | ||
| 5 | # project. The module is, however, dual licensed under OpenSSL and | ||
| 6 | # CRYPTOGAMS licenses depending on where you obtain it. For further | ||
| 7 | # details see http://www.openssl.org/~appro/cryptogams/. | ||
| 8 | # ==================================================================== | ||
| 9 | |||
| 10 | # This module doesn't present direct interest for OpenSSL, because it | ||
| 11 | # doesn't provide better performance for longer keys. While 512-bit | ||
| 12 | # RSA private key operations are 40% faster, 1024-bit ones are hardly | ||
| 13 | # faster at all, while longer key operations are slower by up to 20%. | ||
| 14 | # It might be of interest to embedded system developers though, as | ||
| 15 | # it's smaller than 1KB, yet offers ~3x improvement over compiler | ||
| 16 | # generated code. | ||
| 17 | # | ||
| 18 | # The module targets N32 and N64 MIPS ABIs and currently is a bit | ||
| 19 | # IRIX-centric, i.e. is likely to require adaptation for other OSes. | ||
| 20 | |||
| 21 | # int bn_mul_mont( | ||
| 22 | $rp="a0"; # BN_ULONG *rp, | ||
| 23 | $ap="a1"; # const BN_ULONG *ap, | ||
| 24 | $bp="a2"; # const BN_ULONG *bp, | ||
| 25 | $np="a3"; # const BN_ULONG *np, | ||
| 26 | $n0="a4"; # const BN_ULONG *n0, | ||
| 27 | $num="a5"; # int num); | ||
| 28 | |||
| 29 | $lo0="a6"; | ||
| 30 | $hi0="a7"; | ||
| 31 | $lo1="v0"; | ||
| 32 | $hi1="v1"; | ||
| 33 | $aj="t0"; | ||
| 34 | $bi="t1"; | ||
| 35 | $nj="t2"; | ||
| 36 | $tp="t3"; | ||
| 37 | $alo="s0"; | ||
| 38 | $ahi="s1"; | ||
| 39 | $nlo="s2"; | ||
| 40 | $nhi="s3"; | ||
| 41 | $tj="s4"; | ||
| 42 | $i="s5"; | ||
| 43 | $j="s6"; | ||
| 44 | $fp="t8"; | ||
| 45 | $m1="t9"; | ||
| 46 | |||
| 47 | $FRAME=8*(2+8); | ||
| 48 | |||
| 49 | $code=<<___; | ||
| 50 | #include <asm.h> | ||
| 51 | #include <regdef.h> | ||
| 52 | |||
| 53 | .text | ||
| 54 | |||
| 55 | .set noat | ||
| 56 | .set reorder | ||
| 57 | |||
| 58 | .align 5 | ||
| 59 | .globl bn_mul_mont | ||
| 60 | .ent bn_mul_mont | ||
| 61 | bn_mul_mont: | ||
| 62 | .set noreorder | ||
| 63 | PTR_SUB sp,64 | ||
| 64 | move $fp,sp | ||
| 65 | .frame $fp,64,ra | ||
| 66 | slt AT,$num,4 | ||
| 67 | li v0,0 | ||
| 68 | beqzl AT,.Lproceed | ||
| 69 | nop | ||
| 70 | jr ra | ||
| 71 | PTR_ADD sp,$fp,64 | ||
| 72 | .set reorder | ||
| 73 | .align 5 | ||
| 74 | .Lproceed: | ||
| 75 | ld $n0,0($n0) | ||
| 76 | ld $bi,0($bp) # bp[0] | ||
| 77 | ld $aj,0($ap) # ap[0] | ||
| 78 | ld $nj,0($np) # np[0] | ||
| 79 | PTR_SUB sp,16 # place for two extra words | ||
| 80 | sll $num,3 | ||
| 81 | li AT,-4096 | ||
| 82 | PTR_SUB sp,$num | ||
| 83 | and sp,AT | ||
| 84 | |||
| 85 | sd s0,0($fp) | ||
| 86 | sd s1,8($fp) | ||
| 87 | sd s2,16($fp) | ||
| 88 | sd s3,24($fp) | ||
| 89 | sd s4,32($fp) | ||
| 90 | sd s5,40($fp) | ||
| 91 | sd s6,48($fp) | ||
| 92 | sd s7,56($fp) | ||
| 93 | |||
| 94 | dmultu $aj,$bi | ||
| 95 | ld $alo,8($ap) | ||
| 96 | ld $nlo,8($np) | ||
| 97 | mflo $lo0 | ||
| 98 | mfhi $hi0 | ||
| 99 | dmultu $lo0,$n0 | ||
| 100 | mflo $m1 | ||
| 101 | |||
| 102 | dmultu $alo,$bi | ||
| 103 | mflo $alo | ||
| 104 | mfhi $ahi | ||
| 105 | |||
| 106 | dmultu $nj,$m1 | ||
| 107 | mflo $lo1 | ||
| 108 | mfhi $hi1 | ||
| 109 | dmultu $nlo,$m1 | ||
| 110 | daddu $lo1,$lo0 | ||
| 111 | sltu AT,$lo1,$lo0 | ||
| 112 | daddu $hi1,AT | ||
| 113 | mflo $nlo | ||
| 114 | mfhi $nhi | ||
| 115 | |||
| 116 | move $tp,sp | ||
| 117 | li $j,16 | ||
| 118 | .align 4 | ||
| 119 | .L1st: | ||
| 120 | .set noreorder | ||
| 121 | PTR_ADD $aj,$ap,$j | ||
| 122 | ld $aj,($aj) | ||
| 123 | PTR_ADD $nj,$np,$j | ||
| 124 | ld $nj,($nj) | ||
| 125 | |||
| 126 | dmultu $aj,$bi | ||
| 127 | daddu $lo0,$alo,$hi0 | ||
| 128 | daddu $lo1,$nlo,$hi1 | ||
| 129 | sltu AT,$lo0,$hi0 | ||
| 130 | sltu s7,$lo1,$hi1 | ||
| 131 | daddu $hi0,$ahi,AT | ||
| 132 | daddu $hi1,$nhi,s7 | ||
| 133 | mflo $alo | ||
| 134 | mfhi $ahi | ||
| 135 | |||
| 136 | daddu $lo1,$lo0 | ||
| 137 | sltu AT,$lo1,$lo0 | ||
| 138 | dmultu $nj,$m1 | ||
| 139 | daddu $hi1,AT | ||
| 140 | addu $j,8 | ||
| 141 | sd $lo1,($tp) | ||
| 142 | sltu s7,$j,$num | ||
| 143 | mflo $nlo | ||
| 144 | mfhi $nhi | ||
| 145 | |||
| 146 | bnez s7,.L1st | ||
| 147 | PTR_ADD $tp,8 | ||
| 148 | .set reorder | ||
| 149 | |||
| 150 | daddu $lo0,$alo,$hi0 | ||
| 151 | sltu AT,$lo0,$hi0 | ||
| 152 | daddu $hi0,$ahi,AT | ||
| 153 | |||
| 154 | daddu $lo1,$nlo,$hi1 | ||
| 155 | sltu s7,$lo1,$hi1 | ||
| 156 | daddu $hi1,$nhi,s7 | ||
| 157 | daddu $lo1,$lo0 | ||
| 158 | sltu AT,$lo1,$lo0 | ||
| 159 | daddu $hi1,AT | ||
| 160 | |||
| 161 | sd $lo1,($tp) | ||
| 162 | |||
| 163 | daddu $hi1,$hi0 | ||
| 164 | sltu AT,$hi1,$hi0 | ||
| 165 | sd $hi1,8($tp) | ||
| 166 | sd AT,16($tp) | ||
| 167 | |||
| 168 | li $i,8 | ||
| 169 | .align 4 | ||
| 170 | .Louter: | ||
| 171 | PTR_ADD $bi,$bp,$i | ||
| 172 | ld $bi,($bi) | ||
| 173 | ld $aj,($ap) | ||
| 174 | ld $alo,8($ap) | ||
| 175 | ld $tj,(sp) | ||
| 176 | |||
| 177 | dmultu $aj,$bi | ||
| 178 | ld $nj,($np) | ||
| 179 | ld $nlo,8($np) | ||
| 180 | mflo $lo0 | ||
| 181 | mfhi $hi0 | ||
| 182 | daddu $lo0,$tj | ||
| 183 | dmultu $lo0,$n0 | ||
| 184 | sltu AT,$lo0,$tj | ||
| 185 | daddu $hi0,AT | ||
| 186 | mflo $m1 | ||
| 187 | |||
| 188 | dmultu $alo,$bi | ||
| 189 | mflo $alo | ||
| 190 | mfhi $ahi | ||
| 191 | |||
| 192 | dmultu $nj,$m1 | ||
| 193 | mflo $lo1 | ||
| 194 | mfhi $hi1 | ||
| 195 | |||
| 196 | dmultu $nlo,$m1 | ||
| 197 | daddu $lo1,$lo0 | ||
| 198 | sltu AT,$lo1,$lo0 | ||
| 199 | daddu $hi1,AT | ||
| 200 | mflo $nlo | ||
| 201 | mfhi $nhi | ||
| 202 | |||
| 203 | move $tp,sp | ||
| 204 | li $j,16 | ||
| 205 | ld $tj,8($tp) | ||
| 206 | .align 4 | ||
| 207 | .Linner: | ||
| 208 | .set noreorder | ||
| 209 | PTR_ADD $aj,$ap,$j | ||
| 210 | ld $aj,($aj) | ||
| 211 | PTR_ADD $nj,$np,$j | ||
| 212 | ld $nj,($nj) | ||
| 213 | |||
| 214 | dmultu $aj,$bi | ||
| 215 | daddu $lo0,$alo,$hi0 | ||
| 216 | daddu $lo1,$nlo,$hi1 | ||
| 217 | sltu AT,$lo0,$hi0 | ||
| 218 | sltu s7,$lo1,$hi1 | ||
| 219 | daddu $hi0,$ahi,AT | ||
| 220 | daddu $hi1,$nhi,s7 | ||
| 221 | mflo $alo | ||
| 222 | mfhi $ahi | ||
| 223 | |||
| 224 | daddu $lo0,$tj | ||
| 225 | addu $j,8 | ||
| 226 | dmultu $nj,$m1 | ||
| 227 | sltu AT,$lo0,$tj | ||
| 228 | daddu $lo1,$lo0 | ||
| 229 | daddu $hi0,AT | ||
| 230 | sltu s7,$lo1,$lo0 | ||
| 231 | ld $tj,16($tp) | ||
| 232 | daddu $hi1,s7 | ||
| 233 | sltu AT,$j,$num | ||
| 234 | mflo $nlo | ||
| 235 | mfhi $nhi | ||
| 236 | sd $lo1,($tp) | ||
| 237 | bnez AT,.Linner | ||
| 238 | PTR_ADD $tp,8 | ||
| 239 | .set reorder | ||
| 240 | |||
| 241 | daddu $lo0,$alo,$hi0 | ||
| 242 | sltu AT,$lo0,$hi0 | ||
| 243 | daddu $hi0,$ahi,AT | ||
| 244 | daddu $lo0,$tj | ||
| 245 | sltu s7,$lo0,$tj | ||
| 246 | daddu $hi0,s7 | ||
| 247 | |||
| 248 | ld $tj,16($tp) | ||
| 249 | daddu $lo1,$nlo,$hi1 | ||
| 250 | sltu AT,$lo1,$hi1 | ||
| 251 | daddu $hi1,$nhi,AT | ||
| 252 | daddu $lo1,$lo0 | ||
| 253 | sltu s7,$lo1,$lo0 | ||
| 254 | daddu $hi1,s7 | ||
| 255 | sd $lo1,($tp) | ||
| 256 | |||
| 257 | daddu $lo1,$hi1,$hi0 | ||
| 258 | sltu $hi1,$lo1,$hi0 | ||
| 259 | daddu $lo1,$tj | ||
| 260 | sltu AT,$lo1,$tj | ||
| 261 | daddu $hi1,AT | ||
| 262 | sd $lo1,8($tp) | ||
| 263 | sd $hi1,16($tp) | ||
| 264 | |||
| 265 | addu $i,8 | ||
| 266 | sltu s7,$i,$num | ||
| 267 | bnez s7,.Louter | ||
| 268 | |||
| 269 | .set noreorder | ||
| 270 | PTR_ADD $tj,sp,$num # &tp[num] | ||
| 271 | move $tp,sp | ||
| 272 | move $ap,sp | ||
| 273 | li $hi0,0 # clear borrow bit | ||
| 274 | |||
| 275 | .align 4 | ||
| 276 | .Lsub: ld $lo0,($tp) | ||
| 277 | ld $lo1,($np) | ||
| 278 | PTR_ADD $tp,8 | ||
| 279 | PTR_ADD $np,8 | ||
| 280 | dsubu $lo1,$lo0,$lo1 # tp[i]-np[i] | ||
| 281 | sgtu AT,$lo1,$lo0 | ||
| 282 | dsubu $lo0,$lo1,$hi0 | ||
| 283 | sgtu $hi0,$lo0,$lo1 | ||
| 284 | sd $lo0,($rp) | ||
| 285 | or $hi0,AT | ||
| 286 | sltu AT,$tp,$tj | ||
| 287 | bnez AT,.Lsub | ||
| 288 | PTR_ADD $rp,8 | ||
| 289 | |||
| 290 | dsubu $hi0,$hi1,$hi0 # handle upmost overflow bit | ||
| 291 | move $tp,sp | ||
| 292 | PTR_SUB $rp,$num # restore rp | ||
| 293 | not $hi1,$hi0 | ||
| 294 | |||
| 295 | and $ap,$hi0,sp | ||
| 296 | and $bp,$hi1,$rp | ||
| 297 | or $ap,$ap,$bp # ap=borrow?tp:rp | ||
| 298 | |||
| 299 | .align 4 | ||
| 300 | .Lcopy: ld $aj,($ap) | ||
| 301 | PTR_ADD $ap,8 | ||
| 302 | PTR_ADD $tp,8 | ||
| 303 | sd zero,-8($tp) | ||
| 304 | sltu AT,$tp,$tj | ||
| 305 | sd $aj,($rp) | ||
| 306 | bnez AT,.Lcopy | ||
| 307 | PTR_ADD $rp,8 | ||
| 308 | |||
| 309 | ld s0,0($fp) | ||
| 310 | ld s1,8($fp) | ||
| 311 | ld s2,16($fp) | ||
| 312 | ld s3,24($fp) | ||
| 313 | ld s4,32($fp) | ||
| 314 | ld s5,40($fp) | ||
| 315 | ld s6,48($fp) | ||
| 316 | ld s7,56($fp) | ||
| 317 | li v0,1 | ||
| 318 | jr ra | ||
| 319 | PTR_ADD sp,$fp,64 | ||
| 320 | .set reorder | ||
| 321 | END(bn_mul_mont) | ||
| 322 | .rdata | ||
| 323 | .asciiz "Montgomery Multiplication for MIPS III/IV, CRYPTOGAMS by <appro\@openssl.org>" | ||
| 324 | ___ | ||
| 325 | |||
| 326 | print $code; | ||
| 327 | close STDOUT; | ||
diff --git a/src/lib/libcrypto/bn/asm/mo-586.pl b/src/lib/libcrypto/bn/asm/mo-586.pl deleted file mode 100644 index 0982293094..0000000000 --- a/src/lib/libcrypto/bn/asm/mo-586.pl +++ /dev/null | |||
| @@ -1,603 +0,0 @@ | |||
| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | # This is crypto/bn/asm/x86-mont.pl (with asciz from crypto/perlasm/x86asm.pl) | ||
| 4 | # from OpenSSL 0.9.9-dev | ||
| 5 | |||
| 6 | sub ::asciz | ||
| 7 | { my @str=unpack("C*",shift); | ||
| 8 | push @str,0; | ||
| 9 | while ($#str>15) { | ||
| 10 | &data_byte(@str[0..15]); | ||
| 11 | foreach (0..15) { shift @str; } | ||
| 12 | } | ||
| 13 | &data_byte(@str) if (@str); | ||
| 14 | } | ||
| 15 | |||
| 16 | # ==================================================================== | ||
| 17 | # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL | ||
| 18 | # project. The module is, however, dual licensed under OpenSSL and | ||
| 19 | # CRYPTOGAMS licenses depending on where you obtain it. For further | ||
| 20 | # details see http://www.openssl.org/~appro/cryptogams/. | ||
| 21 | # ==================================================================== | ||
| 22 | |||
| 23 | # October 2005 | ||
| 24 | # | ||
| 25 | # This is a "teaser" code, as it can be improved in several ways... | ||
| 26 | # First of all non-SSE2 path should be implemented (yes, for now it | ||
| 27 | # performs Montgomery multiplication/convolution only on SSE2-capable | ||
| 28 | # CPUs such as P4, others fall down to original code). Then inner loop | ||
| 29 | # can be unrolled and modulo-scheduled to improve ILP and possibly | ||
| 30 | # moved to 128-bit XMM register bank (though it would require input | ||
| 31 | # rearrangement and/or increase bus bandwidth utilization). Dedicated | ||
| 32 | # squaring procedure should give further performance improvement... | ||
| 33 | # Yet, for being draft, the code improves rsa512 *sign* benchmark by | ||
| 34 | # 110%(!), rsa1024 one - by 70% and rsa4096 - by 20%:-) | ||
| 35 | |||
| 36 | # December 2006 | ||
| 37 | # | ||
| 38 | # Modulo-scheduling SSE2 loops results in further 15-20% improvement. | ||
| 39 | # Integer-only code [being equipped with dedicated squaring procedure] | ||
| 40 | # gives ~40% on rsa512 sign benchmark... | ||
| 41 | |||
| 42 | push(@INC,"perlasm","../../perlasm"); | ||
| 43 | require "x86asm.pl"; | ||
| 44 | |||
| 45 | &asm_init($ARGV[0],$0); | ||
| 46 | |||
| 47 | $sse2=0; | ||
| 48 | for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); } | ||
| 49 | |||
| 50 | &external_label("OPENSSL_ia32cap_P") if ($sse2); | ||
| 51 | |||
| 52 | &function_begin("bn_mul_mont"); | ||
| 53 | |||
| 54 | $i="edx"; | ||
| 55 | $j="ecx"; | ||
| 56 | $ap="esi"; $tp="esi"; # overlapping variables!!! | ||
| 57 | $rp="edi"; $bp="edi"; # overlapping variables!!! | ||
| 58 | $np="ebp"; | ||
| 59 | $num="ebx"; | ||
| 60 | |||
| 61 | $_num=&DWP(4*0,"esp"); # stack top layout | ||
| 62 | $_rp=&DWP(4*1,"esp"); | ||
| 63 | $_ap=&DWP(4*2,"esp"); | ||
| 64 | $_bp=&DWP(4*3,"esp"); | ||
| 65 | $_np=&DWP(4*4,"esp"); | ||
| 66 | $_n0=&DWP(4*5,"esp"); $_n0q=&QWP(4*5,"esp"); | ||
| 67 | $_sp=&DWP(4*6,"esp"); | ||
| 68 | $_bpend=&DWP(4*7,"esp"); | ||
| 69 | $frame=32; # size of above frame rounded up to 16n | ||
| 70 | |||
| 71 | &xor ("eax","eax"); | ||
| 72 | &mov ("edi",&wparam(5)); # int num | ||
| 73 | &cmp ("edi",4); | ||
| 74 | &jl (&label("just_leave")); | ||
| 75 | |||
| 76 | &lea ("esi",&wparam(0)); # put aside pointer to argument block | ||
| 77 | &lea ("edx",&wparam(1)); # load ap | ||
| 78 | &mov ("ebp","esp"); # saved stack pointer! | ||
| 79 | &add ("edi",2); # extra two words on top of tp | ||
| 80 | &neg ("edi"); | ||
| 81 | &lea ("esp",&DWP(-$frame,"esp","edi",4)); # alloca($frame+4*(num+2)) | ||
| 82 | &neg ("edi"); | ||
| 83 | |||
| 84 | # minimize cache contention by arraning 2K window between stack | ||
| 85 | # pointer and ap argument [np is also position sensitive vector, | ||
| 86 | # but it's assumed to be near ap, as it's allocated at ~same | ||
| 87 | # time]. | ||
| 88 | &mov ("eax","esp"); | ||
| 89 | &sub ("eax","edx"); | ||
| 90 | &and ("eax",2047); | ||
| 91 | &sub ("esp","eax"); # this aligns sp and ap modulo 2048 | ||
| 92 | |||
| 93 | &xor ("edx","esp"); | ||
| 94 | &and ("edx",2048); | ||
| 95 | &xor ("edx",2048); | ||
| 96 | &sub ("esp","edx"); # this splits them apart modulo 4096 | ||
| 97 | |||
| 98 | &and ("esp",-64); # align to cache line | ||
| 99 | |||
| 100 | ################################# load argument block... | ||
| 101 | &mov ("eax",&DWP(0*4,"esi"));# BN_ULONG *rp | ||
| 102 | &mov ("ebx",&DWP(1*4,"esi"));# const BN_ULONG *ap | ||
| 103 | &mov ("ecx",&DWP(2*4,"esi"));# const BN_ULONG *bp | ||
| 104 | &mov ("edx",&DWP(3*4,"esi"));# const BN_ULONG *np | ||
| 105 | &mov ("esi",&DWP(4*4,"esi"));# const BN_ULONG *n0 | ||
| 106 | #&mov ("edi",&DWP(5*4,"esi"));# int num | ||
| 107 | |||
| 108 | &mov ("esi",&DWP(0,"esi")); # pull n0[0] | ||
| 109 | &mov ($_rp,"eax"); # ... save a copy of argument block | ||
| 110 | &mov ($_ap,"ebx"); | ||
| 111 | &mov ($_bp,"ecx"); | ||
| 112 | &mov ($_np,"edx"); | ||
| 113 | &mov ($_n0,"esi"); | ||
| 114 | &lea ($num,&DWP(-3,"edi")); # num=num-1 to assist modulo-scheduling | ||
| 115 | #&mov ($_num,$num); # redundant as $num is not reused | ||
| 116 | &mov ($_sp,"ebp"); # saved stack pointer! | ||
| 117 | |||
| 118 | if($sse2) { | ||
| 119 | $acc0="mm0"; # mmx register bank layout | ||
| 120 | $acc1="mm1"; | ||
| 121 | $car0="mm2"; | ||
| 122 | $car1="mm3"; | ||
| 123 | $mul0="mm4"; | ||
| 124 | $mul1="mm5"; | ||
| 125 | $temp="mm6"; | ||
| 126 | $mask="mm7"; | ||
| 127 | |||
| 128 | &picmeup("eax","OPENSSL_ia32cap_P"); | ||
| 129 | &bt (&DWP(0,"eax"),26); | ||
| 130 | &jnc (&label("non_sse2")); | ||
| 131 | |||
| 132 | &mov ("eax",-1); | ||
| 133 | &movd ($mask,"eax"); # mask 32 lower bits | ||
| 134 | |||
| 135 | &mov ($ap,$_ap); # load input pointers | ||
| 136 | &mov ($bp,$_bp); | ||
| 137 | &mov ($np,$_np); | ||
| 138 | |||
| 139 | &xor ($i,$i); # i=0 | ||
| 140 | &xor ($j,$j); # j=0 | ||
| 141 | |||
| 142 | &movd ($mul0,&DWP(0,$bp)); # bp[0] | ||
| 143 | &movd ($mul1,&DWP(0,$ap)); # ap[0] | ||
| 144 | &movd ($car1,&DWP(0,$np)); # np[0] | ||
| 145 | |||
| 146 | &pmuludq($mul1,$mul0); # ap[0]*bp[0] | ||
| 147 | &movq ($car0,$mul1); | ||
| 148 | &movq ($acc0,$mul1); # I wish movd worked for | ||
| 149 | &pand ($acc0,$mask); # inter-register transfers | ||
| 150 | |||
| 151 | &pmuludq($mul1,$_n0q); # *=n0 | ||
| 152 | |||
| 153 | &pmuludq($car1,$mul1); # "t[0]"*np[0]*n0 | ||
| 154 | &paddq ($car1,$acc0); | ||
| 155 | |||
| 156 | &movd ($acc1,&DWP(4,$np)); # np[1] | ||
| 157 | &movd ($acc0,&DWP(4,$ap)); # ap[1] | ||
| 158 | |||
| 159 | &psrlq ($car0,32); | ||
| 160 | &psrlq ($car1,32); | ||
| 161 | |||
| 162 | &inc ($j); # j++ | ||
| 163 | &set_label("1st",16); | ||
| 164 | &pmuludq($acc0,$mul0); # ap[j]*bp[0] | ||
| 165 | &pmuludq($acc1,$mul1); # np[j]*m1 | ||
| 166 | &paddq ($car0,$acc0); # +=c0 | ||
| 167 | &paddq ($car1,$acc1); # +=c1 | ||
| 168 | |||
| 169 | &movq ($acc0,$car0); | ||
| 170 | &pand ($acc0,$mask); | ||
| 171 | &movd ($acc1,&DWP(4,$np,$j,4)); # np[j+1] | ||
| 172 | &paddq ($car1,$acc0); # +=ap[j]*bp[0]; | ||
| 173 | &movd ($acc0,&DWP(4,$ap,$j,4)); # ap[j+1] | ||
| 174 | &psrlq ($car0,32); | ||
| 175 | &movd (&DWP($frame-4,"esp",$j,4),$car1); # tp[j-1]= | ||
| 176 | &psrlq ($car1,32); | ||
| 177 | |||
| 178 | &lea ($j,&DWP(1,$j)); | ||
| 179 | &cmp ($j,$num); | ||
| 180 | &jl (&label("1st")); | ||
| 181 | |||
| 182 | &pmuludq($acc0,$mul0); # ap[num-1]*bp[0] | ||
| 183 | &pmuludq($acc1,$mul1); # np[num-1]*m1 | ||
| 184 | &paddq ($car0,$acc0); # +=c0 | ||
| 185 | &paddq ($car1,$acc1); # +=c1 | ||
| 186 | |||
| 187 | &movq ($acc0,$car0); | ||
| 188 | &pand ($acc0,$mask); | ||
| 189 | &paddq ($car1,$acc0); # +=ap[num-1]*bp[0]; | ||
| 190 | &movd (&DWP($frame-4,"esp",$j,4),$car1); # tp[num-2]= | ||
| 191 | |||
| 192 | &psrlq ($car0,32); | ||
| 193 | &psrlq ($car1,32); | ||
| 194 | |||
| 195 | &paddq ($car1,$car0); | ||
| 196 | &movq (&QWP($frame,"esp",$num,4),$car1); # tp[num].tp[num-1] | ||
| 197 | |||
| 198 | &inc ($i); # i++ | ||
| 199 | &set_label("outer"); | ||
| 200 | &xor ($j,$j); # j=0 | ||
| 201 | |||
| 202 | &movd ($mul0,&DWP(0,$bp,$i,4)); # bp[i] | ||
| 203 | &movd ($mul1,&DWP(0,$ap)); # ap[0] | ||
| 204 | &movd ($temp,&DWP($frame,"esp")); # tp[0] | ||
| 205 | &movd ($car1,&DWP(0,$np)); # np[0] | ||
| 206 | &pmuludq($mul1,$mul0); # ap[0]*bp[i] | ||
| 207 | |||
| 208 | &paddq ($mul1,$temp); # +=tp[0] | ||
| 209 | &movq ($acc0,$mul1); | ||
| 210 | &movq ($car0,$mul1); | ||
| 211 | &pand ($acc0,$mask); | ||
| 212 | |||
| 213 | &pmuludq($mul1,$_n0q); # *=n0 | ||
| 214 | |||
| 215 | &pmuludq($car1,$mul1); | ||
| 216 | &paddq ($car1,$acc0); | ||
| 217 | |||
| 218 | &movd ($temp,&DWP($frame+4,"esp")); # tp[1] | ||
| 219 | &movd ($acc1,&DWP(4,$np)); # np[1] | ||
| 220 | &movd ($acc0,&DWP(4,$ap)); # ap[1] | ||
| 221 | |||
| 222 | &psrlq ($car0,32); | ||
| 223 | &psrlq ($car1,32); | ||
| 224 | &paddq ($car0,$temp); # +=tp[1] | ||
| 225 | |||
| 226 | &inc ($j); # j++ | ||
| 227 | &dec ($num); | ||
| 228 | &set_label("inner"); | ||
| 229 | &pmuludq($acc0,$mul0); # ap[j]*bp[i] | ||
| 230 | &pmuludq($acc1,$mul1); # np[j]*m1 | ||
| 231 | &paddq ($car0,$acc0); # +=c0 | ||
| 232 | &paddq ($car1,$acc1); # +=c1 | ||
| 233 | |||
| 234 | &movq ($acc0,$car0); | ||
| 235 | &movd ($temp,&DWP($frame+4,"esp",$j,4));# tp[j+1] | ||
| 236 | &pand ($acc0,$mask); | ||
| 237 | &movd ($acc1,&DWP(4,$np,$j,4)); # np[j+1] | ||
| 238 | &paddq ($car1,$acc0); # +=ap[j]*bp[i]+tp[j] | ||
| 239 | &movd ($acc0,&DWP(4,$ap,$j,4)); # ap[j+1] | ||
| 240 | &psrlq ($car0,32); | ||
| 241 | &movd (&DWP($frame-4,"esp",$j,4),$car1);# tp[j-1]= | ||
| 242 | &psrlq ($car1,32); | ||
| 243 | &paddq ($car0,$temp); # +=tp[j+1] | ||
| 244 | |||
| 245 | &dec ($num); | ||
| 246 | &lea ($j,&DWP(1,$j)); # j++ | ||
| 247 | &jnz (&label("inner")); | ||
| 248 | |||
| 249 | &mov ($num,$j); | ||
| 250 | &pmuludq($acc0,$mul0); # ap[num-1]*bp[i] | ||
| 251 | &pmuludq($acc1,$mul1); # np[num-1]*m1 | ||
| 252 | &paddq ($car0,$acc0); # +=c0 | ||
| 253 | &paddq ($car1,$acc1); # +=c1 | ||
| 254 | |||
| 255 | &movq ($acc0,$car0); | ||
| 256 | &pand ($acc0,$mask); | ||
| 257 | &paddq ($car1,$acc0); # +=ap[num-1]*bp[i]+tp[num-1] | ||
| 258 | &movd (&DWP($frame-4,"esp",$j,4),$car1); # tp[num-2]= | ||
| 259 | &psrlq ($car0,32); | ||
| 260 | &psrlq ($car1,32); | ||
| 261 | |||
| 262 | &movd ($temp,&DWP($frame+4,"esp",$num,4)); # += tp[num] | ||
| 263 | &paddq ($car1,$car0); | ||
| 264 | &paddq ($car1,$temp); | ||
| 265 | &movq (&QWP($frame,"esp",$num,4),$car1); # tp[num].tp[num-1] | ||
| 266 | |||
| 267 | &lea ($i,&DWP(1,$i)); # i++ | ||
| 268 | &cmp ($i,$num); | ||
| 269 | &jle (&label("outer")); | ||
| 270 | |||
| 271 | &emms (); # done with mmx bank | ||
| 272 | &jmp (&label("common_tail")); | ||
| 273 | |||
| 274 | &set_label("non_sse2",16); | ||
| 275 | } | ||
| 276 | |||
| 277 | if (0) { | ||
| 278 | &mov ("esp",$_sp); | ||
| 279 | &xor ("eax","eax"); # signal "not fast enough [yet]" | ||
| 280 | &jmp (&label("just_leave")); | ||
| 281 | # While the below code provides competitive performance for | ||
| 282 | # all key lengthes on modern Intel cores, it's still more | ||
| 283 | # than 10% slower for 4096-bit key elsewhere:-( "Competitive" | ||
| 284 | # means compared to the original integer-only assembler. | ||
| 285 | # 512-bit RSA sign is better by ~40%, but that's about all | ||
| 286 | # one can say about all CPUs... | ||
| 287 | } else { | ||
| 288 | $inp="esi"; # integer path uses these registers differently | ||
| 289 | $word="edi"; | ||
| 290 | $carry="ebp"; | ||
| 291 | |||
| 292 | &mov ($inp,$_ap); | ||
| 293 | &lea ($carry,&DWP(1,$num)); | ||
| 294 | &mov ($word,$_bp); | ||
| 295 | &xor ($j,$j); # j=0 | ||
| 296 | &mov ("edx",$inp); | ||
| 297 | &and ($carry,1); # see if num is even | ||
| 298 | &sub ("edx",$word); # see if ap==bp | ||
| 299 | &lea ("eax",&DWP(4,$word,$num,4)); # &bp[num] | ||
| 300 | &or ($carry,"edx"); | ||
| 301 | &mov ($word,&DWP(0,$word)); # bp[0] | ||
| 302 | &jz (&label("bn_sqr_mont")); | ||
| 303 | &mov ($_bpend,"eax"); | ||
| 304 | &mov ("eax",&DWP(0,$inp)); | ||
| 305 | &xor ("edx","edx"); | ||
| 306 | |||
| 307 | &set_label("mull",16); | ||
| 308 | &mov ($carry,"edx"); | ||
| 309 | &mul ($word); # ap[j]*bp[0] | ||
| 310 | &add ($carry,"eax"); | ||
| 311 | &lea ($j,&DWP(1,$j)); | ||
| 312 | &adc ("edx",0); | ||
| 313 | &mov ("eax",&DWP(0,$inp,$j,4)); # ap[j+1] | ||
| 314 | &cmp ($j,$num); | ||
| 315 | &mov (&DWP($frame-4,"esp",$j,4),$carry); # tp[j]= | ||
| 316 | &jl (&label("mull")); | ||
| 317 | |||
| 318 | &mov ($carry,"edx"); | ||
| 319 | &mul ($word); # ap[num-1]*bp[0] | ||
| 320 | &mov ($word,$_n0); | ||
| 321 | &add ("eax",$carry); | ||
| 322 | &mov ($inp,$_np); | ||
| 323 | &adc ("edx",0); | ||
| 324 | &imul ($word,&DWP($frame,"esp")); # n0*tp[0] | ||
| 325 | |||
| 326 | &mov (&DWP($frame,"esp",$num,4),"eax"); # tp[num-1]= | ||
| 327 | &xor ($j,$j); | ||
| 328 | &mov (&DWP($frame+4,"esp",$num,4),"edx"); # tp[num]= | ||
| 329 | &mov (&DWP($frame+8,"esp",$num,4),$j); # tp[num+1]= | ||
| 330 | |||
| 331 | &mov ("eax",&DWP(0,$inp)); # np[0] | ||
| 332 | &mul ($word); # np[0]*m | ||
| 333 | &add ("eax",&DWP($frame,"esp")); # +=tp[0] | ||
| 334 | &mov ("eax",&DWP(4,$inp)); # np[1] | ||
| 335 | &adc ("edx",0); | ||
| 336 | &inc ($j); | ||
| 337 | |||
| 338 | &jmp (&label("2ndmadd")); | ||
| 339 | |||
| 340 | &set_label("1stmadd",16); | ||
| 341 | &mov ($carry,"edx"); | ||
| 342 | &mul ($word); # ap[j]*bp[i] | ||
| 343 | &add ($carry,&DWP($frame,"esp",$j,4)); # +=tp[j] | ||
| 344 | &lea ($j,&DWP(1,$j)); | ||
| 345 | &adc ("edx",0); | ||
| 346 | &add ($carry,"eax"); | ||
| 347 | &mov ("eax",&DWP(0,$inp,$j,4)); # ap[j+1] | ||
| 348 | &adc ("edx",0); | ||
| 349 | &cmp ($j,$num); | ||
| 350 | &mov (&DWP($frame-4,"esp",$j,4),$carry); # tp[j]= | ||
| 351 | &jl (&label("1stmadd")); | ||
| 352 | |||
| 353 | &mov ($carry,"edx"); | ||
| 354 | &mul ($word); # ap[num-1]*bp[i] | ||
| 355 | &add ("eax",&DWP($frame,"esp",$num,4)); # +=tp[num-1] | ||
| 356 | &mov ($word,$_n0); | ||
| 357 | &adc ("edx",0); | ||
| 358 | &mov ($inp,$_np); | ||
| 359 | &add ($carry,"eax"); | ||
| 360 | &adc ("edx",0); | ||
| 361 | &imul ($word,&DWP($frame,"esp")); # n0*tp[0] | ||
| 362 | |||
| 363 | &xor ($j,$j); | ||
| 364 | &add ("edx",&DWP($frame+4,"esp",$num,4)); # carry+=tp[num] | ||
| 365 | &mov (&DWP($frame,"esp",$num,4),$carry); # tp[num-1]= | ||
| 366 | &adc ($j,0); | ||
| 367 | &mov ("eax",&DWP(0,$inp)); # np[0] | ||
| 368 | &mov (&DWP($frame+4,"esp",$num,4),"edx"); # tp[num]= | ||
| 369 | &mov (&DWP($frame+8,"esp",$num,4),$j); # tp[num+1]= | ||
| 370 | |||
| 371 | &mul ($word); # np[0]*m | ||
| 372 | &add ("eax",&DWP($frame,"esp")); # +=tp[0] | ||
| 373 | &mov ("eax",&DWP(4,$inp)); # np[1] | ||
| 374 | &adc ("edx",0); | ||
| 375 | &mov ($j,1); | ||
| 376 | |||
| 377 | &set_label("2ndmadd",16); | ||
| 378 | &mov ($carry,"edx"); | ||
| 379 | &mul ($word); # np[j]*m | ||
| 380 | &add ($carry,&DWP($frame,"esp",$j,4)); # +=tp[j] | ||
| 381 | &lea ($j,&DWP(1,$j)); | ||
| 382 | &adc ("edx",0); | ||
| 383 | &add ($carry,"eax"); | ||
| 384 | &mov ("eax",&DWP(0,$inp,$j,4)); # np[j+1] | ||
| 385 | &adc ("edx",0); | ||
| 386 | &cmp ($j,$num); | ||
| 387 | &mov (&DWP($frame-8,"esp",$j,4),$carry); # tp[j-1]= | ||
| 388 | &jl (&label("2ndmadd")); | ||
| 389 | |||
| 390 | &mov ($carry,"edx"); | ||
| 391 | &mul ($word); # np[j]*m | ||
| 392 | &add ($carry,&DWP($frame,"esp",$num,4)); # +=tp[num-1] | ||
| 393 | &adc ("edx",0); | ||
| 394 | &add ($carry,"eax"); | ||
| 395 | &adc ("edx",0); | ||
| 396 | &mov (&DWP($frame-4,"esp",$num,4),$carry); # tp[num-2]= | ||
| 397 | |||
| 398 | &xor ("eax","eax"); | ||
| 399 | &mov ($j,$_bp); # &bp[i] | ||
| 400 | &add ("edx",&DWP($frame+4,"esp",$num,4)); # carry+=tp[num] | ||
| 401 | &adc ("eax",&DWP($frame+8,"esp",$num,4)); # +=tp[num+1] | ||
| 402 | &lea ($j,&DWP(4,$j)); | ||
| 403 | &mov (&DWP($frame,"esp",$num,4),"edx"); # tp[num-1]= | ||
| 404 | &cmp ($j,$_bpend); | ||
| 405 | &mov (&DWP($frame+4,"esp",$num,4),"eax"); # tp[num]= | ||
| 406 | &je (&label("common_tail")); | ||
| 407 | |||
| 408 | &mov ($word,&DWP(0,$j)); # bp[i+1] | ||
| 409 | &mov ($inp,$_ap); | ||
| 410 | &mov ($_bp,$j); # &bp[++i] | ||
| 411 | &xor ($j,$j); | ||
| 412 | &xor ("edx","edx"); | ||
| 413 | &mov ("eax",&DWP(0,$inp)); | ||
| 414 | &jmp (&label("1stmadd")); | ||
| 415 | |||
| 416 | &set_label("bn_sqr_mont",16); | ||
| 417 | $sbit=$num; | ||
| 418 | &mov ($_num,$num); | ||
| 419 | &mov ($_bp,$j); # i=0 | ||
| 420 | |||
| 421 | &mov ("eax",$word); # ap[0] | ||
| 422 | &mul ($word); # ap[0]*ap[0] | ||
| 423 | &mov (&DWP($frame,"esp"),"eax"); # tp[0]= | ||
| 424 | &mov ($sbit,"edx"); | ||
| 425 | &shr ("edx",1); | ||
| 426 | &and ($sbit,1); | ||
| 427 | &inc ($j); | ||
| 428 | &set_label("sqr",16); | ||
| 429 | &mov ("eax",&DWP(0,$inp,$j,4)); # ap[j] | ||
| 430 | &mov ($carry,"edx"); | ||
| 431 | &mul ($word); # ap[j]*ap[0] | ||
| 432 | &add ("eax",$carry); | ||
| 433 | &lea ($j,&DWP(1,$j)); | ||
| 434 | &adc ("edx",0); | ||
| 435 | &lea ($carry,&DWP(0,$sbit,"eax",2)); | ||
| 436 | &shr ("eax",31); | ||
| 437 | &cmp ($j,$_num); | ||
| 438 | &mov ($sbit,"eax"); | ||
| 439 | &mov (&DWP($frame-4,"esp",$j,4),$carry); # tp[j]= | ||
| 440 | &jl (&label("sqr")); | ||
| 441 | |||
| 442 | &mov ("eax",&DWP(0,$inp,$j,4)); # ap[num-1] | ||
| 443 | &mov ($carry,"edx"); | ||
| 444 | &mul ($word); # ap[num-1]*ap[0] | ||
| 445 | &add ("eax",$carry); | ||
| 446 | &mov ($word,$_n0); | ||
| 447 | &adc ("edx",0); | ||
| 448 | &mov ($inp,$_np); | ||
| 449 | &lea ($carry,&DWP(0,$sbit,"eax",2)); | ||
| 450 | &imul ($word,&DWP($frame,"esp")); # n0*tp[0] | ||
| 451 | &shr ("eax",31); | ||
| 452 | &mov (&DWP($frame,"esp",$j,4),$carry); # tp[num-1]= | ||
| 453 | |||
| 454 | &lea ($carry,&DWP(0,"eax","edx",2)); | ||
| 455 | &mov ("eax",&DWP(0,$inp)); # np[0] | ||
| 456 | &shr ("edx",31); | ||
| 457 | &mov (&DWP($frame+4,"esp",$j,4),$carry); # tp[num]= | ||
| 458 | &mov (&DWP($frame+8,"esp",$j,4),"edx"); # tp[num+1]= | ||
| 459 | |||
| 460 | &mul ($word); # np[0]*m | ||
| 461 | &add ("eax",&DWP($frame,"esp")); # +=tp[0] | ||
| 462 | &mov ($num,$j); | ||
| 463 | &adc ("edx",0); | ||
| 464 | &mov ("eax",&DWP(4,$inp)); # np[1] | ||
| 465 | &mov ($j,1); | ||
| 466 | |||
| 467 | &set_label("3rdmadd",16); | ||
| 468 | &mov ($carry,"edx"); | ||
| 469 | &mul ($word); # np[j]*m | ||
| 470 | &add ($carry,&DWP($frame,"esp",$j,4)); # +=tp[j] | ||
| 471 | &adc ("edx",0); | ||
| 472 | &add ($carry,"eax"); | ||
| 473 | &mov ("eax",&DWP(4,$inp,$j,4)); # np[j+1] | ||
| 474 | &adc ("edx",0); | ||
| 475 | &mov (&DWP($frame-4,"esp",$j,4),$carry); # tp[j-1]= | ||
| 476 | |||
| 477 | &mov ($carry,"edx"); | ||
| 478 | &mul ($word); # np[j+1]*m | ||
| 479 | &add ($carry,&DWP($frame+4,"esp",$j,4)); # +=tp[j+1] | ||
| 480 | &lea ($j,&DWP(2,$j)); | ||
| 481 | &adc ("edx",0); | ||
| 482 | &add ($carry,"eax"); | ||
| 483 | &mov ("eax",&DWP(0,$inp,$j,4)); # np[j+2] | ||
| 484 | &adc ("edx",0); | ||
| 485 | &cmp ($j,$num); | ||
| 486 | &mov (&DWP($frame-8,"esp",$j,4),$carry); # tp[j]= | ||
| 487 | &jl (&label("3rdmadd")); | ||
| 488 | |||
| 489 | &mov ($carry,"edx"); | ||
| 490 | &mul ($word); # np[j]*m | ||
| 491 | &add ($carry,&DWP($frame,"esp",$num,4)); # +=tp[num-1] | ||
| 492 | &adc ("edx",0); | ||
| 493 | &add ($carry,"eax"); | ||
| 494 | &adc ("edx",0); | ||
| 495 | &mov (&DWP($frame-4,"esp",$num,4),$carry); # tp[num-2]= | ||
| 496 | |||
| 497 | &mov ($j,$_bp); # i | ||
| 498 | &xor ("eax","eax"); | ||
| 499 | &mov ($inp,$_ap); | ||
| 500 | &add ("edx",&DWP($frame+4,"esp",$num,4)); # carry+=tp[num] | ||
| 501 | &adc ("eax",&DWP($frame+8,"esp",$num,4)); # +=tp[num+1] | ||
| 502 | &mov (&DWP($frame,"esp",$num,4),"edx"); # tp[num-1]= | ||
| 503 | &cmp ($j,$num); | ||
| 504 | &mov (&DWP($frame+4,"esp",$num,4),"eax"); # tp[num]= | ||
| 505 | &je (&label("common_tail")); | ||
| 506 | |||
| 507 | &mov ($word,&DWP(4,$inp,$j,4)); # ap[i] | ||
| 508 | &lea ($j,&DWP(1,$j)); | ||
| 509 | &mov ("eax",$word); | ||
| 510 | &mov ($_bp,$j); # ++i | ||
| 511 | &mul ($word); # ap[i]*ap[i] | ||
| 512 | &add ("eax",&DWP($frame,"esp",$j,4)); # +=tp[i] | ||
| 513 | &adc ("edx",0); | ||
| 514 | &mov (&DWP($frame,"esp",$j,4),"eax"); # tp[i]= | ||
| 515 | &xor ($carry,$carry); | ||
| 516 | &cmp ($j,$num); | ||
| 517 | &lea ($j,&DWP(1,$j)); | ||
| 518 | &je (&label("sqrlast")); | ||
| 519 | |||
| 520 | &mov ($sbit,"edx"); # zaps $num | ||
| 521 | &shr ("edx",1); | ||
| 522 | &and ($sbit,1); | ||
| 523 | &set_label("sqradd",16); | ||
| 524 | &mov ("eax",&DWP(0,$inp,$j,4)); # ap[j] | ||
| 525 | &mov ($carry,"edx"); | ||
| 526 | &mul ($word); # ap[j]*ap[i] | ||
| 527 | &add ("eax",$carry); | ||
| 528 | &lea ($carry,&DWP(0,"eax","eax")); | ||
| 529 | &adc ("edx",0); | ||
| 530 | &shr ("eax",31); | ||
| 531 | &add ($carry,&DWP($frame,"esp",$j,4)); # +=tp[j] | ||
| 532 | &lea ($j,&DWP(1,$j)); | ||
| 533 | &adc ("eax",0); | ||
| 534 | &add ($carry,$sbit); | ||
| 535 | &adc ("eax",0); | ||
| 536 | &cmp ($j,$_num); | ||
| 537 | &mov (&DWP($frame-4,"esp",$j,4),$carry); # tp[j]= | ||
| 538 | &mov ($sbit,"eax"); | ||
| 539 | &jle (&label("sqradd")); | ||
| 540 | |||
| 541 | &mov ($carry,"edx"); | ||
| 542 | &lea ("edx",&DWP(0,$sbit,"edx",2)); | ||
| 543 | &shr ($carry,31); | ||
| 544 | &set_label("sqrlast"); | ||
| 545 | &mov ($word,$_n0); | ||
| 546 | &mov ($inp,$_np); | ||
| 547 | &imul ($word,&DWP($frame,"esp")); # n0*tp[0] | ||
| 548 | |||
| 549 | &add ("edx",&DWP($frame,"esp",$j,4)); # +=tp[num] | ||
| 550 | &mov ("eax",&DWP(0,$inp)); # np[0] | ||
| 551 | &adc ($carry,0); | ||
| 552 | &mov (&DWP($frame,"esp",$j,4),"edx"); # tp[num]= | ||
| 553 | &mov (&DWP($frame+4,"esp",$j,4),$carry); # tp[num+1]= | ||
| 554 | |||
| 555 | &mul ($word); # np[0]*m | ||
| 556 | &add ("eax",&DWP($frame,"esp")); # +=tp[0] | ||
| 557 | &lea ($num,&DWP(-1,$j)); | ||
| 558 | &adc ("edx",0); | ||
| 559 | &mov ($j,1); | ||
| 560 | &mov ("eax",&DWP(4,$inp)); # np[1] | ||
| 561 | |||
| 562 | &jmp (&label("3rdmadd")); | ||
| 563 | } | ||
| 564 | |||
| 565 | &set_label("common_tail",16); | ||
| 566 | &mov ($np,$_np); # load modulus pointer | ||
| 567 | &mov ($rp,$_rp); # load result pointer | ||
| 568 | &lea ($tp,&DWP($frame,"esp")); # [$ap and $bp are zapped] | ||
| 569 | |||
| 570 | &mov ("eax",&DWP(0,$tp)); # tp[0] | ||
| 571 | &mov ($j,$num); # j=num-1 | ||
| 572 | &xor ($i,$i); # i=0 and clear CF! | ||
| 573 | |||
| 574 | &set_label("sub",16); | ||
| 575 | &sbb ("eax",&DWP(0,$np,$i,4)); | ||
| 576 | &mov (&DWP(0,$rp,$i,4),"eax"); # rp[i]=tp[i]-np[i] | ||
| 577 | &dec ($j); # doesn't affect CF! | ||
| 578 | &mov ("eax",&DWP(4,$tp,$i,4)); # tp[i+1] | ||
| 579 | &lea ($i,&DWP(1,$i)); # i++ | ||
| 580 | &jge (&label("sub")); | ||
| 581 | |||
| 582 | &sbb ("eax",0); # handle upmost overflow bit | ||
| 583 | &and ($tp,"eax"); | ||
| 584 | ¬ ("eax"); | ||
| 585 | &mov ($np,$rp); | ||
| 586 | &and ($np,"eax"); | ||
| 587 | &or ($tp,$np); # tp=carry?tp:rp | ||
| 588 | |||
| 589 | &set_label("copy",16); # copy or in-place refresh | ||
| 590 | &mov ("eax",&DWP(0,$tp,$num,4)); | ||
| 591 | &mov (&DWP(0,$rp,$num,4),"eax"); # rp[i]=tp[i] | ||
| 592 | &mov (&DWP($frame,"esp",$num,4),$j); # zap temporary vector | ||
| 593 | &dec ($num); | ||
| 594 | &jge (&label("copy")); | ||
| 595 | |||
| 596 | &mov ("esp",$_sp); # pull saved stack pointer | ||
| 597 | &mov ("eax",1); | ||
| 598 | &set_label("just_leave"); | ||
| 599 | &function_end("bn_mul_mont"); | ||
| 600 | |||
| 601 | &asciz("Montgomery Multiplication for x86, CRYPTOGAMS by <appro\@openssl.org>"); | ||
| 602 | |||
| 603 | &asm_finish(); | ||
diff --git a/src/lib/libcrypto/bn/asm/pa-risc.s b/src/lib/libcrypto/bn/asm/pa-risc.s deleted file mode 100644 index 775130a191..0000000000 --- a/src/lib/libcrypto/bn/asm/pa-risc.s +++ /dev/null | |||
| @@ -1,710 +0,0 @@ | |||
| 1 | .SPACE $PRIVATE$ | ||
| 2 | .SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31 | ||
| 3 | .SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82 | ||
| 4 | .SPACE $TEXT$ | ||
| 5 | .SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44 | ||
| 6 | .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY | ||
| 7 | .IMPORT $global$,DATA | ||
| 8 | .IMPORT $$dyncall,MILLICODE | ||
| 9 | ; gcc_compiled.: | ||
| 10 | .SPACE $TEXT$ | ||
| 11 | .SUBSPA $CODE$ | ||
| 12 | |||
| 13 | .align 4 | ||
| 14 | .EXPORT bn_mul_add_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR | ||
| 15 | bn_mul_add_words | ||
| 16 | .PROC | ||
| 17 | .CALLINFO FRAME=0,CALLS,SAVE_RP | ||
| 18 | .ENTRY | ||
| 19 | stw %r2,-20(0,%r30) | ||
| 20 | ldi 0,%r28 | ||
| 21 | extru %r23,31,16,%r2 | ||
| 22 | stw %r2,-16(0,%r30) | ||
| 23 | extru %r23,15,16,%r23 | ||
| 24 | ldil L'65536,%r31 | ||
| 25 | fldws -16(0,%r30),%fr11R | ||
| 26 | stw %r23,-16(0,%r30) | ||
| 27 | ldo 12(%r25),%r29 | ||
| 28 | ldo 12(%r26),%r23 | ||
| 29 | fldws -16(0,%r30),%fr11L | ||
| 30 | L$0002 | ||
| 31 | ldw 0(0,%r25),%r19 | ||
| 32 | extru %r19,31,16,%r20 | ||
| 33 | stw %r20,-16(0,%r30) | ||
| 34 | extru %r19,15,16,%r19 | ||
| 35 | fldws -16(0,%r30),%fr22L | ||
| 36 | stw %r19,-16(0,%r30) | ||
| 37 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 38 | fldws -16(0,%r30),%fr22L | ||
| 39 | fstws %fr8R,-16(0,%r30) | ||
| 40 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 41 | ldw -16(0,%r30),%r2 | ||
| 42 | stw %r20,-16(0,%r30) | ||
| 43 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 44 | fldws -16(0,%r30),%fr22L | ||
| 45 | fstws %fr10R,-16(0,%r30) | ||
| 46 | copy %r2,%r22 | ||
| 47 | ldw -16(0,%r30),%r2 | ||
| 48 | fstws %fr9R,-16(0,%r30) | ||
| 49 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 50 | copy %r2,%r19 | ||
| 51 | ldw -16(0,%r30),%r2 | ||
| 52 | fstws %fr8R,-16(0,%r30) | ||
| 53 | copy %r2,%r20 | ||
| 54 | ldw -16(0,%r30),%r2 | ||
| 55 | addl %r2,%r19,%r21 | ||
| 56 | comclr,<<= %r19,%r21,0 | ||
| 57 | addl %r20,%r31,%r20 | ||
| 58 | L$0005 | ||
| 59 | extru %r21,15,16,%r19 | ||
| 60 | addl %r20,%r19,%r20 | ||
| 61 | zdep %r21,15,16,%r19 | ||
| 62 | addl %r22,%r19,%r22 | ||
| 63 | comclr,<<= %r19,%r22,0 | ||
| 64 | addi,tr 1,%r20,%r19 | ||
| 65 | copy %r20,%r19 | ||
| 66 | addl %r22,%r28,%r20 | ||
| 67 | comclr,<<= %r28,%r20,0 | ||
| 68 | addi 1,%r19,%r19 | ||
| 69 | ldw 0(0,%r26),%r28 | ||
| 70 | addl %r20,%r28,%r20 | ||
| 71 | comclr,<<= %r28,%r20,0 | ||
| 72 | addi,tr 1,%r19,%r28 | ||
| 73 | copy %r19,%r28 | ||
| 74 | addib,= -1,%r24,L$0003 | ||
| 75 | stw %r20,0(0,%r26) | ||
| 76 | ldw -8(0,%r29),%r19 | ||
| 77 | extru %r19,31,16,%r20 | ||
| 78 | stw %r20,-16(0,%r30) | ||
| 79 | extru %r19,15,16,%r19 | ||
| 80 | fldws -16(0,%r30),%fr22L | ||
| 81 | stw %r19,-16(0,%r30) | ||
| 82 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 83 | fldws -16(0,%r30),%fr22L | ||
| 84 | fstws %fr8R,-16(0,%r30) | ||
| 85 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 86 | ldw -16(0,%r30),%r2 | ||
| 87 | stw %r20,-16(0,%r30) | ||
| 88 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 89 | fldws -16(0,%r30),%fr22L | ||
| 90 | fstws %fr10R,-16(0,%r30) | ||
| 91 | copy %r2,%r22 | ||
| 92 | ldw -16(0,%r30),%r2 | ||
| 93 | fstws %fr9R,-16(0,%r30) | ||
| 94 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 95 | copy %r2,%r19 | ||
| 96 | ldw -16(0,%r30),%r2 | ||
| 97 | fstws %fr8R,-16(0,%r30) | ||
| 98 | copy %r2,%r20 | ||
| 99 | ldw -16(0,%r30),%r2 | ||
| 100 | addl %r2,%r19,%r21 | ||
| 101 | comclr,<<= %r19,%r21,0 | ||
| 102 | addl %r20,%r31,%r20 | ||
| 103 | L$0010 | ||
| 104 | extru %r21,15,16,%r19 | ||
| 105 | addl %r20,%r19,%r20 | ||
| 106 | zdep %r21,15,16,%r19 | ||
| 107 | addl %r22,%r19,%r22 | ||
| 108 | comclr,<<= %r19,%r22,0 | ||
| 109 | addi,tr 1,%r20,%r19 | ||
| 110 | copy %r20,%r19 | ||
| 111 | addl %r22,%r28,%r20 | ||
| 112 | comclr,<<= %r28,%r20,0 | ||
| 113 | addi 1,%r19,%r19 | ||
| 114 | ldw -8(0,%r23),%r28 | ||
| 115 | addl %r20,%r28,%r20 | ||
| 116 | comclr,<<= %r28,%r20,0 | ||
| 117 | addi,tr 1,%r19,%r28 | ||
| 118 | copy %r19,%r28 | ||
| 119 | addib,= -1,%r24,L$0003 | ||
| 120 | stw %r20,-8(0,%r23) | ||
| 121 | ldw -4(0,%r29),%r19 | ||
| 122 | extru %r19,31,16,%r20 | ||
| 123 | stw %r20,-16(0,%r30) | ||
| 124 | extru %r19,15,16,%r19 | ||
| 125 | fldws -16(0,%r30),%fr22L | ||
| 126 | stw %r19,-16(0,%r30) | ||
| 127 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 128 | fldws -16(0,%r30),%fr22L | ||
| 129 | fstws %fr8R,-16(0,%r30) | ||
| 130 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 131 | ldw -16(0,%r30),%r2 | ||
| 132 | stw %r20,-16(0,%r30) | ||
| 133 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 134 | fldws -16(0,%r30),%fr22L | ||
| 135 | fstws %fr10R,-16(0,%r30) | ||
| 136 | copy %r2,%r22 | ||
| 137 | ldw -16(0,%r30),%r2 | ||
| 138 | fstws %fr9R,-16(0,%r30) | ||
| 139 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 140 | copy %r2,%r19 | ||
| 141 | ldw -16(0,%r30),%r2 | ||
| 142 | fstws %fr8R,-16(0,%r30) | ||
| 143 | copy %r2,%r20 | ||
| 144 | ldw -16(0,%r30),%r2 | ||
| 145 | addl %r2,%r19,%r21 | ||
| 146 | comclr,<<= %r19,%r21,0 | ||
| 147 | addl %r20,%r31,%r20 | ||
| 148 | L$0015 | ||
| 149 | extru %r21,15,16,%r19 | ||
| 150 | addl %r20,%r19,%r20 | ||
| 151 | zdep %r21,15,16,%r19 | ||
| 152 | addl %r22,%r19,%r22 | ||
| 153 | comclr,<<= %r19,%r22,0 | ||
| 154 | addi,tr 1,%r20,%r19 | ||
| 155 | copy %r20,%r19 | ||
| 156 | addl %r22,%r28,%r20 | ||
| 157 | comclr,<<= %r28,%r20,0 | ||
| 158 | addi 1,%r19,%r19 | ||
| 159 | ldw -4(0,%r23),%r28 | ||
| 160 | addl %r20,%r28,%r20 | ||
| 161 | comclr,<<= %r28,%r20,0 | ||
| 162 | addi,tr 1,%r19,%r28 | ||
| 163 | copy %r19,%r28 | ||
| 164 | addib,= -1,%r24,L$0003 | ||
| 165 | stw %r20,-4(0,%r23) | ||
| 166 | ldw 0(0,%r29),%r19 | ||
| 167 | extru %r19,31,16,%r20 | ||
| 168 | stw %r20,-16(0,%r30) | ||
| 169 | extru %r19,15,16,%r19 | ||
| 170 | fldws -16(0,%r30),%fr22L | ||
| 171 | stw %r19,-16(0,%r30) | ||
| 172 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 173 | fldws -16(0,%r30),%fr22L | ||
| 174 | fstws %fr8R,-16(0,%r30) | ||
| 175 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 176 | ldw -16(0,%r30),%r2 | ||
| 177 | stw %r20,-16(0,%r30) | ||
| 178 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 179 | fldws -16(0,%r30),%fr22L | ||
| 180 | fstws %fr10R,-16(0,%r30) | ||
| 181 | copy %r2,%r22 | ||
| 182 | ldw -16(0,%r30),%r2 | ||
| 183 | fstws %fr9R,-16(0,%r30) | ||
| 184 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 185 | copy %r2,%r19 | ||
| 186 | ldw -16(0,%r30),%r2 | ||
| 187 | fstws %fr8R,-16(0,%r30) | ||
| 188 | copy %r2,%r20 | ||
| 189 | ldw -16(0,%r30),%r2 | ||
| 190 | addl %r2,%r19,%r21 | ||
| 191 | comclr,<<= %r19,%r21,0 | ||
| 192 | addl %r20,%r31,%r20 | ||
| 193 | L$0020 | ||
| 194 | extru %r21,15,16,%r19 | ||
| 195 | addl %r20,%r19,%r20 | ||
| 196 | zdep %r21,15,16,%r19 | ||
| 197 | addl %r22,%r19,%r22 | ||
| 198 | comclr,<<= %r19,%r22,0 | ||
| 199 | addi,tr 1,%r20,%r19 | ||
| 200 | copy %r20,%r19 | ||
| 201 | addl %r22,%r28,%r20 | ||
| 202 | comclr,<<= %r28,%r20,0 | ||
| 203 | addi 1,%r19,%r19 | ||
| 204 | ldw 0(0,%r23),%r28 | ||
| 205 | addl %r20,%r28,%r20 | ||
| 206 | comclr,<<= %r28,%r20,0 | ||
| 207 | addi,tr 1,%r19,%r28 | ||
| 208 | copy %r19,%r28 | ||
| 209 | addib,= -1,%r24,L$0003 | ||
| 210 | stw %r20,0(0,%r23) | ||
| 211 | ldo 16(%r29),%r29 | ||
| 212 | ldo 16(%r25),%r25 | ||
| 213 | ldo 16(%r23),%r23 | ||
| 214 | bl L$0002,0 | ||
| 215 | ldo 16(%r26),%r26 | ||
| 216 | L$0003 | ||
| 217 | ldw -20(0,%r30),%r2 | ||
| 218 | bv,n 0(%r2) | ||
| 219 | .EXIT | ||
| 220 | .PROCEND | ||
| 221 | .align 4 | ||
| 222 | .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR | ||
| 223 | bn_mul_words | ||
| 224 | .PROC | ||
| 225 | .CALLINFO FRAME=0,CALLS,SAVE_RP | ||
| 226 | .ENTRY | ||
| 227 | stw %r2,-20(0,%r30) | ||
| 228 | ldi 0,%r28 | ||
| 229 | extru %r23,31,16,%r2 | ||
| 230 | stw %r2,-16(0,%r30) | ||
| 231 | extru %r23,15,16,%r23 | ||
| 232 | ldil L'65536,%r31 | ||
| 233 | fldws -16(0,%r30),%fr11R | ||
| 234 | stw %r23,-16(0,%r30) | ||
| 235 | ldo 12(%r26),%r29 | ||
| 236 | ldo 12(%r25),%r23 | ||
| 237 | fldws -16(0,%r30),%fr11L | ||
| 238 | L$0026 | ||
| 239 | ldw 0(0,%r25),%r19 | ||
| 240 | extru %r19,31,16,%r20 | ||
| 241 | stw %r20,-16(0,%r30) | ||
| 242 | extru %r19,15,16,%r19 | ||
| 243 | fldws -16(0,%r30),%fr22L | ||
| 244 | stw %r19,-16(0,%r30) | ||
| 245 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 246 | fldws -16(0,%r30),%fr22L | ||
| 247 | fstws %fr8R,-16(0,%r30) | ||
| 248 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 249 | ldw -16(0,%r30),%r2 | ||
| 250 | stw %r20,-16(0,%r30) | ||
| 251 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 252 | fldws -16(0,%r30),%fr22L | ||
| 253 | fstws %fr10R,-16(0,%r30) | ||
| 254 | copy %r2,%r22 | ||
| 255 | ldw -16(0,%r30),%r2 | ||
| 256 | fstws %fr9R,-16(0,%r30) | ||
| 257 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 258 | copy %r2,%r19 | ||
| 259 | ldw -16(0,%r30),%r2 | ||
| 260 | fstws %fr8R,-16(0,%r30) | ||
| 261 | copy %r2,%r20 | ||
| 262 | ldw -16(0,%r30),%r2 | ||
| 263 | addl %r2,%r19,%r21 | ||
| 264 | comclr,<<= %r19,%r21,0 | ||
| 265 | addl %r20,%r31,%r20 | ||
| 266 | L$0029 | ||
| 267 | extru %r21,15,16,%r19 | ||
| 268 | addl %r20,%r19,%r20 | ||
| 269 | zdep %r21,15,16,%r19 | ||
| 270 | addl %r22,%r19,%r22 | ||
| 271 | comclr,<<= %r19,%r22,0 | ||
| 272 | addi,tr 1,%r20,%r19 | ||
| 273 | copy %r20,%r19 | ||
| 274 | addl %r22,%r28,%r20 | ||
| 275 | comclr,<<= %r28,%r20,0 | ||
| 276 | addi,tr 1,%r19,%r28 | ||
| 277 | copy %r19,%r28 | ||
| 278 | addib,= -1,%r24,L$0027 | ||
| 279 | stw %r20,0(0,%r26) | ||
| 280 | ldw -8(0,%r23),%r19 | ||
| 281 | extru %r19,31,16,%r20 | ||
| 282 | stw %r20,-16(0,%r30) | ||
| 283 | extru %r19,15,16,%r19 | ||
| 284 | fldws -16(0,%r30),%fr22L | ||
| 285 | stw %r19,-16(0,%r30) | ||
| 286 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 287 | fldws -16(0,%r30),%fr22L | ||
| 288 | fstws %fr8R,-16(0,%r30) | ||
| 289 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 290 | ldw -16(0,%r30),%r2 | ||
| 291 | stw %r20,-16(0,%r30) | ||
| 292 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 293 | fldws -16(0,%r30),%fr22L | ||
| 294 | fstws %fr10R,-16(0,%r30) | ||
| 295 | copy %r2,%r22 | ||
| 296 | ldw -16(0,%r30),%r2 | ||
| 297 | fstws %fr9R,-16(0,%r30) | ||
| 298 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 299 | copy %r2,%r19 | ||
| 300 | ldw -16(0,%r30),%r2 | ||
| 301 | fstws %fr8R,-16(0,%r30) | ||
| 302 | copy %r2,%r20 | ||
| 303 | ldw -16(0,%r30),%r2 | ||
| 304 | addl %r2,%r19,%r21 | ||
| 305 | comclr,<<= %r19,%r21,0 | ||
| 306 | addl %r20,%r31,%r20 | ||
| 307 | L$0033 | ||
| 308 | extru %r21,15,16,%r19 | ||
| 309 | addl %r20,%r19,%r20 | ||
| 310 | zdep %r21,15,16,%r19 | ||
| 311 | addl %r22,%r19,%r22 | ||
| 312 | comclr,<<= %r19,%r22,0 | ||
| 313 | addi,tr 1,%r20,%r19 | ||
| 314 | copy %r20,%r19 | ||
| 315 | addl %r22,%r28,%r20 | ||
| 316 | comclr,<<= %r28,%r20,0 | ||
| 317 | addi,tr 1,%r19,%r28 | ||
| 318 | copy %r19,%r28 | ||
| 319 | addib,= -1,%r24,L$0027 | ||
| 320 | stw %r20,-8(0,%r29) | ||
| 321 | ldw -4(0,%r23),%r19 | ||
| 322 | extru %r19,31,16,%r20 | ||
| 323 | stw %r20,-16(0,%r30) | ||
| 324 | extru %r19,15,16,%r19 | ||
| 325 | fldws -16(0,%r30),%fr22L | ||
| 326 | stw %r19,-16(0,%r30) | ||
| 327 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 328 | fldws -16(0,%r30),%fr22L | ||
| 329 | fstws %fr8R,-16(0,%r30) | ||
| 330 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 331 | ldw -16(0,%r30),%r2 | ||
| 332 | stw %r20,-16(0,%r30) | ||
| 333 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 334 | fldws -16(0,%r30),%fr22L | ||
| 335 | fstws %fr10R,-16(0,%r30) | ||
| 336 | copy %r2,%r22 | ||
| 337 | ldw -16(0,%r30),%r2 | ||
| 338 | fstws %fr9R,-16(0,%r30) | ||
| 339 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 340 | copy %r2,%r19 | ||
| 341 | ldw -16(0,%r30),%r2 | ||
| 342 | fstws %fr8R,-16(0,%r30) | ||
| 343 | copy %r2,%r20 | ||
| 344 | ldw -16(0,%r30),%r2 | ||
| 345 | addl %r2,%r19,%r21 | ||
| 346 | comclr,<<= %r19,%r21,0 | ||
| 347 | addl %r20,%r31,%r20 | ||
| 348 | L$0037 | ||
| 349 | extru %r21,15,16,%r19 | ||
| 350 | addl %r20,%r19,%r20 | ||
| 351 | zdep %r21,15,16,%r19 | ||
| 352 | addl %r22,%r19,%r22 | ||
| 353 | comclr,<<= %r19,%r22,0 | ||
| 354 | addi,tr 1,%r20,%r19 | ||
| 355 | copy %r20,%r19 | ||
| 356 | addl %r22,%r28,%r20 | ||
| 357 | comclr,<<= %r28,%r20,0 | ||
| 358 | addi,tr 1,%r19,%r28 | ||
| 359 | copy %r19,%r28 | ||
| 360 | addib,= -1,%r24,L$0027 | ||
| 361 | stw %r20,-4(0,%r29) | ||
| 362 | ldw 0(0,%r23),%r19 | ||
| 363 | extru %r19,31,16,%r20 | ||
| 364 | stw %r20,-16(0,%r30) | ||
| 365 | extru %r19,15,16,%r19 | ||
| 366 | fldws -16(0,%r30),%fr22L | ||
| 367 | stw %r19,-16(0,%r30) | ||
| 368 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 369 | fldws -16(0,%r30),%fr22L | ||
| 370 | fstws %fr8R,-16(0,%r30) | ||
| 371 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 372 | ldw -16(0,%r30),%r2 | ||
| 373 | stw %r20,-16(0,%r30) | ||
| 374 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 375 | fldws -16(0,%r30),%fr22L | ||
| 376 | fstws %fr10R,-16(0,%r30) | ||
| 377 | copy %r2,%r22 | ||
| 378 | ldw -16(0,%r30),%r2 | ||
| 379 | fstws %fr9R,-16(0,%r30) | ||
| 380 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 381 | copy %r2,%r19 | ||
| 382 | ldw -16(0,%r30),%r2 | ||
| 383 | fstws %fr8R,-16(0,%r30) | ||
| 384 | copy %r2,%r20 | ||
| 385 | ldw -16(0,%r30),%r2 | ||
| 386 | addl %r2,%r19,%r21 | ||
| 387 | comclr,<<= %r19,%r21,0 | ||
| 388 | addl %r20,%r31,%r20 | ||
| 389 | L$0041 | ||
| 390 | extru %r21,15,16,%r19 | ||
| 391 | addl %r20,%r19,%r20 | ||
| 392 | zdep %r21,15,16,%r19 | ||
| 393 | addl %r22,%r19,%r22 | ||
| 394 | comclr,<<= %r19,%r22,0 | ||
| 395 | addi,tr 1,%r20,%r19 | ||
| 396 | copy %r20,%r19 | ||
| 397 | addl %r22,%r28,%r20 | ||
| 398 | comclr,<<= %r28,%r20,0 | ||
| 399 | addi,tr 1,%r19,%r28 | ||
| 400 | copy %r19,%r28 | ||
| 401 | addib,= -1,%r24,L$0027 | ||
| 402 | stw %r20,0(0,%r29) | ||
| 403 | ldo 16(%r23),%r23 | ||
| 404 | ldo 16(%r25),%r25 | ||
| 405 | ldo 16(%r29),%r29 | ||
| 406 | bl L$0026,0 | ||
| 407 | ldo 16(%r26),%r26 | ||
| 408 | L$0027 | ||
| 409 | ldw -20(0,%r30),%r2 | ||
| 410 | bv,n 0(%r2) | ||
| 411 | .EXIT | ||
| 412 | .PROCEND | ||
| 413 | .align 4 | ||
| 414 | .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR | ||
| 415 | bn_sqr_words | ||
| 416 | .PROC | ||
| 417 | .CALLINFO FRAME=0,NO_CALLS | ||
| 418 | .ENTRY | ||
| 419 | ldo 28(%r26),%r23 | ||
| 420 | ldo 12(%r25),%r28 | ||
| 421 | L$0046 | ||
| 422 | ldw 0(0,%r25),%r21 | ||
| 423 | extru %r21,31,16,%r22 | ||
| 424 | stw %r22,-16(0,%r30) | ||
| 425 | extru %r21,15,16,%r21 | ||
| 426 | fldws -16(0,%r30),%fr10L | ||
| 427 | stw %r21,-16(0,%r30) | ||
| 428 | fldws -16(0,%r30),%fr10R | ||
| 429 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 430 | fstws %fr8R,-16(0,%r30) | ||
| 431 | ldw -16(0,%r30),%r29 | ||
| 432 | stw %r22,-16(0,%r30) | ||
| 433 | fldws -16(0,%r30),%fr10R | ||
| 434 | stw %r21,-16(0,%r30) | ||
| 435 | copy %r29,%r19 | ||
| 436 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 437 | fldws -16(0,%r30),%fr10L | ||
| 438 | stw %r21,-16(0,%r30) | ||
| 439 | fldws -16(0,%r30),%fr10R | ||
| 440 | fstws %fr8R,-16(0,%r30) | ||
| 441 | extru %r19,16,17,%r20 | ||
| 442 | zdep %r19,14,15,%r19 | ||
| 443 | ldw -16(0,%r30),%r29 | ||
| 444 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 445 | addl %r29,%r19,%r22 | ||
| 446 | stw %r22,0(0,%r26) | ||
| 447 | fstws %fr9R,-16(0,%r30) | ||
| 448 | ldw -16(0,%r30),%r29 | ||
| 449 | addl %r29,%r20,%r21 | ||
| 450 | comclr,<<= %r19,%r22,0 | ||
| 451 | addi 1,%r21,%r21 | ||
| 452 | addib,= -1,%r24,L$0057 | ||
| 453 | stw %r21,-24(0,%r23) | ||
| 454 | ldw -8(0,%r28),%r21 | ||
| 455 | extru %r21,31,16,%r22 | ||
| 456 | stw %r22,-16(0,%r30) | ||
| 457 | extru %r21,15,16,%r21 | ||
| 458 | fldws -16(0,%r30),%fr10L | ||
| 459 | stw %r21,-16(0,%r30) | ||
| 460 | fldws -16(0,%r30),%fr10R | ||
| 461 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 462 | fstws %fr8R,-16(0,%r30) | ||
| 463 | ldw -16(0,%r30),%r29 | ||
| 464 | stw %r22,-16(0,%r30) | ||
| 465 | fldws -16(0,%r30),%fr10R | ||
| 466 | stw %r21,-16(0,%r30) | ||
| 467 | copy %r29,%r19 | ||
| 468 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 469 | fldws -16(0,%r30),%fr10L | ||
| 470 | stw %r21,-16(0,%r30) | ||
| 471 | fldws -16(0,%r30),%fr10R | ||
| 472 | fstws %fr8R,-16(0,%r30) | ||
| 473 | extru %r19,16,17,%r20 | ||
| 474 | zdep %r19,14,15,%r19 | ||
| 475 | ldw -16(0,%r30),%r29 | ||
| 476 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 477 | addl %r29,%r19,%r22 | ||
| 478 | stw %r22,-20(0,%r23) | ||
| 479 | fstws %fr9R,-16(0,%r30) | ||
| 480 | ldw -16(0,%r30),%r29 | ||
| 481 | addl %r29,%r20,%r21 | ||
| 482 | comclr,<<= %r19,%r22,0 | ||
| 483 | addi 1,%r21,%r21 | ||
| 484 | addib,= -1,%r24,L$0057 | ||
| 485 | stw %r21,-16(0,%r23) | ||
| 486 | ldw -4(0,%r28),%r21 | ||
| 487 | extru %r21,31,16,%r22 | ||
| 488 | stw %r22,-16(0,%r30) | ||
| 489 | extru %r21,15,16,%r21 | ||
| 490 | fldws -16(0,%r30),%fr10L | ||
| 491 | stw %r21,-16(0,%r30) | ||
| 492 | fldws -16(0,%r30),%fr10R | ||
| 493 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 494 | fstws %fr8R,-16(0,%r30) | ||
| 495 | ldw -16(0,%r30),%r29 | ||
| 496 | stw %r22,-16(0,%r30) | ||
| 497 | fldws -16(0,%r30),%fr10R | ||
| 498 | stw %r21,-16(0,%r30) | ||
| 499 | copy %r29,%r19 | ||
| 500 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 501 | fldws -16(0,%r30),%fr10L | ||
| 502 | stw %r21,-16(0,%r30) | ||
| 503 | fldws -16(0,%r30),%fr10R | ||
| 504 | fstws %fr8R,-16(0,%r30) | ||
| 505 | extru %r19,16,17,%r20 | ||
| 506 | zdep %r19,14,15,%r19 | ||
| 507 | ldw -16(0,%r30),%r29 | ||
| 508 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 509 | addl %r29,%r19,%r22 | ||
| 510 | stw %r22,-12(0,%r23) | ||
| 511 | fstws %fr9R,-16(0,%r30) | ||
| 512 | ldw -16(0,%r30),%r29 | ||
| 513 | addl %r29,%r20,%r21 | ||
| 514 | comclr,<<= %r19,%r22,0 | ||
| 515 | addi 1,%r21,%r21 | ||
| 516 | addib,= -1,%r24,L$0057 | ||
| 517 | stw %r21,-8(0,%r23) | ||
| 518 | ldw 0(0,%r28),%r21 | ||
| 519 | extru %r21,31,16,%r22 | ||
| 520 | stw %r22,-16(0,%r30) | ||
| 521 | extru %r21,15,16,%r21 | ||
| 522 | fldws -16(0,%r30),%fr10L | ||
| 523 | stw %r21,-16(0,%r30) | ||
| 524 | fldws -16(0,%r30),%fr10R | ||
| 525 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 526 | fstws %fr8R,-16(0,%r30) | ||
| 527 | ldw -16(0,%r30),%r29 | ||
| 528 | stw %r22,-16(0,%r30) | ||
| 529 | fldws -16(0,%r30),%fr10R | ||
| 530 | stw %r21,-16(0,%r30) | ||
| 531 | copy %r29,%r19 | ||
| 532 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 533 | fldws -16(0,%r30),%fr10L | ||
| 534 | stw %r21,-16(0,%r30) | ||
| 535 | fldws -16(0,%r30),%fr10R | ||
| 536 | fstws %fr8R,-16(0,%r30) | ||
| 537 | extru %r19,16,17,%r20 | ||
| 538 | zdep %r19,14,15,%r19 | ||
| 539 | ldw -16(0,%r30),%r29 | ||
| 540 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 541 | addl %r29,%r19,%r22 | ||
| 542 | stw %r22,-4(0,%r23) | ||
| 543 | fstws %fr9R,-16(0,%r30) | ||
| 544 | ldw -16(0,%r30),%r29 | ||
| 545 | addl %r29,%r20,%r21 | ||
| 546 | comclr,<<= %r19,%r22,0 | ||
| 547 | addi 1,%r21,%r21 | ||
| 548 | addib,= -1,%r24,L$0057 | ||
| 549 | stw %r21,0(0,%r23) | ||
| 550 | ldo 16(%r28),%r28 | ||
| 551 | ldo 16(%r25),%r25 | ||
| 552 | ldo 32(%r23),%r23 | ||
| 553 | bl L$0046,0 | ||
| 554 | ldo 32(%r26),%r26 | ||
| 555 | L$0057 | ||
| 556 | bv,n 0(%r2) | ||
| 557 | .EXIT | ||
| 558 | .PROCEND | ||
| 559 | .IMPORT BN_num_bits_word,CODE | ||
| 560 | .IMPORT fprintf,CODE | ||
| 561 | .IMPORT __iob,DATA | ||
| 562 | .SPACE $TEXT$ | ||
| 563 | .SUBSPA $LIT$ | ||
| 564 | |||
| 565 | .align 4 | ||
| 566 | L$C0000 | ||
| 567 | .STRING "Division would overflow\x0a\x00" | ||
| 568 | .IMPORT abort,CODE | ||
| 569 | .SPACE $TEXT$ | ||
| 570 | .SUBSPA $CODE$ | ||
| 571 | |||
| 572 | .align 4 | ||
| 573 | .EXPORT bn_div64,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR | ||
| 574 | bn_div64 | ||
| 575 | .PROC | ||
| 576 | .CALLINFO FRAME=128,CALLS,SAVE_RP,ENTRY_GR=8 | ||
| 577 | .ENTRY | ||
| 578 | stw %r2,-20(0,%r30) | ||
| 579 | stwm %r8,128(0,%r30) | ||
| 580 | stw %r7,-124(0,%r30) | ||
| 581 | stw %r4,-112(0,%r30) | ||
| 582 | stw %r3,-108(0,%r30) | ||
| 583 | copy %r26,%r3 | ||
| 584 | copy %r25,%r4 | ||
| 585 | stw %r6,-120(0,%r30) | ||
| 586 | ldi 0,%r7 | ||
| 587 | stw %r5,-116(0,%r30) | ||
| 588 | movb,<> %r24,%r5,L$0059 | ||
| 589 | ldi 2,%r6 | ||
| 590 | bl L$0076,0 | ||
| 591 | ldi -1,%r28 | ||
| 592 | L$0059 | ||
| 593 | .CALL ARGW0=GR | ||
| 594 | bl BN_num_bits_word,%r2 | ||
| 595 | copy %r5,%r26 | ||
| 596 | ldi 32,%r19 | ||
| 597 | comb,= %r19,%r28,L$0060 | ||
| 598 | subi 31,%r28,%r19 | ||
| 599 | mtsar %r19 | ||
| 600 | zvdepi 1,32,%r19 | ||
| 601 | comb,>>= %r19,%r3,L$0060 | ||
| 602 | addil LR'__iob-$global$+32,%r27 | ||
| 603 | ldo RR'__iob-$global$+32(%r1),%r26 | ||
| 604 | ldil LR'L$C0000,%r25 | ||
| 605 | .CALL ARGW0=GR,ARGW1=GR | ||
| 606 | bl fprintf,%r2 | ||
| 607 | ldo RR'L$C0000(%r25),%r25 | ||
| 608 | .CALL | ||
| 609 | bl abort,%r2 | ||
| 610 | nop | ||
| 611 | L$0060 | ||
| 612 | comb,>> %r5,%r3,L$0061 | ||
| 613 | subi 32,%r28,%r28 | ||
| 614 | sub %r3,%r5,%r3 | ||
| 615 | L$0061 | ||
| 616 | comib,= 0,%r28,L$0062 | ||
| 617 | subi 31,%r28,%r19 | ||
| 618 | mtsar %r19 | ||
| 619 | zvdep %r5,32,%r5 | ||
| 620 | zvdep %r3,32,%r21 | ||
| 621 | subi 32,%r28,%r20 | ||
| 622 | mtsar %r20 | ||
| 623 | vshd 0,%r4,%r20 | ||
| 624 | or %r21,%r20,%r3 | ||
| 625 | mtsar %r19 | ||
| 626 | zvdep %r4,32,%r4 | ||
| 627 | L$0062 | ||
| 628 | extru %r5,15,16,%r23 | ||
| 629 | extru %r5,31,16,%r28 | ||
| 630 | L$0063 | ||
| 631 | extru %r3,15,16,%r19 | ||
| 632 | comb,<> %r23,%r19,L$0066 | ||
| 633 | copy %r3,%r26 | ||
| 634 | bl L$0067,0 | ||
| 635 | zdepi -1,31,16,%r29 | ||
| 636 | L$0066 | ||
| 637 | .IMPORT $$divU,MILLICODE | ||
| 638 | bl $$divU,%r31 | ||
| 639 | copy %r23,%r25 | ||
| 640 | L$0067 | ||
| 641 | stw %r29,-16(0,%r30) | ||
| 642 | fldws -16(0,%r30),%fr10L | ||
| 643 | stw %r28,-16(0,%r30) | ||
| 644 | fldws -16(0,%r30),%fr10R | ||
| 645 | stw %r23,-16(0,%r30) | ||
| 646 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 647 | fldws -16(0,%r30),%fr10R | ||
| 648 | fstws %fr8R,-16(0,%r30) | ||
| 649 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 650 | ldw -16(0,%r30),%r8 | ||
| 651 | fstws %fr9R,-16(0,%r30) | ||
| 652 | copy %r8,%r22 | ||
| 653 | ldw -16(0,%r30),%r8 | ||
| 654 | extru %r4,15,16,%r24 | ||
| 655 | copy %r8,%r21 | ||
| 656 | L$0068 | ||
| 657 | sub %r3,%r21,%r20 | ||
| 658 | copy %r20,%r19 | ||
| 659 | depi 0,31,16,%r19 | ||
| 660 | comib,<> 0,%r19,L$0069 | ||
| 661 | zdep %r20,15,16,%r19 | ||
| 662 | addl %r19,%r24,%r19 | ||
| 663 | comb,>>= %r19,%r22,L$0069 | ||
| 664 | sub %r22,%r28,%r22 | ||
| 665 | sub %r21,%r23,%r21 | ||
| 666 | bl L$0068,0 | ||
| 667 | ldo -1(%r29),%r29 | ||
| 668 | L$0069 | ||
| 669 | stw %r29,-16(0,%r30) | ||
| 670 | fldws -16(0,%r30),%fr10L | ||
| 671 | stw %r28,-16(0,%r30) | ||
| 672 | fldws -16(0,%r30),%fr10R | ||
| 673 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 674 | fstws %fr8R,-16(0,%r30) | ||
| 675 | ldw -16(0,%r30),%r8 | ||
| 676 | stw %r23,-16(0,%r30) | ||
| 677 | fldws -16(0,%r30),%fr10R | ||
| 678 | copy %r8,%r19 | ||
| 679 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 680 | fstws %fr8R,-16(0,%r30) | ||
| 681 | extru %r19,15,16,%r20 | ||
| 682 | ldw -16(0,%r30),%r8 | ||
| 683 | zdep %r19,15,16,%r19 | ||
| 684 | addl %r8,%r20,%r20 | ||
| 685 | comclr,<<= %r19,%r4,0 | ||
| 686 | addi 1,%r20,%r20 | ||
| 687 | comb,<<= %r20,%r3,L$0074 | ||
| 688 | sub %r4,%r19,%r4 | ||
| 689 | addl %r3,%r5,%r3 | ||
| 690 | ldo -1(%r29),%r29 | ||
| 691 | L$0074 | ||
| 692 | addib,= -1,%r6,L$0064 | ||
| 693 | sub %r3,%r20,%r3 | ||
| 694 | zdep %r29,15,16,%r7 | ||
| 695 | shd %r3,%r4,16,%r3 | ||
| 696 | bl L$0063,0 | ||
| 697 | zdep %r4,15,16,%r4 | ||
| 698 | L$0064 | ||
| 699 | or %r7,%r29,%r28 | ||
| 700 | L$0076 | ||
| 701 | ldw -148(0,%r30),%r2 | ||
| 702 | ldw -124(0,%r30),%r7 | ||
| 703 | ldw -120(0,%r30),%r6 | ||
| 704 | ldw -116(0,%r30),%r5 | ||
| 705 | ldw -112(0,%r30),%r4 | ||
| 706 | ldw -108(0,%r30),%r3 | ||
| 707 | bv 0(%r2) | ||
| 708 | ldwm -128(0,%r30),%r8 | ||
| 709 | .EXIT | ||
| 710 | .PROCEND | ||
diff --git a/src/lib/libcrypto/bn/asm/r3000.s b/src/lib/libcrypto/bn/asm/r3000.s deleted file mode 100644 index e95269afa3..0000000000 --- a/src/lib/libcrypto/bn/asm/r3000.s +++ /dev/null | |||
| @@ -1,646 +0,0 @@ | |||
| 1 | .file 1 "../bn_mulw.c" | ||
| 2 | .set nobopt | ||
| 3 | .option pic2 | ||
| 4 | |||
| 5 | # GNU C 2.6.3 [AL 1.1, MM 40] SGI running IRIX 5.0 compiled by GNU C | ||
| 6 | |||
| 7 | # Cc1 defaults: | ||
| 8 | # -mabicalls | ||
| 9 | |||
| 10 | # Cc1 arguments (-G value = 0, Cpu = 3000, ISA = 1): | ||
| 11 | # -quiet -dumpbase -O2 -o | ||
| 12 | |||
| 13 | gcc2_compiled.: | ||
| 14 | __gnu_compiled_c: | ||
| 15 | .rdata | ||
| 16 | |||
| 17 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 18 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x39,0x20 | ||
| 19 | .byte 0x24,0x0 | ||
| 20 | |||
| 21 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 22 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x33,0x34,0x20 | ||
| 23 | .byte 0x24,0x0 | ||
| 24 | |||
| 25 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 26 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x35,0x20,0x24 | ||
| 27 | .byte 0x0 | ||
| 28 | |||
| 29 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 30 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24 | ||
| 31 | .byte 0x0 | ||
| 32 | |||
| 33 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 34 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x33,0x20 | ||
| 35 | .byte 0x24,0x0 | ||
| 36 | |||
| 37 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 38 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x37,0x38,0x20 | ||
| 39 | .byte 0x24,0x0 | ||
| 40 | |||
| 41 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 42 | .byte 0x6e,0x3a,0x20,0x33,0x2e,0x37,0x30,0x20 | ||
| 43 | .byte 0x24,0x0 | ||
| 44 | |||
| 45 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 46 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x20,0x24 | ||
| 47 | .byte 0x0 | ||
| 48 | |||
| 49 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 50 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x20,0x24 | ||
| 51 | .byte 0x0 | ||
| 52 | |||
| 53 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 54 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24 | ||
| 55 | .byte 0x0 | ||
| 56 | .text | ||
| 57 | .align 2 | ||
| 58 | .globl bn_mul_add_words | ||
| 59 | .ent bn_mul_add_words | ||
| 60 | bn_mul_add_words: | ||
| 61 | .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0 | ||
| 62 | .mask 0x00000000,0 | ||
| 63 | .fmask 0x00000000,0 | ||
| 64 | .set noreorder | ||
| 65 | .cpload $25 | ||
| 66 | .set reorder | ||
| 67 | move $12,$4 | ||
| 68 | move $14,$5 | ||
| 69 | move $9,$6 | ||
| 70 | move $13,$7 | ||
| 71 | move $8,$0 | ||
| 72 | addu $10,$12,12 | ||
| 73 | addu $11,$14,12 | ||
| 74 | $L2: | ||
| 75 | lw $6,0($14) | ||
| 76 | #nop | ||
| 77 | multu $13,$6 | ||
| 78 | mfhi $6 | ||
| 79 | mflo $7 | ||
| 80 | #nop | ||
| 81 | move $5,$8 | ||
| 82 | move $4,$0 | ||
| 83 | lw $3,0($12) | ||
| 84 | addu $9,$9,-1 | ||
| 85 | move $2,$0 | ||
| 86 | addu $7,$7,$3 | ||
| 87 | sltu $8,$7,$3 | ||
| 88 | addu $6,$6,$2 | ||
| 89 | addu $6,$6,$8 | ||
| 90 | addu $7,$7,$5 | ||
| 91 | sltu $2,$7,$5 | ||
| 92 | addu $6,$6,$4 | ||
| 93 | addu $6,$6,$2 | ||
| 94 | srl $3,$6,0 | ||
| 95 | move $2,$0 | ||
| 96 | move $8,$3 | ||
| 97 | .set noreorder | ||
| 98 | .set nomacro | ||
| 99 | beq $9,$0,$L3 | ||
| 100 | sw $7,0($12) | ||
| 101 | .set macro | ||
| 102 | .set reorder | ||
| 103 | |||
| 104 | lw $6,-8($11) | ||
| 105 | #nop | ||
| 106 | multu $13,$6 | ||
| 107 | mfhi $6 | ||
| 108 | mflo $7 | ||
| 109 | #nop | ||
| 110 | move $5,$8 | ||
| 111 | move $4,$0 | ||
| 112 | lw $3,-8($10) | ||
| 113 | addu $9,$9,-1 | ||
| 114 | move $2,$0 | ||
| 115 | addu $7,$7,$3 | ||
| 116 | sltu $8,$7,$3 | ||
| 117 | addu $6,$6,$2 | ||
| 118 | addu $6,$6,$8 | ||
| 119 | addu $7,$7,$5 | ||
| 120 | sltu $2,$7,$5 | ||
| 121 | addu $6,$6,$4 | ||
| 122 | addu $6,$6,$2 | ||
| 123 | srl $3,$6,0 | ||
| 124 | move $2,$0 | ||
| 125 | move $8,$3 | ||
| 126 | .set noreorder | ||
| 127 | .set nomacro | ||
| 128 | beq $9,$0,$L3 | ||
| 129 | sw $7,-8($10) | ||
| 130 | .set macro | ||
| 131 | .set reorder | ||
| 132 | |||
| 133 | lw $6,-4($11) | ||
| 134 | #nop | ||
| 135 | multu $13,$6 | ||
| 136 | mfhi $6 | ||
| 137 | mflo $7 | ||
| 138 | #nop | ||
| 139 | move $5,$8 | ||
| 140 | move $4,$0 | ||
| 141 | lw $3,-4($10) | ||
| 142 | addu $9,$9,-1 | ||
| 143 | move $2,$0 | ||
| 144 | addu $7,$7,$3 | ||
| 145 | sltu $8,$7,$3 | ||
| 146 | addu $6,$6,$2 | ||
| 147 | addu $6,$6,$8 | ||
| 148 | addu $7,$7,$5 | ||
| 149 | sltu $2,$7,$5 | ||
| 150 | addu $6,$6,$4 | ||
| 151 | addu $6,$6,$2 | ||
| 152 | srl $3,$6,0 | ||
| 153 | move $2,$0 | ||
| 154 | move $8,$3 | ||
| 155 | .set noreorder | ||
| 156 | .set nomacro | ||
| 157 | beq $9,$0,$L3 | ||
| 158 | sw $7,-4($10) | ||
| 159 | .set macro | ||
| 160 | .set reorder | ||
| 161 | |||
| 162 | lw $6,0($11) | ||
| 163 | #nop | ||
| 164 | multu $13,$6 | ||
| 165 | mfhi $6 | ||
| 166 | mflo $7 | ||
| 167 | #nop | ||
| 168 | move $5,$8 | ||
| 169 | move $4,$0 | ||
| 170 | lw $3,0($10) | ||
| 171 | addu $9,$9,-1 | ||
| 172 | move $2,$0 | ||
| 173 | addu $7,$7,$3 | ||
| 174 | sltu $8,$7,$3 | ||
| 175 | addu $6,$6,$2 | ||
| 176 | addu $6,$6,$8 | ||
| 177 | addu $7,$7,$5 | ||
| 178 | sltu $2,$7,$5 | ||
| 179 | addu $6,$6,$4 | ||
| 180 | addu $6,$6,$2 | ||
| 181 | srl $3,$6,0 | ||
| 182 | move $2,$0 | ||
| 183 | move $8,$3 | ||
| 184 | .set noreorder | ||
| 185 | .set nomacro | ||
| 186 | beq $9,$0,$L3 | ||
| 187 | sw $7,0($10) | ||
| 188 | .set macro | ||
| 189 | .set reorder | ||
| 190 | |||
| 191 | addu $11,$11,16 | ||
| 192 | addu $14,$14,16 | ||
| 193 | addu $10,$10,16 | ||
| 194 | .set noreorder | ||
| 195 | .set nomacro | ||
| 196 | j $L2 | ||
| 197 | addu $12,$12,16 | ||
| 198 | .set macro | ||
| 199 | .set reorder | ||
| 200 | |||
| 201 | $L3: | ||
| 202 | .set noreorder | ||
| 203 | .set nomacro | ||
| 204 | j $31 | ||
| 205 | move $2,$8 | ||
| 206 | .set macro | ||
| 207 | .set reorder | ||
| 208 | |||
| 209 | .end bn_mul_add_words | ||
| 210 | .align 2 | ||
| 211 | .globl bn_mul_words | ||
| 212 | .ent bn_mul_words | ||
| 213 | bn_mul_words: | ||
| 214 | .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0 | ||
| 215 | .mask 0x00000000,0 | ||
| 216 | .fmask 0x00000000,0 | ||
| 217 | .set noreorder | ||
| 218 | .cpload $25 | ||
| 219 | .set reorder | ||
| 220 | move $11,$4 | ||
| 221 | move $12,$5 | ||
| 222 | move $8,$6 | ||
| 223 | move $6,$0 | ||
| 224 | addu $10,$11,12 | ||
| 225 | addu $9,$12,12 | ||
| 226 | $L10: | ||
| 227 | lw $4,0($12) | ||
| 228 | #nop | ||
| 229 | multu $7,$4 | ||
| 230 | mfhi $4 | ||
| 231 | mflo $5 | ||
| 232 | #nop | ||
| 233 | move $3,$6 | ||
| 234 | move $2,$0 | ||
| 235 | addu $8,$8,-1 | ||
| 236 | addu $5,$5,$3 | ||
| 237 | sltu $6,$5,$3 | ||
| 238 | addu $4,$4,$2 | ||
| 239 | addu $4,$4,$6 | ||
| 240 | srl $3,$4,0 | ||
| 241 | move $2,$0 | ||
| 242 | move $6,$3 | ||
| 243 | .set noreorder | ||
| 244 | .set nomacro | ||
| 245 | beq $8,$0,$L11 | ||
| 246 | sw $5,0($11) | ||
| 247 | .set macro | ||
| 248 | .set reorder | ||
| 249 | |||
| 250 | lw $4,-8($9) | ||
| 251 | #nop | ||
| 252 | multu $7,$4 | ||
| 253 | mfhi $4 | ||
| 254 | mflo $5 | ||
| 255 | #nop | ||
| 256 | move $3,$6 | ||
| 257 | move $2,$0 | ||
| 258 | addu $8,$8,-1 | ||
| 259 | addu $5,$5,$3 | ||
| 260 | sltu $6,$5,$3 | ||
| 261 | addu $4,$4,$2 | ||
| 262 | addu $4,$4,$6 | ||
| 263 | srl $3,$4,0 | ||
| 264 | move $2,$0 | ||
| 265 | move $6,$3 | ||
| 266 | .set noreorder | ||
| 267 | .set nomacro | ||
| 268 | beq $8,$0,$L11 | ||
| 269 | sw $5,-8($10) | ||
| 270 | .set macro | ||
| 271 | .set reorder | ||
| 272 | |||
| 273 | lw $4,-4($9) | ||
| 274 | #nop | ||
| 275 | multu $7,$4 | ||
| 276 | mfhi $4 | ||
| 277 | mflo $5 | ||
| 278 | #nop | ||
| 279 | move $3,$6 | ||
| 280 | move $2,$0 | ||
| 281 | addu $8,$8,-1 | ||
| 282 | addu $5,$5,$3 | ||
| 283 | sltu $6,$5,$3 | ||
| 284 | addu $4,$4,$2 | ||
| 285 | addu $4,$4,$6 | ||
| 286 | srl $3,$4,0 | ||
| 287 | move $2,$0 | ||
| 288 | move $6,$3 | ||
| 289 | .set noreorder | ||
| 290 | .set nomacro | ||
| 291 | beq $8,$0,$L11 | ||
| 292 | sw $5,-4($10) | ||
| 293 | .set macro | ||
| 294 | .set reorder | ||
| 295 | |||
| 296 | lw $4,0($9) | ||
| 297 | #nop | ||
| 298 | multu $7,$4 | ||
| 299 | mfhi $4 | ||
| 300 | mflo $5 | ||
| 301 | #nop | ||
| 302 | move $3,$6 | ||
| 303 | move $2,$0 | ||
| 304 | addu $8,$8,-1 | ||
| 305 | addu $5,$5,$3 | ||
| 306 | sltu $6,$5,$3 | ||
| 307 | addu $4,$4,$2 | ||
| 308 | addu $4,$4,$6 | ||
| 309 | srl $3,$4,0 | ||
| 310 | move $2,$0 | ||
| 311 | move $6,$3 | ||
| 312 | .set noreorder | ||
| 313 | .set nomacro | ||
| 314 | beq $8,$0,$L11 | ||
| 315 | sw $5,0($10) | ||
| 316 | .set macro | ||
| 317 | .set reorder | ||
| 318 | |||
| 319 | addu $9,$9,16 | ||
| 320 | addu $12,$12,16 | ||
| 321 | addu $10,$10,16 | ||
| 322 | .set noreorder | ||
| 323 | .set nomacro | ||
| 324 | j $L10 | ||
| 325 | addu $11,$11,16 | ||
| 326 | .set macro | ||
| 327 | .set reorder | ||
| 328 | |||
| 329 | $L11: | ||
| 330 | .set noreorder | ||
| 331 | .set nomacro | ||
| 332 | j $31 | ||
| 333 | move $2,$6 | ||
| 334 | .set macro | ||
| 335 | .set reorder | ||
| 336 | |||
| 337 | .end bn_mul_words | ||
| 338 | .align 2 | ||
| 339 | .globl bn_sqr_words | ||
| 340 | .ent bn_sqr_words | ||
| 341 | bn_sqr_words: | ||
| 342 | .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0 | ||
| 343 | .mask 0x00000000,0 | ||
| 344 | .fmask 0x00000000,0 | ||
| 345 | .set noreorder | ||
| 346 | .cpload $25 | ||
| 347 | .set reorder | ||
| 348 | move $9,$4 | ||
| 349 | addu $7,$9,28 | ||
| 350 | addu $8,$5,12 | ||
| 351 | $L18: | ||
| 352 | lw $2,0($5) | ||
| 353 | #nop | ||
| 354 | multu $2,$2 | ||
| 355 | mfhi $2 | ||
| 356 | mflo $3 | ||
| 357 | #nop | ||
| 358 | addu $6,$6,-1 | ||
| 359 | sw $3,0($9) | ||
| 360 | srl $3,$2,0 | ||
| 361 | move $2,$0 | ||
| 362 | .set noreorder | ||
| 363 | .set nomacro | ||
| 364 | beq $6,$0,$L19 | ||
| 365 | sw $3,-24($7) | ||
| 366 | .set macro | ||
| 367 | .set reorder | ||
| 368 | |||
| 369 | lw $2,-8($8) | ||
| 370 | #nop | ||
| 371 | multu $2,$2 | ||
| 372 | mfhi $2 | ||
| 373 | mflo $3 | ||
| 374 | #nop | ||
| 375 | addu $6,$6,-1 | ||
| 376 | sw $3,-20($7) | ||
| 377 | srl $3,$2,0 | ||
| 378 | move $2,$0 | ||
| 379 | .set noreorder | ||
| 380 | .set nomacro | ||
| 381 | beq $6,$0,$L19 | ||
| 382 | sw $3,-16($7) | ||
| 383 | .set macro | ||
| 384 | .set reorder | ||
| 385 | |||
| 386 | lw $2,-4($8) | ||
| 387 | #nop | ||
| 388 | multu $2,$2 | ||
| 389 | mfhi $2 | ||
| 390 | mflo $3 | ||
| 391 | #nop | ||
| 392 | addu $6,$6,-1 | ||
| 393 | sw $3,-12($7) | ||
| 394 | srl $3,$2,0 | ||
| 395 | move $2,$0 | ||
| 396 | .set noreorder | ||
| 397 | .set nomacro | ||
| 398 | beq $6,$0,$L19 | ||
| 399 | sw $3,-8($7) | ||
| 400 | .set macro | ||
| 401 | .set reorder | ||
| 402 | |||
| 403 | lw $2,0($8) | ||
| 404 | #nop | ||
| 405 | multu $2,$2 | ||
| 406 | mfhi $2 | ||
| 407 | mflo $3 | ||
| 408 | #nop | ||
| 409 | addu $6,$6,-1 | ||
| 410 | sw $3,-4($7) | ||
| 411 | srl $3,$2,0 | ||
| 412 | move $2,$0 | ||
| 413 | .set noreorder | ||
| 414 | .set nomacro | ||
| 415 | beq $6,$0,$L19 | ||
| 416 | sw $3,0($7) | ||
| 417 | .set macro | ||
| 418 | .set reorder | ||
| 419 | |||
| 420 | addu $8,$8,16 | ||
| 421 | addu $5,$5,16 | ||
| 422 | addu $7,$7,32 | ||
| 423 | .set noreorder | ||
| 424 | .set nomacro | ||
| 425 | j $L18 | ||
| 426 | addu $9,$9,32 | ||
| 427 | .set macro | ||
| 428 | .set reorder | ||
| 429 | |||
| 430 | $L19: | ||
| 431 | j $31 | ||
| 432 | .end bn_sqr_words | ||
| 433 | .rdata | ||
| 434 | .align 2 | ||
| 435 | $LC0: | ||
| 436 | |||
| 437 | .byte 0x44,0x69,0x76,0x69,0x73,0x69,0x6f,0x6e | ||
| 438 | .byte 0x20,0x77,0x6f,0x75,0x6c,0x64,0x20,0x6f | ||
| 439 | .byte 0x76,0x65,0x72,0x66,0x6c,0x6f,0x77,0xa | ||
| 440 | .byte 0x0 | ||
| 441 | .text | ||
| 442 | .align 2 | ||
| 443 | .globl bn_div64 | ||
| 444 | .ent bn_div64 | ||
| 445 | bn_div64: | ||
| 446 | .frame $sp,56,$31 # vars= 0, regs= 7/0, args= 16, extra= 8 | ||
| 447 | .mask 0x901f0000,-8 | ||
| 448 | .fmask 0x00000000,0 | ||
| 449 | .set noreorder | ||
| 450 | .cpload $25 | ||
| 451 | .set reorder | ||
| 452 | subu $sp,$sp,56 | ||
| 453 | .cprestore 16 | ||
| 454 | sw $16,24($sp) | ||
| 455 | move $16,$4 | ||
| 456 | sw $17,28($sp) | ||
| 457 | move $17,$5 | ||
| 458 | sw $18,32($sp) | ||
| 459 | move $18,$6 | ||
| 460 | sw $20,40($sp) | ||
| 461 | move $20,$0 | ||
| 462 | sw $19,36($sp) | ||
| 463 | li $19,0x00000002 # 2 | ||
| 464 | sw $31,48($sp) | ||
| 465 | .set noreorder | ||
| 466 | .set nomacro | ||
| 467 | bne $18,$0,$L26 | ||
| 468 | sw $28,44($sp) | ||
| 469 | .set macro | ||
| 470 | .set reorder | ||
| 471 | |||
| 472 | .set noreorder | ||
| 473 | .set nomacro | ||
| 474 | j $L43 | ||
| 475 | li $2,-1 # 0xffffffff | ||
| 476 | .set macro | ||
| 477 | .set reorder | ||
| 478 | |||
| 479 | $L26: | ||
| 480 | move $4,$18 | ||
| 481 | jal BN_num_bits_word | ||
| 482 | move $4,$2 | ||
| 483 | li $2,0x00000020 # 32 | ||
| 484 | .set noreorder | ||
| 485 | .set nomacro | ||
| 486 | beq $4,$2,$L27 | ||
| 487 | li $2,0x00000001 # 1 | ||
| 488 | .set macro | ||
| 489 | .set reorder | ||
| 490 | |||
| 491 | sll $2,$2,$4 | ||
| 492 | sltu $2,$2,$16 | ||
| 493 | .set noreorder | ||
| 494 | .set nomacro | ||
| 495 | beq $2,$0,$L44 | ||
| 496 | li $5,0x00000020 # 32 | ||
| 497 | .set macro | ||
| 498 | .set reorder | ||
| 499 | |||
| 500 | la $4,__iob+32 | ||
| 501 | la $5,$LC0 | ||
| 502 | jal fprintf | ||
| 503 | jal abort | ||
| 504 | $L27: | ||
| 505 | li $5,0x00000020 # 32 | ||
| 506 | $L44: | ||
| 507 | sltu $2,$16,$18 | ||
| 508 | .set noreorder | ||
| 509 | .set nomacro | ||
| 510 | bne $2,$0,$L28 | ||
| 511 | subu $4,$5,$4 | ||
| 512 | .set macro | ||
| 513 | .set reorder | ||
| 514 | |||
| 515 | subu $16,$16,$18 | ||
| 516 | $L28: | ||
| 517 | .set noreorder | ||
| 518 | .set nomacro | ||
| 519 | beq $4,$0,$L29 | ||
| 520 | li $10,-65536 # 0xffff0000 | ||
| 521 | .set macro | ||
| 522 | .set reorder | ||
| 523 | |||
| 524 | sll $18,$18,$4 | ||
| 525 | sll $3,$16,$4 | ||
| 526 | subu $2,$5,$4 | ||
| 527 | srl $2,$17,$2 | ||
| 528 | or $16,$3,$2 | ||
| 529 | sll $17,$17,$4 | ||
| 530 | $L29: | ||
| 531 | srl $7,$18,16 | ||
| 532 | andi $9,$18,0xffff | ||
| 533 | $L30: | ||
| 534 | srl $2,$16,16 | ||
| 535 | .set noreorder | ||
| 536 | .set nomacro | ||
| 537 | beq $2,$7,$L34 | ||
| 538 | li $6,0x0000ffff # 65535 | ||
| 539 | .set macro | ||
| 540 | .set reorder | ||
| 541 | |||
| 542 | divu $6,$16,$7 | ||
| 543 | $L34: | ||
| 544 | mult $6,$9 | ||
| 545 | mflo $5 | ||
| 546 | #nop | ||
| 547 | #nop | ||
| 548 | mult $6,$7 | ||
| 549 | and $2,$17,$10 | ||
| 550 | srl $8,$2,16 | ||
| 551 | mflo $4 | ||
| 552 | $L35: | ||
| 553 | subu $3,$16,$4 | ||
| 554 | and $2,$3,$10 | ||
| 555 | .set noreorder | ||
| 556 | .set nomacro | ||
| 557 | bne $2,$0,$L36 | ||
| 558 | sll $2,$3,16 | ||
| 559 | .set macro | ||
| 560 | .set reorder | ||
| 561 | |||
| 562 | addu $2,$2,$8 | ||
| 563 | sltu $2,$2,$5 | ||
| 564 | .set noreorder | ||
| 565 | .set nomacro | ||
| 566 | beq $2,$0,$L36 | ||
| 567 | subu $5,$5,$9 | ||
| 568 | .set macro | ||
| 569 | .set reorder | ||
| 570 | |||
| 571 | subu $4,$4,$7 | ||
| 572 | .set noreorder | ||
| 573 | .set nomacro | ||
| 574 | j $L35 | ||
| 575 | addu $6,$6,-1 | ||
| 576 | .set macro | ||
| 577 | .set reorder | ||
| 578 | |||
| 579 | $L36: | ||
| 580 | mult $6,$7 | ||
| 581 | mflo $5 | ||
| 582 | #nop | ||
| 583 | #nop | ||
| 584 | mult $6,$9 | ||
| 585 | mflo $4 | ||
| 586 | #nop | ||
| 587 | #nop | ||
| 588 | srl $3,$4,16 | ||
| 589 | sll $2,$4,16 | ||
| 590 | and $4,$2,$10 | ||
| 591 | sltu $2,$17,$4 | ||
| 592 | .set noreorder | ||
| 593 | .set nomacro | ||
| 594 | beq $2,$0,$L40 | ||
| 595 | addu $5,$5,$3 | ||
| 596 | .set macro | ||
| 597 | .set reorder | ||
| 598 | |||
| 599 | addu $5,$5,1 | ||
| 600 | $L40: | ||
| 601 | sltu $2,$16,$5 | ||
| 602 | .set noreorder | ||
| 603 | .set nomacro | ||
| 604 | beq $2,$0,$L41 | ||
| 605 | subu $17,$17,$4 | ||
| 606 | .set macro | ||
| 607 | .set reorder | ||
| 608 | |||
| 609 | addu $16,$16,$18 | ||
| 610 | addu $6,$6,-1 | ||
| 611 | $L41: | ||
| 612 | addu $19,$19,-1 | ||
| 613 | .set noreorder | ||
| 614 | .set nomacro | ||
| 615 | beq $19,$0,$L31 | ||
| 616 | subu $16,$16,$5 | ||
| 617 | .set macro | ||
| 618 | .set reorder | ||
| 619 | |||
| 620 | sll $20,$6,16 | ||
| 621 | sll $3,$16,16 | ||
| 622 | srl $2,$17,16 | ||
| 623 | or $16,$3,$2 | ||
| 624 | .set noreorder | ||
| 625 | .set nomacro | ||
| 626 | j $L30 | ||
| 627 | sll $17,$17,16 | ||
| 628 | .set macro | ||
| 629 | .set reorder | ||
| 630 | |||
| 631 | $L31: | ||
| 632 | or $2,$20,$6 | ||
| 633 | $L43: | ||
| 634 | lw $31,48($sp) | ||
| 635 | lw $20,40($sp) | ||
| 636 | lw $19,36($sp) | ||
| 637 | lw $18,32($sp) | ||
| 638 | lw $17,28($sp) | ||
| 639 | lw $16,24($sp) | ||
| 640 | addu $sp,$sp,56 | ||
| 641 | j $31 | ||
| 642 | .end bn_div64 | ||
| 643 | |||
| 644 | .globl abort .text | ||
| 645 | .globl fprintf .text | ||
| 646 | .globl BN_num_bits_word .text | ||
diff --git a/src/lib/libcrypto/bn/bn_opt.c b/src/lib/libcrypto/bn/bn_opt.c deleted file mode 100644 index 21cbb38f62..0000000000 --- a/src/lib/libcrypto/bn/bn_opt.c +++ /dev/null | |||
| @@ -1,87 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_opt.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef BN_DEBUG | ||
| 60 | # undef NDEBUG /* avoid conflicting definitions */ | ||
| 61 | # define NDEBUG | ||
| 62 | #endif | ||
| 63 | |||
| 64 | #include <assert.h> | ||
| 65 | #include <limits.h> | ||
| 66 | #include <stdio.h> | ||
| 67 | #include "cryptlib.h" | ||
| 68 | #include "bn_lcl.h" | ||
| 69 | |||
| 70 | char *BN_options(void) | ||
| 71 | { | ||
| 72 | static int init=0; | ||
| 73 | static char data[16]; | ||
| 74 | |||
| 75 | if (!init) | ||
| 76 | { | ||
| 77 | init++; | ||
| 78 | #ifdef BN_LLONG | ||
| 79 | BIO_snprintf(data,sizeof data,"bn(%d,%d)", | ||
| 80 | (int)sizeof(BN_ULLONG)*8,(int)sizeof(BN_ULONG)*8); | ||
| 81 | #else | ||
| 82 | BIO_snprintf(data,sizeof data,"bn(%d,%d)", | ||
| 83 | (int)sizeof(BN_ULONG)*8,(int)sizeof(BN_ULONG)*8); | ||
| 84 | #endif | ||
| 85 | } | ||
| 86 | return(data); | ||
| 87 | } | ||
diff --git a/src/lib/libcrypto/camellia/Makefile b/src/lib/libcrypto/camellia/Makefile new file mode 100644 index 0000000000..ff5fe4a01d --- /dev/null +++ b/src/lib/libcrypto/camellia/Makefile | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | # | ||
| 2 | # crypto/camellia/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= camellia | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | CPP= $(CC) -E | ||
| 9 | INCLUDES= | ||
| 10 | CFLAG=-g | ||
| 11 | MAKEFILE= Makefile | ||
| 12 | AR= ar r | ||
| 13 | |||
| 14 | CMLL_ENC= camellia.o cmll_misc.o cmll_cbc.o | ||
| 15 | |||
| 16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 17 | ASFLAGS= $(INCLUDES) $(ASFLAG) | ||
| 18 | AFLAGS= $(ASFLAGS) | ||
| 19 | |||
| 20 | GENERAL=Makefile | ||
| 21 | #TEST=camelliatest.c | ||
| 22 | APPS= | ||
| 23 | |||
| 24 | LIB=$(TOP)/libcrypto.a | ||
| 25 | LIBSRC=camellia.c cmll_misc.c cmll_ecb.c cmll_cbc.c cmll_ofb.c \ | ||
| 26 | cmll_cfb.c cmll_ctr.c | ||
| 27 | |||
| 28 | LIBOBJ= cmll_ecb.o cmll_ofb.o cmll_cfb.o cmll_ctr.o $(CMLL_ENC) | ||
| 29 | |||
| 30 | SRC= $(LIBSRC) | ||
| 31 | |||
| 32 | EXHEADER= camellia.h | ||
| 33 | HEADER= cmll_locl.h $(EXHEADER) | ||
| 34 | |||
| 35 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 36 | |||
| 37 | top: | ||
| 38 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 39 | |||
| 40 | all: lib | ||
| 41 | |||
| 42 | lib: $(LIBOBJ) | ||
| 43 | $(AR) $(LIB) $(LIBOBJ) | ||
| 44 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 45 | @touch lib | ||
| 46 | |||
| 47 | cmll-x86.s: asm/cmll-x86.pl ../perlasm/x86asm.pl | ||
| 48 | $(PERL) asm/cmll-x86.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@ | ||
| 49 | cmll-x86_64.s: asm/cmll-x86_64.pl | ||
| 50 | $(PERL) asm/cmll-x86_64.pl $(PERLASM_SCHEME) > $@ | ||
| 51 | |||
| 52 | files: | ||
| 53 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 54 | |||
| 55 | links: | ||
| 56 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 57 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 58 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 59 | |||
| 60 | install: | ||
| 61 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 62 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 63 | do \ | ||
| 64 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 65 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 66 | done; | ||
| 67 | |||
| 68 | tags: | ||
| 69 | ctags $(SRC) | ||
| 70 | |||
| 71 | tests: | ||
| 72 | |||
| 73 | lint: | ||
| 74 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 75 | |||
| 76 | depend: | ||
| 77 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 78 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 79 | |||
| 80 | dclean: | ||
| 81 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 82 | mv -f Makefile.new $(MAKEFILE) | ||
| 83 | |||
| 84 | clean: | ||
| 85 | rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 86 | |||
| 87 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 88 | |||
| 89 | camellia.o: ../../include/openssl/opensslconf.h camellia.c camellia.h | ||
| 90 | camellia.o: cmll_locl.h | ||
| 91 | cmll_cbc.o: ../../include/openssl/camellia.h ../../include/openssl/modes.h | ||
| 92 | cmll_cbc.o: ../../include/openssl/opensslconf.h cmll_cbc.c | ||
| 93 | cmll_cfb.o: ../../include/openssl/camellia.h ../../include/openssl/modes.h | ||
| 94 | cmll_cfb.o: ../../include/openssl/opensslconf.h cmll_cfb.c | ||
| 95 | cmll_ctr.o: ../../include/openssl/camellia.h ../../include/openssl/modes.h | ||
| 96 | cmll_ctr.o: ../../include/openssl/opensslconf.h cmll_ctr.c | ||
| 97 | cmll_ecb.o: ../../include/openssl/camellia.h | ||
| 98 | cmll_ecb.o: ../../include/openssl/opensslconf.h cmll_ecb.c cmll_locl.h | ||
| 99 | cmll_misc.o: ../../include/openssl/camellia.h | ||
| 100 | cmll_misc.o: ../../include/openssl/opensslconf.h | ||
| 101 | cmll_misc.o: ../../include/openssl/opensslv.h cmll_locl.h cmll_misc.c | ||
| 102 | cmll_ofb.o: ../../include/openssl/camellia.h ../../include/openssl/modes.h | ||
| 103 | cmll_ofb.o: ../../include/openssl/opensslconf.h cmll_ofb.c | ||
diff --git a/src/lib/libcrypto/cms/Makefile b/src/lib/libcrypto/cms/Makefile new file mode 100644 index 0000000000..5837049725 --- /dev/null +++ b/src/lib/libcrypto/cms/Makefile | |||
| @@ -0,0 +1,264 @@ | |||
| 1 | # | ||
| 2 | # OpenSSL/crypto/cms/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= cms | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
| 9 | CFLAG=-g | ||
| 10 | MAKEFILE= Makefile | ||
| 11 | AR= ar r | ||
| 12 | |||
| 13 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 14 | |||
| 15 | GENERAL=Makefile | ||
| 16 | TEST= | ||
| 17 | APPS= | ||
| 18 | |||
| 19 | LIB=$(TOP)/libcrypto.a | ||
| 20 | LIBSRC= cms_lib.c cms_asn1.c cms_att.c cms_io.c cms_smime.c cms_err.c \ | ||
| 21 | cms_sd.c cms_dd.c cms_cd.c cms_env.c cms_enc.c cms_ess.c | ||
| 22 | LIBOBJ= cms_lib.o cms_asn1.o cms_att.o cms_io.o cms_smime.o cms_err.o \ | ||
| 23 | cms_sd.o cms_dd.o cms_cd.o cms_env.o cms_enc.o cms_ess.o | ||
| 24 | |||
| 25 | SRC= $(LIBSRC) | ||
| 26 | |||
| 27 | EXHEADER= cms.h | ||
| 28 | HEADER= cms_lcl.h $(EXHEADER) | ||
| 29 | |||
| 30 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 31 | |||
| 32 | top: | ||
| 33 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 34 | |||
| 35 | test: | ||
| 36 | |||
| 37 | all: lib | ||
| 38 | |||
| 39 | lib: $(LIBOBJ) | ||
| 40 | $(AR) $(LIB) $(LIBOBJ) | ||
| 41 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 42 | @touch lib | ||
| 43 | |||
| 44 | files: | ||
| 45 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 46 | |||
| 47 | links: | ||
| 48 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 49 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 50 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 51 | |||
| 52 | install: | ||
| 53 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 54 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 55 | do \ | ||
| 56 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 57 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 58 | done; | ||
| 59 | |||
| 60 | tags: | ||
| 61 | ctags $(SRC) | ||
| 62 | |||
| 63 | tests: | ||
| 64 | |||
| 65 | lint: | ||
| 66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 67 | |||
| 68 | depend: | ||
| 69 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 70 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 71 | |||
| 72 | dclean: | ||
| 73 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 74 | mv -f Makefile.new $(MAKEFILE) | ||
| 75 | |||
| 76 | clean: | ||
| 77 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 78 | |||
| 79 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 80 | |||
| 81 | cms_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 82 | cms_asn1.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 83 | cms_asn1.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 84 | cms_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 85 | cms_asn1.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 86 | cms_asn1.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 87 | cms_asn1.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 88 | cms_asn1.o: ../../include/openssl/opensslconf.h | ||
| 89 | cms_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 90 | cms_asn1.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 91 | cms_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 92 | cms_asn1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 93 | cms_asn1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 94 | cms_asn1.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 95 | cms_asn1.o: cms.h cms_asn1.c cms_lcl.h | ||
| 96 | cms_att.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 97 | cms_att.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 98 | cms_att.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 99 | cms_att.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 100 | cms_att.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 101 | cms_att.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 102 | cms_att.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 103 | cms_att.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 104 | cms_att.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 105 | cms_att.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 106 | cms_att.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 107 | cms_att.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 108 | cms_att.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 109 | cms_att.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 110 | cms_att.o: cms.h cms_att.c cms_lcl.h | ||
| 111 | cms_cd.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 112 | cms_cd.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 113 | cms_cd.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h | ||
| 114 | cms_cd.o: ../../include/openssl/comp.h ../../include/openssl/conf.h | ||
| 115 | cms_cd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 116 | cms_cd.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 117 | cms_cd.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 118 | cms_cd.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 119 | cms_cd.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 120 | cms_cd.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 121 | cms_cd.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
| 122 | cms_cd.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h | ||
| 123 | cms_cd.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 124 | cms_cd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 125 | cms_cd.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 126 | cms_cd.o: ../../include/openssl/x509v3.h ../cryptlib.h cms_cd.c cms_lcl.h | ||
| 127 | cms_dd.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 128 | cms_dd.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 129 | cms_dd.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h | ||
| 130 | cms_dd.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 131 | cms_dd.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 132 | cms_dd.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 133 | cms_dd.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 134 | cms_dd.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 135 | cms_dd.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 136 | cms_dd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 137 | cms_dd.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 138 | cms_dd.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 139 | cms_dd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 140 | cms_dd.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 141 | cms_dd.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 142 | cms_dd.o: ../cryptlib.h cms_dd.c cms_lcl.h | ||
| 143 | cms_enc.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 144 | cms_enc.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 145 | cms_enc.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h | ||
| 146 | cms_enc.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 147 | cms_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 148 | cms_enc.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 149 | cms_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 150 | cms_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 151 | cms_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 152 | cms_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 153 | cms_enc.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 154 | cms_enc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
| 155 | cms_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 156 | cms_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 157 | cms_enc.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 158 | cms_enc.o: ../../include/openssl/x509v3.h ../cryptlib.h cms_enc.c cms_lcl.h | ||
| 159 | cms_env.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 160 | cms_env.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 161 | cms_env.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 162 | cms_env.o: ../../include/openssl/cms.h ../../include/openssl/conf.h | ||
| 163 | cms_env.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 164 | cms_env.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 165 | cms_env.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 166 | cms_env.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 167 | cms_env.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 168 | cms_env.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 169 | cms_env.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
| 170 | cms_env.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h | ||
| 171 | cms_env.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | ||
| 172 | cms_env.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 173 | cms_env.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 174 | cms_env.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 175 | cms_env.o: ../asn1/asn1_locl.h ../cryptlib.h cms_env.c cms_lcl.h | ||
| 176 | cms_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 177 | cms_err.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h | ||
| 178 | cms_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 179 | cms_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 180 | cms_err.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 181 | cms_err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 182 | cms_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 183 | cms_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 184 | cms_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 185 | cms_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 186 | cms_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 187 | cms_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 188 | cms_err.o: cms_err.c | ||
| 189 | cms_ess.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 190 | cms_ess.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 191 | cms_ess.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h | ||
| 192 | cms_ess.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 193 | cms_ess.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 194 | cms_ess.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 195 | cms_ess.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 196 | cms_ess.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 197 | cms_ess.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 198 | cms_ess.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 199 | cms_ess.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 200 | cms_ess.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
| 201 | cms_ess.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 202 | cms_ess.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 203 | cms_ess.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 204 | cms_ess.o: ../../include/openssl/x509v3.h ../cryptlib.h cms_ess.c cms_lcl.h | ||
| 205 | cms_io.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 206 | cms_io.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 207 | cms_io.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 208 | cms_io.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 209 | cms_io.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 210 | cms_io.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 211 | cms_io.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 212 | cms_io.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 213 | cms_io.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
| 214 | cms_io.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h | ||
| 215 | cms_io.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 216 | cms_io.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 217 | cms_io.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h cms.h | ||
| 218 | cms_io.o: cms_io.c cms_lcl.h | ||
| 219 | cms_lib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 220 | cms_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 221 | cms_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 222 | cms_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 223 | cms_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 224 | cms_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 225 | cms_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 226 | cms_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 227 | cms_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
| 228 | cms_lib.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h | ||
| 229 | cms_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 230 | cms_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 231 | cms_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h cms.h | ||
| 232 | cms_lib.o: cms_lcl.h cms_lib.c | ||
| 233 | cms_sd.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 234 | cms_sd.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 235 | cms_sd.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h | ||
| 236 | cms_sd.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 237 | cms_sd.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 238 | cms_sd.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 239 | cms_sd.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 240 | cms_sd.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 241 | cms_sd.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 242 | cms_sd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 243 | cms_sd.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
| 244 | cms_sd.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 245 | cms_sd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 246 | cms_sd.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 247 | cms_sd.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 248 | cms_sd.o: ../asn1/asn1_locl.h ../cryptlib.h cms_lcl.h cms_sd.c | ||
| 249 | cms_smime.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 250 | cms_smime.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
| 251 | cms_smime.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h | ||
| 252 | cms_smime.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 253 | cms_smime.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 254 | cms_smime.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 255 | cms_smime.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 256 | cms_smime.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 257 | cms_smime.o: ../../include/openssl/objects.h | ||
| 258 | cms_smime.o: ../../include/openssl/opensslconf.h | ||
| 259 | cms_smime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 260 | cms_smime.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 261 | cms_smime.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 262 | cms_smime.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 263 | cms_smime.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 264 | cms_smime.o: ../cryptlib.h cms_lcl.h cms_smime.c | ||
diff --git a/src/lib/libcrypto/des/asm/des686.pl b/src/lib/libcrypto/des/asm/des686.pl deleted file mode 100644 index d3ad5d5edd..0000000000 --- a/src/lib/libcrypto/des/asm/des686.pl +++ /dev/null | |||
| @@ -1,230 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | $prog="des686.pl"; | ||
| 4 | |||
| 5 | # base code is in microsft | ||
| 6 | # op dest, source | ||
| 7 | # format. | ||
| 8 | # | ||
| 9 | |||
| 10 | # WILL NOT WORK ANYMORE WITH desboth.pl | ||
| 11 | require "desboth.pl"; | ||
| 12 | |||
| 13 | if ( ($ARGV[0] eq "elf")) | ||
| 14 | { require "x86unix.pl"; } | ||
| 15 | elsif ( ($ARGV[0] eq "a.out")) | ||
| 16 | { $aout=1; require "x86unix.pl"; } | ||
| 17 | elsif ( ($ARGV[0] eq "sol")) | ||
| 18 | { $sol=1; require "x86unix.pl"; } | ||
| 19 | elsif ( ($ARGV[0] eq "cpp")) | ||
| 20 | { $cpp=1; require "x86unix.pl"; } | ||
| 21 | elsif ( ($ARGV[0] eq "win32")) | ||
| 22 | { require "x86ms.pl"; } | ||
| 23 | else | ||
| 24 | { | ||
| 25 | print STDERR <<"EOF"; | ||
| 26 | Pick one target type from | ||
| 27 | elf - linux, FreeBSD etc | ||
| 28 | a.out - old linux | ||
| 29 | sol - x86 solaris | ||
| 30 | cpp - format so x86unix.cpp can be used | ||
| 31 | win32 - Windows 95/Windows NT | ||
| 32 | EOF | ||
| 33 | exit(1); | ||
| 34 | } | ||
| 35 | |||
| 36 | &comment("Don't even think of reading this code"); | ||
| 37 | &comment("It was automatically generated by $prog"); | ||
| 38 | &comment("Which is a perl program used to generate the x86 assember for"); | ||
| 39 | &comment("any of elf, a.out, Win32, or Solaris"); | ||
| 40 | &comment("It can be found in SSLeay 0.6.5+ or in libdes 3.26+"); | ||
| 41 | &comment("eric <eay\@cryptsoft.com>"); | ||
| 42 | &comment(""); | ||
| 43 | |||
| 44 | &file("dx86xxxx"); | ||
| 45 | |||
| 46 | $L="edi"; | ||
| 47 | $R="esi"; | ||
| 48 | |||
| 49 | &DES_encrypt("DES_encrypt1",1); | ||
| 50 | &DES_encrypt("DES_encrypt2",0); | ||
| 51 | |||
| 52 | &DES_encrypt3("DES_encrypt3",1); | ||
| 53 | &DES_encrypt3("DES_decrypt3",0); | ||
| 54 | |||
| 55 | &file_end(); | ||
| 56 | |||
| 57 | sub DES_encrypt | ||
| 58 | { | ||
| 59 | local($name,$do_ip)=@_; | ||
| 60 | |||
| 61 | &function_begin($name,"EXTRN _DES_SPtrans:DWORD"); | ||
| 62 | |||
| 63 | &comment(""); | ||
| 64 | &comment("Load the 2 words"); | ||
| 65 | &mov("eax",&wparam(0)); | ||
| 66 | &mov($L,&DWP(0,"eax","",0)); | ||
| 67 | &mov($R,&DWP(4,"eax","",0)); | ||
| 68 | |||
| 69 | $ksp=&wparam(1); | ||
| 70 | |||
| 71 | if ($do_ip) | ||
| 72 | { | ||
| 73 | &comment(""); | ||
| 74 | &comment("IP"); | ||
| 75 | &IP_new($L,$R,"eax"); | ||
| 76 | } | ||
| 77 | |||
| 78 | &comment(""); | ||
| 79 | &comment("fixup rotate"); | ||
| 80 | &rotl($R,3); | ||
| 81 | &rotl($L,3); | ||
| 82 | &exch($L,$R); | ||
| 83 | |||
| 84 | &comment(""); | ||
| 85 | &comment("load counter, key_schedule and enc flag"); | ||
| 86 | &mov("eax",&wparam(2)); # get encrypt flag | ||
| 87 | &mov("ebp",&wparam(1)); # get ks | ||
| 88 | &cmp("eax","0"); | ||
| 89 | &je(&label("start_decrypt")); | ||
| 90 | |||
| 91 | # encrypting part | ||
| 92 | |||
| 93 | for ($i=0; $i<16; $i+=2) | ||
| 94 | { | ||
| 95 | &comment(""); | ||
| 96 | &comment("Round $i"); | ||
| 97 | &D_ENCRYPT($L,$R,$i*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx"); | ||
| 98 | |||
| 99 | &comment(""); | ||
| 100 | &comment("Round ".sprintf("%d",$i+1)); | ||
| 101 | &D_ENCRYPT($R,$L,($i+1)*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx"); | ||
| 102 | } | ||
| 103 | &jmp(&label("end")); | ||
| 104 | |||
| 105 | &set_label("start_decrypt"); | ||
| 106 | |||
| 107 | for ($i=15; $i>0; $i-=2) | ||
| 108 | { | ||
| 109 | &comment(""); | ||
| 110 | &comment("Round $i"); | ||
| 111 | &D_ENCRYPT($L,$R,$i*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx"); | ||
| 112 | &comment(""); | ||
| 113 | &comment("Round ".sprintf("%d",$i-1)); | ||
| 114 | &D_ENCRYPT($R,$L,($i-1)*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx"); | ||
| 115 | } | ||
| 116 | |||
| 117 | &set_label("end"); | ||
| 118 | |||
| 119 | &comment(""); | ||
| 120 | &comment("Fixup"); | ||
| 121 | &rotr($L,3); # r | ||
| 122 | &rotr($R,3); # l | ||
| 123 | |||
| 124 | if ($do_ip) | ||
| 125 | { | ||
| 126 | &comment(""); | ||
| 127 | &comment("FP"); | ||
| 128 | &FP_new($R,$L,"eax"); | ||
| 129 | } | ||
| 130 | |||
| 131 | &mov("eax",&wparam(0)); | ||
| 132 | &mov(&DWP(0,"eax","",0),$L); | ||
| 133 | &mov(&DWP(4,"eax","",0),$R); | ||
| 134 | |||
| 135 | &function_end($name); | ||
| 136 | } | ||
| 137 | |||
| 138 | |||
| 139 | # The logic is to load R into 2 registers and operate on both at the same time. | ||
| 140 | # We also load the 2 R's into 2 more registers so we can do the 'move word down a byte' | ||
| 141 | # while also masking the other copy and doing a lookup. We then also accumulate the | ||
| 142 | # L value in 2 registers then combine them at the end. | ||
| 143 | sub D_ENCRYPT | ||
| 144 | { | ||
| 145 | local($L,$R,$S,$ks,$desSP,$u,$t,$tmp1,$tmp2,$tmp3)=@_; | ||
| 146 | |||
| 147 | &mov( $u, &DWP(&n2a($S*4),$ks,"",0)); | ||
| 148 | &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0)); | ||
| 149 | &xor( $u, $R ); | ||
| 150 | &xor( $t, $R ); | ||
| 151 | &rotr( $t, 4 ); | ||
| 152 | |||
| 153 | # the numbers at the end of the line are origional instruction order | ||
| 154 | &mov( $tmp2, $u ); # 1 2 | ||
| 155 | &mov( $tmp1, $t ); # 1 1 | ||
| 156 | &and( $tmp2, "0xfc" ); # 1 4 | ||
| 157 | &and( $tmp1, "0xfc" ); # 1 3 | ||
| 158 | &shr( $t, 8 ); # 1 5 | ||
| 159 | &xor( $L, &DWP("0x100+$desSP",$tmp1,"",0)); # 1 7 | ||
| 160 | &shr( $u, 8 ); # 1 6 | ||
| 161 | &mov( $tmp1, &DWP(" $desSP",$tmp2,"",0)); # 1 8 | ||
| 162 | |||
| 163 | &mov( $tmp2, $u ); # 2 2 | ||
| 164 | &xor( $L, $tmp1 ); # 1 9 | ||
| 165 | &and( $tmp2, "0xfc" ); # 2 4 | ||
| 166 | &mov( $tmp1, $t ); # 2 1 | ||
| 167 | &and( $tmp1, "0xfc" ); # 2 3 | ||
| 168 | &shr( $t, 8 ); # 2 5 | ||
| 169 | &xor( $L, &DWP("0x300+$desSP",$tmp1,"",0)); # 2 7 | ||
| 170 | &shr( $u, 8 ); # 2 6 | ||
| 171 | &mov( $tmp1, &DWP("0x200+$desSP",$tmp2,"",0)); # 2 8 | ||
| 172 | &mov( $tmp2, $u ); # 3 2 | ||
| 173 | |||
| 174 | &xor( $L, $tmp1 ); # 2 9 | ||
| 175 | &and( $tmp2, "0xfc" ); # 3 4 | ||
| 176 | |||
| 177 | &mov( $tmp1, $t ); # 3 1 | ||
| 178 | &shr( $u, 8 ); # 3 6 | ||
| 179 | &and( $tmp1, "0xfc" ); # 3 3 | ||
| 180 | &shr( $t, 8 ); # 3 5 | ||
| 181 | &xor( $L, &DWP("0x500+$desSP",$tmp1,"",0)); # 3 7 | ||
| 182 | &mov( $tmp1, &DWP("0x400+$desSP",$tmp2,"",0)); # 3 8 | ||
| 183 | |||
| 184 | &and( $t, "0xfc" ); # 4 1 | ||
| 185 | &xor( $L, $tmp1 ); # 3 9 | ||
| 186 | |||
| 187 | &and( $u, "0xfc" ); # 4 2 | ||
| 188 | &xor( $L, &DWP("0x700+$desSP",$t,"",0)); # 4 3 | ||
| 189 | &xor( $L, &DWP("0x600+$desSP",$u,"",0)); # 4 4 | ||
| 190 | } | ||
| 191 | |||
| 192 | sub PERM_OP | ||
| 193 | { | ||
| 194 | local($a,$b,$tt,$shift,$mask)=@_; | ||
| 195 | |||
| 196 | &mov( $tt, $a ); | ||
| 197 | &shr( $tt, $shift ); | ||
| 198 | &xor( $tt, $b ); | ||
| 199 | &and( $tt, $mask ); | ||
| 200 | &xor( $b, $tt ); | ||
| 201 | &shl( $tt, $shift ); | ||
| 202 | &xor( $a, $tt ); | ||
| 203 | } | ||
| 204 | |||
| 205 | sub IP_new | ||
| 206 | { | ||
| 207 | local($l,$r,$tt)=@_; | ||
| 208 | |||
| 209 | &PERM_OP($r,$l,$tt, 4,"0x0f0f0f0f"); | ||
| 210 | &PERM_OP($l,$r,$tt,16,"0x0000ffff"); | ||
| 211 | &PERM_OP($r,$l,$tt, 2,"0x33333333"); | ||
| 212 | &PERM_OP($l,$r,$tt, 8,"0x00ff00ff"); | ||
| 213 | &PERM_OP($r,$l,$tt, 1,"0x55555555"); | ||
| 214 | } | ||
| 215 | |||
| 216 | sub FP_new | ||
| 217 | { | ||
| 218 | local($l,$r,$tt)=@_; | ||
| 219 | |||
| 220 | &PERM_OP($l,$r,$tt, 1,"0x55555555"); | ||
| 221 | &PERM_OP($r,$l,$tt, 8,"0x00ff00ff"); | ||
| 222 | &PERM_OP($l,$r,$tt, 2,"0x33333333"); | ||
| 223 | &PERM_OP($r,$l,$tt,16,"0x0000ffff"); | ||
| 224 | &PERM_OP($l,$r,$tt, 4,"0x0f0f0f0f"); | ||
| 225 | } | ||
| 226 | |||
| 227 | sub n2a | ||
| 228 | { | ||
| 229 | sprintf("%d",$_[0]); | ||
| 230 | } | ||
diff --git a/src/lib/libcrypto/des/des_lib.c b/src/lib/libcrypto/des/des_lib.c deleted file mode 100644 index d4b3047932..0000000000 --- a/src/lib/libcrypto/des/des_lib.c +++ /dev/null | |||
| @@ -1,106 +0,0 @@ | |||
| 1 | /* crypto/des/ecb_enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | #include "des_ver.h" | ||
| 61 | #include <openssl/opensslv.h> | ||
| 62 | #include <openssl/bio.h> | ||
| 63 | |||
| 64 | OPENSSL_GLOBAL const char libdes_version[]="libdes" OPENSSL_VERSION_PTEXT; | ||
| 65 | OPENSSL_GLOBAL const char DES_version[]="DES" OPENSSL_VERSION_PTEXT; | ||
| 66 | |||
| 67 | const char *DES_options(void) | ||
| 68 | { | ||
| 69 | static int init=1; | ||
| 70 | static char buf[32]; | ||
| 71 | |||
| 72 | if (init) | ||
| 73 | { | ||
| 74 | const char *ptr,*unroll,*risc,*size; | ||
| 75 | |||
| 76 | #ifdef DES_PTR | ||
| 77 | ptr="ptr"; | ||
| 78 | #else | ||
| 79 | ptr="idx"; | ||
| 80 | #endif | ||
| 81 | #if defined(DES_RISC1) || defined(DES_RISC2) | ||
| 82 | #ifdef DES_RISC1 | ||
| 83 | risc="risc1"; | ||
| 84 | #endif | ||
| 85 | #ifdef DES_RISC2 | ||
| 86 | risc="risc2"; | ||
| 87 | #endif | ||
| 88 | #else | ||
| 89 | risc="cisc"; | ||
| 90 | #endif | ||
| 91 | #ifdef DES_UNROLL | ||
| 92 | unroll="16"; | ||
| 93 | #else | ||
| 94 | unroll="4"; | ||
| 95 | #endif | ||
| 96 | if (sizeof(DES_LONG) != sizeof(long)) | ||
| 97 | size="int"; | ||
| 98 | else | ||
| 99 | size="long"; | ||
| 100 | BIO_snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll, | ||
| 101 | size); | ||
| 102 | init=0; | ||
| 103 | } | ||
| 104 | return(buf); | ||
| 105 | } | ||
| 106 | |||
diff --git a/src/lib/libcrypto/dsa/dsa_utl.c b/src/lib/libcrypto/dsa/dsa_utl.c deleted file mode 100644 index 24c021d120..0000000000 --- a/src/lib/libcrypto/dsa/dsa_utl.c +++ /dev/null | |||
| @@ -1,95 +0,0 @@ | |||
| 1 | /* crypto/dsa/dsa_lib.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include <openssl/bn.h> | ||
| 64 | #include <openssl/dsa.h> | ||
| 65 | #include <openssl/asn1.h> | ||
| 66 | #ifndef OPENSSL_NO_ENGINE | ||
| 67 | #include <openssl/engine.h> | ||
| 68 | #endif | ||
| 69 | #ifndef OPENSSL_NO_DH | ||
| 70 | #include <openssl/dh.h> | ||
| 71 | #endif | ||
| 72 | |||
| 73 | DSA_SIG *DSA_SIG_new(void) | ||
| 74 | { | ||
| 75 | DSA_SIG *sig; | ||
| 76 | sig = OPENSSL_malloc(sizeof(DSA_SIG)); | ||
| 77 | if (!sig) | ||
| 78 | return NULL; | ||
| 79 | sig->r = NULL; | ||
| 80 | sig->s = NULL; | ||
| 81 | return sig; | ||
| 82 | } | ||
| 83 | |||
| 84 | void DSA_SIG_free(DSA_SIG *sig) | ||
| 85 | { | ||
| 86 | if (sig) | ||
| 87 | { | ||
| 88 | if (sig->r) | ||
| 89 | BN_free(sig->r); | ||
| 90 | if (sig->s) | ||
| 91 | BN_free(sig->s); | ||
| 92 | OPENSSL_free(sig); | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
diff --git a/src/lib/libcrypto/dso/dso_beos.c b/src/lib/libcrypto/dso/dso_beos.c new file mode 100644 index 0000000000..553966e699 --- /dev/null +++ b/src/lib/libcrypto/dso/dso_beos.c | |||
| @@ -0,0 +1,270 @@ | |||
| 1 | /* dso_beos.c */ | ||
| 2 | /* Written by Marcin Konicki (ahwayakchih@neoni.net) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/dso.h> | ||
| 63 | |||
| 64 | #if !defined(OPENSSL_SYS_BEOS) | ||
| 65 | DSO_METHOD *DSO_METHOD_beos(void) | ||
| 66 | { | ||
| 67 | return NULL; | ||
| 68 | } | ||
| 69 | #else | ||
| 70 | |||
| 71 | #include <kernel/image.h> | ||
| 72 | |||
| 73 | static int beos_load(DSO *dso); | ||
| 74 | static int beos_unload(DSO *dso); | ||
| 75 | static void *beos_bind_var(DSO *dso, const char *symname); | ||
| 76 | static DSO_FUNC_TYPE beos_bind_func(DSO *dso, const char *symname); | ||
| 77 | #if 0 | ||
| 78 | static int beos_unbind_var(DSO *dso, char *symname, void *symptr); | ||
| 79 | static int beos_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); | ||
| 80 | static int beos_init(DSO *dso); | ||
| 81 | static int beos_finish(DSO *dso); | ||
| 82 | static long beos_ctrl(DSO *dso, int cmd, long larg, void *parg); | ||
| 83 | #endif | ||
| 84 | static char *beos_name_converter(DSO *dso, const char *filename); | ||
| 85 | |||
| 86 | static DSO_METHOD dso_meth_beos = { | ||
| 87 | "OpenSSL 'beos' shared library method", | ||
| 88 | beos_load, | ||
| 89 | beos_unload, | ||
| 90 | beos_bind_var, | ||
| 91 | beos_bind_func, | ||
| 92 | /* For now, "unbind" doesn't exist */ | ||
| 93 | #if 0 | ||
| 94 | NULL, /* unbind_var */ | ||
| 95 | NULL, /* unbind_func */ | ||
| 96 | #endif | ||
| 97 | NULL, /* ctrl */ | ||
| 98 | beos_name_converter, | ||
| 99 | NULL, /* init */ | ||
| 100 | NULL /* finish */ | ||
| 101 | }; | ||
| 102 | |||
| 103 | DSO_METHOD *DSO_METHOD_beos(void) | ||
| 104 | { | ||
| 105 | return(&dso_meth_beos); | ||
| 106 | } | ||
| 107 | |||
| 108 | /* For this DSO_METHOD, our meth_data STACK will contain; | ||
| 109 | * (i) a pointer to the handle (image_id) returned from | ||
| 110 | * load_add_on(). | ||
| 111 | */ | ||
| 112 | |||
| 113 | static int beos_load(DSO *dso) | ||
| 114 | { | ||
| 115 | image_id id; | ||
| 116 | /* See applicable comments from dso_dl.c */ | ||
| 117 | char *filename = DSO_convert_filename(dso, NULL); | ||
| 118 | |||
| 119 | if(filename == NULL) | ||
| 120 | { | ||
| 121 | DSOerr(DSO_F_BEOS_LOAD,DSO_R_NO_FILENAME); | ||
| 122 | goto err; | ||
| 123 | } | ||
| 124 | id = load_add_on(filename); | ||
| 125 | if(id < 1) | ||
| 126 | { | ||
| 127 | DSOerr(DSO_F_BEOS_LOAD,DSO_R_LOAD_FAILED); | ||
| 128 | ERR_add_error_data(3, "filename(", filename, ")"); | ||
| 129 | goto err; | ||
| 130 | } | ||
| 131 | if(!sk_push(dso->meth_data, (char *)id)) | ||
| 132 | { | ||
| 133 | DSOerr(DSO_F_BEOS_LOAD,DSO_R_STACK_ERROR); | ||
| 134 | goto err; | ||
| 135 | } | ||
| 136 | /* Success */ | ||
| 137 | dso->loaded_filename = filename; | ||
| 138 | return(1); | ||
| 139 | err: | ||
| 140 | /* Cleanup !*/ | ||
| 141 | if(filename != NULL) | ||
| 142 | OPENSSL_free(filename); | ||
| 143 | if(id > 0) | ||
| 144 | unload_add_on(id); | ||
| 145 | return(0); | ||
| 146 | } | ||
| 147 | |||
| 148 | static int beos_unload(DSO *dso) | ||
| 149 | { | ||
| 150 | image_id id; | ||
| 151 | if(dso == NULL) | ||
| 152 | { | ||
| 153 | DSOerr(DSO_F_BEOS_UNLOAD,ERR_R_PASSED_NULL_PARAMETER); | ||
| 154 | return(0); | ||
| 155 | } | ||
| 156 | if(sk_num(dso->meth_data) < 1) | ||
| 157 | return(1); | ||
| 158 | id = (image_id)sk_pop(dso->meth_data); | ||
| 159 | if(id < 1) | ||
| 160 | { | ||
| 161 | DSOerr(DSO_F_BEOS_UNLOAD,DSO_R_NULL_HANDLE); | ||
| 162 | return(0); | ||
| 163 | } | ||
| 164 | if(unload_add_on(id) != B_OK) | ||
| 165 | { | ||
| 166 | DSOerr(DSO_F_BEOS_UNLOAD,DSO_R_UNLOAD_FAILED); | ||
| 167 | /* We should push the value back onto the stack in | ||
| 168 | * case of a retry. */ | ||
| 169 | sk_push(dso->meth_data, (char *)id); | ||
| 170 | return(0); | ||
| 171 | } | ||
| 172 | return(1); | ||
| 173 | } | ||
| 174 | |||
| 175 | static void *beos_bind_var(DSO *dso, const char *symname) | ||
| 176 | { | ||
| 177 | image_id id; | ||
| 178 | void *sym; | ||
| 179 | |||
| 180 | if((dso == NULL) || (symname == NULL)) | ||
| 181 | { | ||
| 182 | DSOerr(DSO_F_BEOS_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); | ||
| 183 | return(NULL); | ||
| 184 | } | ||
| 185 | if(sk_num(dso->meth_data) < 1) | ||
| 186 | { | ||
| 187 | DSOerr(DSO_F_BEOS_BIND_VAR,DSO_R_STACK_ERROR); | ||
| 188 | return(NULL); | ||
| 189 | } | ||
| 190 | id = (image_id)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | ||
| 191 | if(id < 1) | ||
| 192 | { | ||
| 193 | DSOerr(DSO_F_BEOS_BIND_VAR,DSO_R_NULL_HANDLE); | ||
| 194 | return(NULL); | ||
| 195 | } | ||
| 196 | if(get_image_symbol(id, symname, B_SYMBOL_TYPE_DATA, &sym) != B_OK) | ||
| 197 | { | ||
| 198 | DSOerr(DSO_F_BEOS_BIND_VAR,DSO_R_SYM_FAILURE); | ||
| 199 | ERR_add_error_data(3, "symname(", symname, ")"); | ||
| 200 | return(NULL); | ||
| 201 | } | ||
| 202 | return(sym); | ||
| 203 | } | ||
| 204 | |||
| 205 | static DSO_FUNC_TYPE beos_bind_func(DSO *dso, const char *symname) | ||
| 206 | { | ||
| 207 | image_id id; | ||
| 208 | void *sym; | ||
| 209 | |||
| 210 | if((dso == NULL) || (symname == NULL)) | ||
| 211 | { | ||
| 212 | DSOerr(DSO_F_BEOS_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); | ||
| 213 | return(NULL); | ||
| 214 | } | ||
| 215 | if(sk_num(dso->meth_data) < 1) | ||
| 216 | { | ||
| 217 | DSOerr(DSO_F_BEOS_BIND_FUNC,DSO_R_STACK_ERROR); | ||
| 218 | return(NULL); | ||
| 219 | } | ||
| 220 | id = (image_id)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | ||
| 221 | if(id < 1) | ||
| 222 | { | ||
| 223 | DSOerr(DSO_F_BEOS_BIND_FUNC,DSO_R_NULL_HANDLE); | ||
| 224 | return(NULL); | ||
| 225 | } | ||
| 226 | if(get_image_symbol(id, symname, B_SYMBOL_TYPE_TEXT, &sym) != B_OK) | ||
| 227 | { | ||
| 228 | DSOerr(DSO_F_BEOS_BIND_FUNC,DSO_R_SYM_FAILURE); | ||
| 229 | ERR_add_error_data(3, "symname(", symname, ")"); | ||
| 230 | return(NULL); | ||
| 231 | } | ||
| 232 | return((DSO_FUNC_TYPE)sym); | ||
| 233 | } | ||
| 234 | |||
| 235 | /* This one is the same as the one in dlfcn */ | ||
| 236 | static char *beos_name_converter(DSO *dso, const char *filename) | ||
| 237 | { | ||
| 238 | char *translated; | ||
| 239 | int len, rsize, transform; | ||
| 240 | |||
| 241 | len = strlen(filename); | ||
| 242 | rsize = len + 1; | ||
| 243 | transform = (strstr(filename, "/") == NULL); | ||
| 244 | if(transform) | ||
| 245 | { | ||
| 246 | /* We will convert this to "%s.so" or "lib%s.so" */ | ||
| 247 | rsize += 3; /* The length of ".so" */ | ||
| 248 | if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) | ||
| 249 | rsize += 3; /* The length of "lib" */ | ||
| 250 | } | ||
| 251 | translated = OPENSSL_malloc(rsize); | ||
| 252 | if(translated == NULL) | ||
| 253 | { | ||
| 254 | DSOerr(DSO_F_BEOS_NAME_CONVERTER, | ||
| 255 | DSO_R_NAME_TRANSLATION_FAILED); | ||
| 256 | return(NULL); | ||
| 257 | } | ||
| 258 | if(transform) | ||
| 259 | { | ||
| 260 | if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) | ||
| 261 | sprintf(translated, "lib%s.so", filename); | ||
| 262 | else | ||
| 263 | sprintf(translated, "%s.so", filename); | ||
| 264 | } | ||
| 265 | else | ||
| 266 | sprintf(translated, "%s", filename); | ||
| 267 | return(translated); | ||
| 268 | } | ||
| 269 | |||
| 270 | #endif | ||
diff --git a/src/lib/libcrypto/dyn_lck.c b/src/lib/libcrypto/dyn_lck.c deleted file mode 100644 index 7f82c41264..0000000000 --- a/src/lib/libcrypto/dyn_lck.c +++ /dev/null | |||
| @@ -1,428 +0,0 @@ | |||
| 1 | /* crypto/cryptlib.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 56 | * All rights reserved. | ||
| 57 | * | ||
| 58 | * This package is an SSL implementation written | ||
| 59 | * by Eric Young (eay@cryptsoft.com). | ||
| 60 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 61 | * | ||
| 62 | * This library is free for commercial and non-commercial use as long as | ||
| 63 | * the following conditions are aheared to. The following conditions | ||
| 64 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 65 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 66 | * included with this distribution is covered by the same copyright terms | ||
| 67 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 68 | * | ||
| 69 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 70 | * the code are not to be removed. | ||
| 71 | * If this package is used in a product, Eric Young should be given attribution | ||
| 72 | * as the author of the parts of the library used. | ||
| 73 | * This can be in the form of a textual message at program startup or | ||
| 74 | * in documentation (online or textual) provided with the package. | ||
| 75 | * | ||
| 76 | * Redistribution and use in source and binary forms, with or without | ||
| 77 | * modification, are permitted provided that the following conditions | ||
| 78 | * are met: | ||
| 79 | * 1. Redistributions of source code must retain the copyright | ||
| 80 | * notice, this list of conditions and the following disclaimer. | ||
| 81 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 82 | * notice, this list of conditions and the following disclaimer in the | ||
| 83 | * documentation and/or other materials provided with the distribution. | ||
| 84 | * 3. All advertising materials mentioning features or use of this software | ||
| 85 | * must display the following acknowledgement: | ||
| 86 | * "This product includes cryptographic software written by | ||
| 87 | * Eric Young (eay@cryptsoft.com)" | ||
| 88 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 89 | * being used are not cryptographic related :-). | ||
| 90 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 91 | * the apps directory (application code) you must include an acknowledgement: | ||
| 92 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 93 | * | ||
| 94 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 95 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 96 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 97 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 98 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 99 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 100 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 101 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 102 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 103 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 104 | * SUCH DAMAGE. | ||
| 105 | * | ||
| 106 | * The licence and distribution terms for any publically available version or | ||
| 107 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 108 | * copied and put under another distribution licence | ||
| 109 | * [including the GNU Public Licence.] | ||
| 110 | */ | ||
| 111 | /* ==================================================================== | ||
| 112 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 113 | * ECDH support in OpenSSL originally developed by | ||
| 114 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
| 115 | */ | ||
| 116 | |||
| 117 | #include "cryptlib.h" | ||
| 118 | #include <openssl/safestack.h> | ||
| 119 | |||
| 120 | #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) | ||
| 121 | static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */ | ||
| 122 | #endif | ||
| 123 | |||
| 124 | DECLARE_STACK_OF(CRYPTO_dynlock) | ||
| 125 | IMPLEMENT_STACK_OF(CRYPTO_dynlock) | ||
| 126 | |||
| 127 | /* real #defines in crypto.h, keep these upto date */ | ||
| 128 | static const char* const lock_names[CRYPTO_NUM_LOCKS] = | ||
| 129 | { | ||
| 130 | "<<ERROR>>", | ||
| 131 | "err", | ||
| 132 | "ex_data", | ||
| 133 | "x509", | ||
| 134 | "x509_info", | ||
| 135 | "x509_pkey", | ||
| 136 | "x509_crl", | ||
| 137 | "x509_req", | ||
| 138 | "dsa", | ||
| 139 | "rsa", | ||
| 140 | "evp_pkey", | ||
| 141 | "x509_store", | ||
| 142 | "ssl_ctx", | ||
| 143 | "ssl_cert", | ||
| 144 | "ssl_session", | ||
| 145 | "ssl_sess_cert", | ||
| 146 | "ssl", | ||
| 147 | "ssl_method", | ||
| 148 | "rand", | ||
| 149 | "rand2", | ||
| 150 | "debug_malloc", | ||
| 151 | "BIO", | ||
| 152 | "gethostbyname", | ||
| 153 | "getservbyname", | ||
| 154 | "readdir", | ||
| 155 | "RSA_blinding", | ||
| 156 | "dh", | ||
| 157 | "debug_malloc2", | ||
| 158 | "dso", | ||
| 159 | "dynlock", | ||
| 160 | "engine", | ||
| 161 | "ui", | ||
| 162 | "ecdsa", | ||
| 163 | "ec", | ||
| 164 | "ecdh", | ||
| 165 | "bn", | ||
| 166 | "ec_pre_comp", | ||
| 167 | "store", | ||
| 168 | "comp", | ||
| 169 | #ifndef OPENSSL_FIPS | ||
| 170 | # if CRYPTO_NUM_LOCKS != 39 | ||
| 171 | # error "Inconsistency between crypto.h and cryptlib.c" | ||
| 172 | # endif | ||
| 173 | #else | ||
| 174 | "fips", | ||
| 175 | "fips2", | ||
| 176 | # if CRYPTO_NUM_LOCKS != 41 | ||
| 177 | # error "Inconsistency between crypto.h and cryptlib.c" | ||
| 178 | # endif | ||
| 179 | #endif | ||
| 180 | }; | ||
| 181 | |||
| 182 | /* This is for applications to allocate new type names in the non-dynamic | ||
| 183 | array of lock names. These are numbered with positive numbers. */ | ||
| 184 | static STACK *app_locks=NULL; | ||
| 185 | |||
| 186 | /* For applications that want a more dynamic way of handling threads, the | ||
| 187 | following stack is used. These are externally numbered with negative | ||
| 188 | numbers. */ | ||
| 189 | static STACK_OF(CRYPTO_dynlock) *dyn_locks=NULL; | ||
| 190 | |||
| 191 | |||
| 192 | static struct CRYPTO_dynlock_value *(MS_FAR *dynlock_create_callback) | ||
| 193 | (const char *file,int line)=NULL; | ||
| 194 | static void (MS_FAR *dynlock_lock_callback)(int mode, | ||
| 195 | struct CRYPTO_dynlock_value *l, const char *file,int line)=NULL; | ||
| 196 | static void (MS_FAR *dynlock_destroy_callback)(struct CRYPTO_dynlock_value *l, | ||
| 197 | const char *file,int line)=NULL; | ||
| 198 | |||
| 199 | int CRYPTO_get_new_lockid(char *name) | ||
| 200 | { | ||
| 201 | char *str; | ||
| 202 | int i; | ||
| 203 | |||
| 204 | #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) | ||
| 205 | /* A hack to make Visual C++ 5.0 work correctly when linking as | ||
| 206 | * a DLL using /MT. Without this, the application cannot use | ||
| 207 | * and floating point printf's. | ||
| 208 | * It also seems to be needed for Visual C 1.5 (win16) */ | ||
| 209 | SSLeay_MSVC5_hack=(double)name[0]*(double)name[1]; | ||
| 210 | #endif | ||
| 211 | |||
| 212 | if ((app_locks == NULL) && ((app_locks=sk_new_null()) == NULL)) | ||
| 213 | { | ||
| 214 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE); | ||
| 215 | return(0); | ||
| 216 | } | ||
| 217 | if ((str=BUF_strdup(name)) == NULL) | ||
| 218 | { | ||
| 219 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE); | ||
| 220 | return(0); | ||
| 221 | } | ||
| 222 | i=sk_push(app_locks,str); | ||
| 223 | if (!i) | ||
| 224 | OPENSSL_free(str); | ||
| 225 | else | ||
| 226 | i+=CRYPTO_NUM_LOCKS; /* gap of one :-) */ | ||
| 227 | return(i); | ||
| 228 | } | ||
| 229 | |||
| 230 | int CRYPTO_get_new_dynlockid(void) | ||
| 231 | { | ||
| 232 | int i = 0; | ||
| 233 | CRYPTO_dynlock *pointer = NULL; | ||
| 234 | |||
| 235 | if (dynlock_create_callback == NULL) | ||
| 236 | { | ||
| 237 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK); | ||
| 238 | return(0); | ||
| 239 | } | ||
| 240 | CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK); | ||
| 241 | if ((dyn_locks == NULL) | ||
| 242 | && ((dyn_locks=sk_CRYPTO_dynlock_new_null()) == NULL)) | ||
| 243 | { | ||
| 244 | CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); | ||
| 245 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE); | ||
| 246 | return(0); | ||
| 247 | } | ||
| 248 | CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); | ||
| 249 | |||
| 250 | pointer = (CRYPTO_dynlock *)OPENSSL_malloc(sizeof(CRYPTO_dynlock)); | ||
| 251 | if (pointer == NULL) | ||
| 252 | { | ||
| 253 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE); | ||
| 254 | return(0); | ||
| 255 | } | ||
| 256 | pointer->references = 1; | ||
| 257 | pointer->data = dynlock_create_callback(__FILE__,__LINE__); | ||
| 258 | if (pointer->data == NULL) | ||
| 259 | { | ||
| 260 | OPENSSL_free(pointer); | ||
| 261 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE); | ||
| 262 | return(0); | ||
| 263 | } | ||
| 264 | |||
| 265 | CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK); | ||
| 266 | /* First, try to find an existing empty slot */ | ||
| 267 | i=sk_CRYPTO_dynlock_find(dyn_locks,NULL); | ||
| 268 | /* If there was none, push, thereby creating a new one */ | ||
| 269 | if (i == -1) | ||
| 270 | /* Since sk_push() returns the number of items on the | ||
| 271 | stack, not the location of the pushed item, we need | ||
| 272 | to transform the returned number into a position, | ||
| 273 | by decreasing it. */ | ||
| 274 | i=sk_CRYPTO_dynlock_push(dyn_locks,pointer) - 1; | ||
| 275 | else | ||
| 276 | /* If we found a place with a NULL pointer, put our pointer | ||
| 277 | in it. */ | ||
| 278 | (void)sk_CRYPTO_dynlock_set(dyn_locks,i,pointer); | ||
| 279 | CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); | ||
| 280 | |||
| 281 | if (i == -1) | ||
| 282 | { | ||
| 283 | dynlock_destroy_callback(pointer->data,__FILE__,__LINE__); | ||
| 284 | OPENSSL_free(pointer); | ||
| 285 | } | ||
| 286 | else | ||
| 287 | i += 1; /* to avoid 0 */ | ||
| 288 | return -i; | ||
| 289 | } | ||
| 290 | |||
| 291 | void CRYPTO_destroy_dynlockid(int i) | ||
| 292 | { | ||
| 293 | CRYPTO_dynlock *pointer = NULL; | ||
| 294 | if (i) | ||
| 295 | i = -i-1; | ||
| 296 | if (dynlock_destroy_callback == NULL) | ||
| 297 | return; | ||
| 298 | |||
| 299 | CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK); | ||
| 300 | |||
| 301 | if (dyn_locks == NULL || i >= sk_CRYPTO_dynlock_num(dyn_locks)) | ||
| 302 | { | ||
| 303 | CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); | ||
| 304 | return; | ||
| 305 | } | ||
| 306 | pointer = sk_CRYPTO_dynlock_value(dyn_locks, i); | ||
| 307 | if (pointer != NULL) | ||
| 308 | { | ||
| 309 | --pointer->references; | ||
| 310 | #ifdef REF_CHECK | ||
| 311 | if (pointer->references < 0) | ||
| 312 | { | ||
| 313 | fprintf(stderr,"CRYPTO_destroy_dynlockid, bad reference count\n"); | ||
| 314 | abort(); | ||
| 315 | } | ||
| 316 | else | ||
| 317 | #endif | ||
| 318 | if (pointer->references <= 0) | ||
| 319 | { | ||
| 320 | (void)sk_CRYPTO_dynlock_set(dyn_locks, i, NULL); | ||
| 321 | } | ||
| 322 | else | ||
| 323 | pointer = NULL; | ||
| 324 | } | ||
| 325 | CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); | ||
| 326 | |||
| 327 | if (pointer) | ||
| 328 | { | ||
| 329 | dynlock_destroy_callback(pointer->data,__FILE__,__LINE__); | ||
| 330 | OPENSSL_free(pointer); | ||
| 331 | } | ||
| 332 | } | ||
| 333 | |||
| 334 | struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i) | ||
| 335 | { | ||
| 336 | CRYPTO_dynlock *pointer = NULL; | ||
| 337 | if (i) | ||
| 338 | i = -i-1; | ||
| 339 | |||
| 340 | CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK); | ||
| 341 | |||
| 342 | if (dyn_locks != NULL && i < sk_CRYPTO_dynlock_num(dyn_locks)) | ||
| 343 | pointer = sk_CRYPTO_dynlock_value(dyn_locks, i); | ||
| 344 | if (pointer) | ||
| 345 | pointer->references++; | ||
| 346 | |||
| 347 | CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); | ||
| 348 | |||
| 349 | if (pointer) | ||
| 350 | return pointer->data; | ||
| 351 | return NULL; | ||
| 352 | } | ||
| 353 | |||
| 354 | struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void)) | ||
| 355 | (const char *file,int line) | ||
| 356 | { | ||
| 357 | return(dynlock_create_callback); | ||
| 358 | } | ||
| 359 | |||
| 360 | void (*CRYPTO_get_dynlock_lock_callback(void))(int mode, | ||
| 361 | struct CRYPTO_dynlock_value *l, const char *file,int line) | ||
| 362 | { | ||
| 363 | return(dynlock_lock_callback); | ||
| 364 | } | ||
| 365 | |||
| 366 | void (*CRYPTO_get_dynlock_destroy_callback(void)) | ||
| 367 | (struct CRYPTO_dynlock_value *l, const char *file,int line) | ||
| 368 | { | ||
| 369 | return(dynlock_destroy_callback); | ||
| 370 | } | ||
| 371 | |||
| 372 | void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(*func) | ||
| 373 | (const char *file, int line)) | ||
| 374 | { | ||
| 375 | dynlock_create_callback=func; | ||
| 376 | } | ||
| 377 | |||
| 378 | static void do_dynlock(int mode, int type, const char *file, int line) | ||
| 379 | { | ||
| 380 | if (dynlock_lock_callback != NULL) | ||
| 381 | { | ||
| 382 | struct CRYPTO_dynlock_value *pointer | ||
| 383 | = CRYPTO_get_dynlock_value(type); | ||
| 384 | |||
| 385 | OPENSSL_assert(pointer != NULL); | ||
| 386 | |||
| 387 | dynlock_lock_callback(mode, pointer, file, line); | ||
| 388 | |||
| 389 | CRYPTO_destroy_dynlockid(type); | ||
| 390 | } | ||
| 391 | } | ||
| 392 | |||
| 393 | void CRYPTO_set_dynlock_lock_callback(void (*func)(int mode, | ||
| 394 | struct CRYPTO_dynlock_value *l, const char *file, int line)) | ||
| 395 | { | ||
| 396 | /* Set callback so CRYPTO_lock() can now handle dynamic locks. | ||
| 397 | * This is OK because at this point and application shouldn't be using | ||
| 398 | * OpenSSL from multiple threads because it is setting up the locking | ||
| 399 | * callbacks. | ||
| 400 | */ | ||
| 401 | static int done = 0; | ||
| 402 | if (!done) | ||
| 403 | { | ||
| 404 | int_CRYPTO_set_do_dynlock_callback(do_dynlock); | ||
| 405 | done = 1; | ||
| 406 | } | ||
| 407 | |||
| 408 | dynlock_lock_callback=func; | ||
| 409 | } | ||
| 410 | |||
| 411 | void CRYPTO_set_dynlock_destroy_callback(void (*func) | ||
| 412 | (struct CRYPTO_dynlock_value *l, const char *file, int line)) | ||
| 413 | { | ||
| 414 | dynlock_destroy_callback=func; | ||
| 415 | } | ||
| 416 | |||
| 417 | const char *CRYPTO_get_lock_name(int type) | ||
| 418 | { | ||
| 419 | if (type < 0) | ||
| 420 | return("dynamic"); | ||
| 421 | else if (type < CRYPTO_NUM_LOCKS) | ||
| 422 | return(lock_names[type]); | ||
| 423 | else if (type-CRYPTO_NUM_LOCKS > sk_num(app_locks)) | ||
| 424 | return("ERROR"); | ||
| 425 | else | ||
| 426 | return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS)); | ||
| 427 | } | ||
| 428 | |||
diff --git a/src/lib/libcrypto/ec/ecp_recp.c b/src/lib/libcrypto/ec/ecp_recp.c deleted file mode 100644 index fec843b5c8..0000000000 --- a/src/lib/libcrypto/ec/ecp_recp.c +++ /dev/null | |||
| @@ -1,133 +0,0 @@ | |||
| 1 | /* crypto/ec/ecp_recp.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | #include "ec_lcl.h" | ||
| 57 | |||
| 58 | #if 0 | ||
| 59 | const EC_METHOD *EC_GFp_recp_method(void) | ||
| 60 | { | ||
| 61 | static const EC_METHOD ret = { | ||
| 62 | ec_GFp_recp_group_init, | ||
| 63 | ec_GFp_recp_group_finish, | ||
| 64 | ec_GFp_recp_group_clear_finish, | ||
| 65 | ec_GFp_recp_group_copy, | ||
| 66 | ec_GFp_recp_group_set_curve_GFp, | ||
| 67 | ec_GFp_simple_group_get_curve_GFp, | ||
| 68 | ec_GFp_simple_group_set_generator, | ||
| 69 | ec_GFp_simple_group_get0_generator, | ||
| 70 | ec_GFp_simple_group_get_order, | ||
| 71 | ec_GFp_simple_group_get_cofactor, | ||
| 72 | ec_GFp_simple_point_init, | ||
| 73 | ec_GFp_simple_point_finish, | ||
| 74 | ec_GFp_simple_point_clear_finish, | ||
| 75 | ec_GFp_simple_point_copy, | ||
| 76 | ec_GFp_simple_point_set_to_infinity, | ||
| 77 | ec_GFp_simple_set_Jprojective_coordinates_GFp, | ||
| 78 | ec_GFp_simple_get_Jprojective_coordinates_GFp, | ||
| 79 | ec_GFp_simple_point_set_affine_coordinates_GFp, | ||
| 80 | ec_GFp_simple_point_get_affine_coordinates_GFp, | ||
| 81 | ec_GFp_simple_set_compressed_coordinates_GFp, | ||
| 82 | ec_GFp_simple_point2oct, | ||
| 83 | ec_GFp_simple_oct2point, | ||
| 84 | ec_GFp_simple_add, | ||
| 85 | ec_GFp_simple_dbl, | ||
| 86 | ec_GFp_simple_invert, | ||
| 87 | ec_GFp_simple_is_at_infinity, | ||
| 88 | ec_GFp_simple_is_on_curve, | ||
| 89 | ec_GFp_simple_cmp, | ||
| 90 | ec_GFp_simple_make_affine, | ||
| 91 | ec_GFp_simple_points_make_affine, | ||
| 92 | ec_GFp_recp_field_mul, | ||
| 93 | ec_GFp_recp_field_sqr, | ||
| 94 | 0 /* field_encode */, | ||
| 95 | 0 /* field_decode */, | ||
| 96 | 0 /* field_set_to_one */ }; | ||
| 97 | |||
| 98 | return &ret; | ||
| 99 | } | ||
| 100 | #endif | ||
| 101 | |||
| 102 | int ec_GFp_recp_group_init(EC_GROUP *group) | ||
| 103 | { | ||
| 104 | int ok; | ||
| 105 | |||
| 106 | ok = ec_GFp_simple_group_init(group); | ||
| 107 | group->field_data1 = NULL; | ||
| 108 | return ok; | ||
| 109 | } | ||
| 110 | |||
| 111 | |||
| 112 | int ec_GFp_recp_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); | ||
| 113 | /* TODO */ | ||
| 114 | |||
| 115 | |||
| 116 | void ec_GFp_recp_group_finish(EC_GROUP *group); | ||
| 117 | /* TODO */ | ||
| 118 | |||
| 119 | |||
| 120 | void ec_GFp_recp_group_clear_finish(EC_GROUP *group); | ||
| 121 | /* TODO */ | ||
| 122 | |||
| 123 | |||
| 124 | int ec_GFp_recp_group_copy(EC_GROUP *dest, const EC_GROUP *src); | ||
| 125 | /* TODO */ | ||
| 126 | |||
| 127 | |||
| 128 | int ec_GFp_recp_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); | ||
| 129 | /* TODO */ | ||
| 130 | |||
| 131 | |||
| 132 | int ec_GFp_recp_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx); | ||
| 133 | /* TODO */ | ||
diff --git a/src/lib/libcrypto/ecdh/Makefile b/src/lib/libcrypto/ecdh/Makefile new file mode 100644 index 0000000000..65d8904ee8 --- /dev/null +++ b/src/lib/libcrypto/ecdh/Makefile | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | # | ||
| 2 | # crypto/ecdh/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= ecdh | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
| 9 | CFLAG=-g -Wall | ||
| 10 | MAKEFILE= Makefile | ||
| 11 | AR= ar r | ||
| 12 | |||
| 13 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 14 | |||
| 15 | GENERAL=Makefile | ||
| 16 | TEST=ecdhtest.c | ||
| 17 | APPS= | ||
| 18 | |||
| 19 | LIB=$(TOP)/libcrypto.a | ||
| 20 | LIBSRC= ech_lib.c ech_ossl.c ech_key.c ech_err.c | ||
| 21 | |||
| 22 | LIBOBJ= ech_lib.o ech_ossl.o ech_key.o ech_err.o | ||
| 23 | |||
| 24 | SRC= $(LIBSRC) | ||
| 25 | |||
| 26 | EXHEADER= ecdh.h | ||
| 27 | HEADER= ech_locl.h $(EXHEADER) | ||
| 28 | |||
| 29 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 30 | |||
| 31 | top: | ||
| 32 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 33 | |||
| 34 | all: lib | ||
| 35 | |||
| 36 | lib: $(LIBOBJ) | ||
| 37 | $(AR) $(LIB) $(LIBOBJ) | ||
| 38 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 39 | @touch lib | ||
| 40 | |||
| 41 | files: | ||
| 42 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 43 | |||
| 44 | links: | ||
| 45 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 46 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 47 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 48 | |||
| 49 | install: | ||
| 50 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 51 | @headerlist="$(EXHEADER)"; for i in $$headerlist; \ | ||
| 52 | do \ | ||
| 53 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 54 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 55 | done; | ||
| 56 | |||
| 57 | tags: | ||
| 58 | ctags $(SRC) | ||
| 59 | |||
| 60 | tests: | ||
| 61 | |||
| 62 | lint: | ||
| 63 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 64 | |||
| 65 | depend: | ||
| 66 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 67 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 68 | |||
| 69 | dclean: | ||
| 70 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 71 | mv -f Makefile.new $(MAKEFILE) | ||
| 72 | |||
| 73 | clean: | ||
| 74 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 75 | |||
| 76 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 77 | |||
| 78 | ech_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 79 | ech_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 80 | ech_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 81 | ech_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 82 | ech_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 83 | ech_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 84 | ech_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 85 | ech_err.o: ech_err.c | ||
| 86 | ech_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 87 | ech_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 88 | ech_key.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 89 | ech_key.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 90 | ech_key.o: ../../include/openssl/engine.h ../../include/openssl/evp.h | ||
| 91 | ech_key.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 92 | ech_key.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 93 | ech_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 94 | ech_key.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 95 | ech_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 96 | ech_key.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 97 | ech_key.o: ../../include/openssl/x509_vfy.h ech_key.c ech_locl.h | ||
| 98 | ech_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 99 | ech_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 100 | ech_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 101 | ech_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 102 | ech_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
| 103 | ech_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 104 | ech_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 105 | ech_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 106 | ech_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 107 | ech_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 108 | ech_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 109 | ech_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 110 | ech_lib.o: ech_lib.c ech_locl.h | ||
| 111 | ech_ossl.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 112 | ech_ossl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 113 | ech_ossl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 114 | ech_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 115 | ech_ossl.o: ../../include/openssl/ecdh.h ../../include/openssl/err.h | ||
| 116 | ech_ossl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 117 | ech_ossl.o: ../../include/openssl/opensslconf.h | ||
| 118 | ech_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 119 | ech_ossl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 120 | ech_ossl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 121 | ech_ossl.o: ../cryptlib.h ech_locl.h ech_ossl.c | ||
diff --git a/src/lib/libcrypto/ecdh/ecdhtest.c b/src/lib/libcrypto/ecdh/ecdhtest.c new file mode 100644 index 0000000000..212a87efa4 --- /dev/null +++ b/src/lib/libcrypto/ecdh/ecdhtest.c | |||
| @@ -0,0 +1,368 @@ | |||
| 1 | /* crypto/ecdh/ecdhtest.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 4 | * | ||
| 5 | * The Elliptic Curve Public-Key Crypto Library (ECC Code) included | ||
| 6 | * herein is developed by SUN MICROSYSTEMS, INC., and is contributed | ||
| 7 | * to the OpenSSL project. | ||
| 8 | * | ||
| 9 | * The ECC Code is licensed pursuant to the OpenSSL open source | ||
| 10 | * license provided below. | ||
| 11 | * | ||
| 12 | * The ECDH software is originally written by Douglas Stebila of | ||
| 13 | * Sun Microsystems Laboratories. | ||
| 14 | * | ||
| 15 | */ | ||
| 16 | /* ==================================================================== | ||
| 17 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. | ||
| 18 | * | ||
| 19 | * Redistribution and use in source and binary forms, with or without | ||
| 20 | * modification, are permitted provided that the following conditions | ||
| 21 | * are met: | ||
| 22 | * | ||
| 23 | * 1. Redistributions of source code must retain the above copyright | ||
| 24 | * notice, this list of conditions and the following disclaimer. | ||
| 25 | * | ||
| 26 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer in | ||
| 28 | * the documentation and/or other materials provided with the | ||
| 29 | * distribution. | ||
| 30 | * | ||
| 31 | * 3. All advertising materials mentioning features or use of this | ||
| 32 | * software must display the following acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 37 | * endorse or promote products derived from this software without | ||
| 38 | * prior written permission. For written permission, please contact | ||
| 39 | * openssl-core@openssl.org. | ||
| 40 | * | ||
| 41 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 42 | * nor may "OpenSSL" appear in their names without prior written | ||
| 43 | * permission of the OpenSSL Project. | ||
| 44 | * | ||
| 45 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 46 | * acknowledgment: | ||
| 47 | * "This product includes software developed by the OpenSSL Project | ||
| 48 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 49 | * | ||
| 50 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 51 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 53 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 54 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 56 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 57 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 59 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 60 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 61 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 62 | * ==================================================================== | ||
| 63 | * | ||
| 64 | * This product includes cryptographic software written by Eric Young | ||
| 65 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 66 | * Hudson (tjh@cryptsoft.com). | ||
| 67 | * | ||
| 68 | */ | ||
| 69 | |||
| 70 | #include <stdio.h> | ||
| 71 | #include <stdlib.h> | ||
| 72 | #include <string.h> | ||
| 73 | |||
| 74 | #include "../e_os.h" | ||
| 75 | |||
| 76 | #include <openssl/opensslconf.h> /* for OPENSSL_NO_ECDH */ | ||
| 77 | #include <openssl/crypto.h> | ||
| 78 | #include <openssl/bio.h> | ||
| 79 | #include <openssl/bn.h> | ||
| 80 | #include <openssl/objects.h> | ||
| 81 | #include <openssl/rand.h> | ||
| 82 | #include <openssl/sha.h> | ||
| 83 | #include <openssl/err.h> | ||
| 84 | |||
| 85 | #ifdef OPENSSL_NO_ECDH | ||
| 86 | int main(int argc, char *argv[]) | ||
| 87 | { | ||
| 88 | printf("No ECDH support\n"); | ||
| 89 | return(0); | ||
| 90 | } | ||
| 91 | #else | ||
| 92 | #include <openssl/ec.h> | ||
| 93 | #include <openssl/ecdh.h> | ||
| 94 | |||
| 95 | #ifdef OPENSSL_SYS_WIN16 | ||
| 96 | #define MS_CALLBACK _far _loadds | ||
| 97 | #else | ||
| 98 | #define MS_CALLBACK | ||
| 99 | #endif | ||
| 100 | |||
| 101 | #if 0 | ||
| 102 | static void MS_CALLBACK cb(int p, int n, void *arg); | ||
| 103 | #endif | ||
| 104 | |||
| 105 | static const char rnd_seed[] = "string to make the random number generator think it has entropy"; | ||
| 106 | |||
| 107 | |||
| 108 | static const int KDF1_SHA1_len = 20; | ||
| 109 | static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen) | ||
| 110 | { | ||
| 111 | #ifndef OPENSSL_NO_SHA | ||
| 112 | if (*outlen < SHA_DIGEST_LENGTH) | ||
| 113 | return NULL; | ||
| 114 | else | ||
| 115 | *outlen = SHA_DIGEST_LENGTH; | ||
| 116 | return SHA1(in, inlen, out); | ||
| 117 | #else | ||
| 118 | return NULL; | ||
| 119 | #endif | ||
| 120 | } | ||
| 121 | |||
| 122 | |||
| 123 | static int test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out) | ||
| 124 | { | ||
| 125 | EC_KEY *a=NULL; | ||
| 126 | EC_KEY *b=NULL; | ||
| 127 | BIGNUM *x_a=NULL, *y_a=NULL, | ||
| 128 | *x_b=NULL, *y_b=NULL; | ||
| 129 | char buf[12]; | ||
| 130 | unsigned char *abuf=NULL,*bbuf=NULL; | ||
| 131 | int i,alen,blen,aout,bout,ret=0; | ||
| 132 | const EC_GROUP *group; | ||
| 133 | |||
| 134 | a = EC_KEY_new_by_curve_name(nid); | ||
| 135 | b = EC_KEY_new_by_curve_name(nid); | ||
| 136 | if (a == NULL || b == NULL) | ||
| 137 | goto err; | ||
| 138 | |||
| 139 | group = EC_KEY_get0_group(a); | ||
| 140 | |||
| 141 | if ((x_a=BN_new()) == NULL) goto err; | ||
| 142 | if ((y_a=BN_new()) == NULL) goto err; | ||
| 143 | if ((x_b=BN_new()) == NULL) goto err; | ||
| 144 | if ((y_b=BN_new()) == NULL) goto err; | ||
| 145 | |||
| 146 | BIO_puts(out,"Testing key generation with "); | ||
| 147 | BIO_puts(out,text); | ||
| 148 | #ifdef NOISY | ||
| 149 | BIO_puts(out,"\n"); | ||
| 150 | #else | ||
| 151 | (void)BIO_flush(out); | ||
| 152 | #endif | ||
| 153 | |||
| 154 | if (!EC_KEY_generate_key(a)) goto err; | ||
| 155 | |||
| 156 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) | ||
| 157 | { | ||
| 158 | if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 159 | EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; | ||
| 160 | } | ||
| 161 | else | ||
| 162 | { | ||
| 163 | if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 164 | EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; | ||
| 165 | } | ||
| 166 | #ifdef NOISY | ||
| 167 | BIO_puts(out," pri 1="); | ||
| 168 | BN_print(out,a->priv_key); | ||
| 169 | BIO_puts(out,"\n pub 1="); | ||
| 170 | BN_print(out,x_a); | ||
| 171 | BIO_puts(out,","); | ||
| 172 | BN_print(out,y_a); | ||
| 173 | BIO_puts(out,"\n"); | ||
| 174 | #else | ||
| 175 | BIO_printf(out," ."); | ||
| 176 | (void)BIO_flush(out); | ||
| 177 | #endif | ||
| 178 | |||
| 179 | if (!EC_KEY_generate_key(b)) goto err; | ||
| 180 | |||
| 181 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) | ||
| 182 | { | ||
| 183 | if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 184 | EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; | ||
| 185 | } | ||
| 186 | else | ||
| 187 | { | ||
| 188 | if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 189 | EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; | ||
| 190 | } | ||
| 191 | |||
| 192 | #ifdef NOISY | ||
| 193 | BIO_puts(out," pri 2="); | ||
| 194 | BN_print(out,b->priv_key); | ||
| 195 | BIO_puts(out,"\n pub 2="); | ||
| 196 | BN_print(out,x_b); | ||
| 197 | BIO_puts(out,","); | ||
| 198 | BN_print(out,y_b); | ||
| 199 | BIO_puts(out,"\n"); | ||
| 200 | #else | ||
| 201 | BIO_printf(out,"."); | ||
| 202 | (void)BIO_flush(out); | ||
| 203 | #endif | ||
| 204 | |||
| 205 | alen=KDF1_SHA1_len; | ||
| 206 | abuf=(unsigned char *)OPENSSL_malloc(alen); | ||
| 207 | aout=ECDH_compute_key(abuf,alen,EC_KEY_get0_public_key(b),a,KDF1_SHA1); | ||
| 208 | |||
| 209 | #ifdef NOISY | ||
| 210 | BIO_puts(out," key1 ="); | ||
| 211 | for (i=0; i<aout; i++) | ||
| 212 | { | ||
| 213 | sprintf(buf,"%02X",abuf[i]); | ||
| 214 | BIO_puts(out,buf); | ||
| 215 | } | ||
| 216 | BIO_puts(out,"\n"); | ||
| 217 | #else | ||
| 218 | BIO_printf(out,"."); | ||
| 219 | (void)BIO_flush(out); | ||
| 220 | #endif | ||
| 221 | |||
| 222 | blen=KDF1_SHA1_len; | ||
| 223 | bbuf=(unsigned char *)OPENSSL_malloc(blen); | ||
| 224 | bout=ECDH_compute_key(bbuf,blen,EC_KEY_get0_public_key(a),b,KDF1_SHA1); | ||
| 225 | |||
| 226 | #ifdef NOISY | ||
| 227 | BIO_puts(out," key2 ="); | ||
| 228 | for (i=0; i<bout; i++) | ||
| 229 | { | ||
| 230 | sprintf(buf,"%02X",bbuf[i]); | ||
| 231 | BIO_puts(out,buf); | ||
| 232 | } | ||
| 233 | BIO_puts(out,"\n"); | ||
| 234 | #else | ||
| 235 | BIO_printf(out,"."); | ||
| 236 | (void)BIO_flush(out); | ||
| 237 | #endif | ||
| 238 | |||
| 239 | if ((aout < 4) || (bout != aout) || (memcmp(abuf,bbuf,aout) != 0)) | ||
| 240 | { | ||
| 241 | #ifndef NOISY | ||
| 242 | BIO_printf(out, " failed\n\n"); | ||
| 243 | BIO_printf(out, "key a:\n"); | ||
| 244 | BIO_printf(out, "private key: "); | ||
| 245 | BN_print(out, EC_KEY_get0_private_key(a)); | ||
| 246 | BIO_printf(out, "\n"); | ||
| 247 | BIO_printf(out, "public key (x,y): "); | ||
| 248 | BN_print(out, x_a); | ||
| 249 | BIO_printf(out, ","); | ||
| 250 | BN_print(out, y_a); | ||
| 251 | BIO_printf(out, "\nkey b:\n"); | ||
| 252 | BIO_printf(out, "private key: "); | ||
| 253 | BN_print(out, EC_KEY_get0_private_key(b)); | ||
| 254 | BIO_printf(out, "\n"); | ||
| 255 | BIO_printf(out, "public key (x,y): "); | ||
| 256 | BN_print(out, x_b); | ||
| 257 | BIO_printf(out, ","); | ||
| 258 | BN_print(out, y_b); | ||
| 259 | BIO_printf(out, "\n"); | ||
| 260 | BIO_printf(out, "generated key a: "); | ||
| 261 | for (i=0; i<bout; i++) | ||
| 262 | { | ||
| 263 | sprintf(buf, "%02X", bbuf[i]); | ||
| 264 | BIO_puts(out, buf); | ||
| 265 | } | ||
| 266 | BIO_printf(out, "\n"); | ||
| 267 | BIO_printf(out, "generated key b: "); | ||
| 268 | for (i=0; i<aout; i++) | ||
| 269 | { | ||
| 270 | sprintf(buf, "%02X", abuf[i]); | ||
| 271 | BIO_puts(out,buf); | ||
| 272 | } | ||
| 273 | BIO_printf(out, "\n"); | ||
| 274 | #endif | ||
| 275 | fprintf(stderr,"Error in ECDH routines\n"); | ||
| 276 | ret=0; | ||
| 277 | } | ||
| 278 | else | ||
| 279 | { | ||
| 280 | #ifndef NOISY | ||
| 281 | BIO_printf(out, " ok\n"); | ||
| 282 | #endif | ||
| 283 | ret=1; | ||
| 284 | } | ||
| 285 | err: | ||
| 286 | ERR_print_errors_fp(stderr); | ||
| 287 | |||
| 288 | if (abuf != NULL) OPENSSL_free(abuf); | ||
| 289 | if (bbuf != NULL) OPENSSL_free(bbuf); | ||
| 290 | if (x_a) BN_free(x_a); | ||
| 291 | if (y_a) BN_free(y_a); | ||
| 292 | if (x_b) BN_free(x_b); | ||
| 293 | if (y_b) BN_free(y_b); | ||
| 294 | if (b) EC_KEY_free(b); | ||
| 295 | if (a) EC_KEY_free(a); | ||
| 296 | return(ret); | ||
| 297 | } | ||
| 298 | |||
| 299 | int main(int argc, char *argv[]) | ||
| 300 | { | ||
| 301 | BN_CTX *ctx=NULL; | ||
| 302 | int ret=1; | ||
| 303 | BIO *out; | ||
| 304 | |||
| 305 | CRYPTO_malloc_debug_init(); | ||
| 306 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | ||
| 307 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
| 308 | |||
| 309 | #ifdef OPENSSL_SYS_WIN32 | ||
| 310 | CRYPTO_malloc_init(); | ||
| 311 | #endif | ||
| 312 | |||
| 313 | RAND_seed(rnd_seed, sizeof rnd_seed); | ||
| 314 | |||
| 315 | out=BIO_new(BIO_s_file()); | ||
| 316 | if (out == NULL) EXIT(1); | ||
| 317 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | ||
| 318 | |||
| 319 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 320 | |||
| 321 | /* NIST PRIME CURVES TESTS */ | ||
| 322 | if (!test_ecdh_curve(NID_X9_62_prime192v1, "NIST Prime-Curve P-192", ctx, out)) goto err; | ||
| 323 | if (!test_ecdh_curve(NID_secp224r1, "NIST Prime-Curve P-224", ctx, out)) goto err; | ||
| 324 | if (!test_ecdh_curve(NID_X9_62_prime256v1, "NIST Prime-Curve P-256", ctx, out)) goto err; | ||
| 325 | if (!test_ecdh_curve(NID_secp384r1, "NIST Prime-Curve P-384", ctx, out)) goto err; | ||
| 326 | if (!test_ecdh_curve(NID_secp521r1, "NIST Prime-Curve P-521", ctx, out)) goto err; | ||
| 327 | /* NIST BINARY CURVES TESTS */ | ||
| 328 | if (!test_ecdh_curve(NID_sect163k1, "NIST Binary-Curve K-163", ctx, out)) goto err; | ||
| 329 | if (!test_ecdh_curve(NID_sect163r2, "NIST Binary-Curve B-163", ctx, out)) goto err; | ||
| 330 | if (!test_ecdh_curve(NID_sect233k1, "NIST Binary-Curve K-233", ctx, out)) goto err; | ||
| 331 | if (!test_ecdh_curve(NID_sect233r1, "NIST Binary-Curve B-233", ctx, out)) goto err; | ||
| 332 | if (!test_ecdh_curve(NID_sect283k1, "NIST Binary-Curve K-283", ctx, out)) goto err; | ||
| 333 | if (!test_ecdh_curve(NID_sect283r1, "NIST Binary-Curve B-283", ctx, out)) goto err; | ||
| 334 | if (!test_ecdh_curve(NID_sect409k1, "NIST Binary-Curve K-409", ctx, out)) goto err; | ||
| 335 | if (!test_ecdh_curve(NID_sect409r1, "NIST Binary-Curve B-409", ctx, out)) goto err; | ||
| 336 | if (!test_ecdh_curve(NID_sect571k1, "NIST Binary-Curve K-571", ctx, out)) goto err; | ||
| 337 | if (!test_ecdh_curve(NID_sect571r1, "NIST Binary-Curve B-571", ctx, out)) goto err; | ||
| 338 | |||
| 339 | ret = 0; | ||
| 340 | |||
| 341 | err: | ||
| 342 | ERR_print_errors_fp(stderr); | ||
| 343 | if (ctx) BN_CTX_free(ctx); | ||
| 344 | BIO_free(out); | ||
| 345 | CRYPTO_cleanup_all_ex_data(); | ||
| 346 | ERR_remove_thread_state(NULL); | ||
| 347 | CRYPTO_mem_leaks_fp(stderr); | ||
| 348 | EXIT(ret); | ||
| 349 | return(ret); | ||
| 350 | } | ||
| 351 | |||
| 352 | #if 0 | ||
| 353 | static void MS_CALLBACK cb(int p, int n, void *arg) | ||
| 354 | { | ||
| 355 | char c='*'; | ||
| 356 | |||
| 357 | if (p == 0) c='.'; | ||
| 358 | if (p == 1) c='+'; | ||
| 359 | if (p == 2) c='*'; | ||
| 360 | if (p == 3) c='\n'; | ||
| 361 | BIO_write((BIO *)arg,&c,1); | ||
| 362 | (void)BIO_flush((BIO *)arg); | ||
| 363 | #ifdef LINT | ||
| 364 | p=n; | ||
| 365 | #endif | ||
| 366 | } | ||
| 367 | #endif | ||
| 368 | #endif | ||
diff --git a/src/lib/libcrypto/ecdh/ech_ossl.c b/src/lib/libcrypto/ecdh/ech_ossl.c new file mode 100644 index 0000000000..2a40ff12df --- /dev/null +++ b/src/lib/libcrypto/ecdh/ech_ossl.c | |||
| @@ -0,0 +1,213 @@ | |||
| 1 | /* crypto/ecdh/ech_ossl.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 4 | * | ||
| 5 | * The Elliptic Curve Public-Key Crypto Library (ECC Code) included | ||
| 6 | * herein is developed by SUN MICROSYSTEMS, INC., and is contributed | ||
| 7 | * to the OpenSSL project. | ||
| 8 | * | ||
| 9 | * The ECC Code is licensed pursuant to the OpenSSL open source | ||
| 10 | * license provided below. | ||
| 11 | * | ||
| 12 | * The ECDH software is originally written by Douglas Stebila of | ||
| 13 | * Sun Microsystems Laboratories. | ||
| 14 | * | ||
| 15 | */ | ||
| 16 | /* ==================================================================== | ||
| 17 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. | ||
| 18 | * | ||
| 19 | * Redistribution and use in source and binary forms, with or without | ||
| 20 | * modification, are permitted provided that the following conditions | ||
| 21 | * are met: | ||
| 22 | * | ||
| 23 | * 1. Redistributions of source code must retain the above copyright | ||
| 24 | * notice, this list of conditions and the following disclaimer. | ||
| 25 | * | ||
| 26 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer in | ||
| 28 | * the documentation and/or other materials provided with the | ||
| 29 | * distribution. | ||
| 30 | * | ||
| 31 | * 3. All advertising materials mentioning features or use of this | ||
| 32 | * software must display the following acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 37 | * endorse or promote products derived from this software without | ||
| 38 | * prior written permission. For written permission, please contact | ||
| 39 | * openssl-core@OpenSSL.org. | ||
| 40 | * | ||
| 41 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 42 | * nor may "OpenSSL" appear in their names without prior written | ||
| 43 | * permission of the OpenSSL Project. | ||
| 44 | * | ||
| 45 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 46 | * acknowledgment: | ||
| 47 | * "This product includes software developed by the OpenSSL Project | ||
| 48 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 49 | * | ||
| 50 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 51 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 53 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 54 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 56 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 57 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 59 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 60 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 61 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 62 | * ==================================================================== | ||
| 63 | * | ||
| 64 | * This product includes cryptographic software written by Eric Young | ||
| 65 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 66 | * Hudson (tjh@cryptsoft.com). | ||
| 67 | * | ||
| 68 | */ | ||
| 69 | |||
| 70 | |||
| 71 | #include <string.h> | ||
| 72 | #include <limits.h> | ||
| 73 | |||
| 74 | #include "cryptlib.h" | ||
| 75 | |||
| 76 | #include "ech_locl.h" | ||
| 77 | #include <openssl/err.h> | ||
| 78 | #include <openssl/sha.h> | ||
| 79 | #include <openssl/obj_mac.h> | ||
| 80 | #include <openssl/bn.h> | ||
| 81 | |||
| 82 | static int ecdh_compute_key(void *out, size_t len, const EC_POINT *pub_key, | ||
| 83 | EC_KEY *ecdh, | ||
| 84 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | ||
| 85 | |||
| 86 | static ECDH_METHOD openssl_ecdh_meth = { | ||
| 87 | "OpenSSL ECDH method", | ||
| 88 | ecdh_compute_key, | ||
| 89 | #if 0 | ||
| 90 | NULL, /* init */ | ||
| 91 | NULL, /* finish */ | ||
| 92 | #endif | ||
| 93 | 0, /* flags */ | ||
| 94 | NULL /* app_data */ | ||
| 95 | }; | ||
| 96 | |||
| 97 | const ECDH_METHOD *ECDH_OpenSSL(void) | ||
| 98 | { | ||
| 99 | return &openssl_ecdh_meth; | ||
| 100 | } | ||
| 101 | |||
| 102 | |||
| 103 | /* This implementation is based on the following primitives in the IEEE 1363 standard: | ||
| 104 | * - ECKAS-DH1 | ||
| 105 | * - ECSVDP-DH | ||
| 106 | * Finally an optional KDF is applied. | ||
| 107 | */ | ||
| 108 | static int ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, | ||
| 109 | EC_KEY *ecdh, | ||
| 110 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) | ||
| 111 | { | ||
| 112 | BN_CTX *ctx; | ||
| 113 | EC_POINT *tmp=NULL; | ||
| 114 | BIGNUM *x=NULL, *y=NULL; | ||
| 115 | const BIGNUM *priv_key; | ||
| 116 | const EC_GROUP* group; | ||
| 117 | int ret= -1; | ||
| 118 | size_t buflen, len; | ||
| 119 | unsigned char *buf=NULL; | ||
| 120 | |||
| 121 | if (outlen > INT_MAX) | ||
| 122 | { | ||
| 123 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); /* sort of, anyway */ | ||
| 124 | return -1; | ||
| 125 | } | ||
| 126 | |||
| 127 | if ((ctx = BN_CTX_new()) == NULL) goto err; | ||
| 128 | BN_CTX_start(ctx); | ||
| 129 | x = BN_CTX_get(ctx); | ||
| 130 | y = BN_CTX_get(ctx); | ||
| 131 | |||
| 132 | priv_key = EC_KEY_get0_private_key(ecdh); | ||
| 133 | if (priv_key == NULL) | ||
| 134 | { | ||
| 135 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_NO_PRIVATE_VALUE); | ||
| 136 | goto err; | ||
| 137 | } | ||
| 138 | |||
| 139 | group = EC_KEY_get0_group(ecdh); | ||
| 140 | if ((tmp=EC_POINT_new(group)) == NULL) | ||
| 141 | { | ||
| 142 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); | ||
| 143 | goto err; | ||
| 144 | } | ||
| 145 | |||
| 146 | if (!EC_POINT_mul(group, tmp, NULL, pub_key, priv_key, ctx)) | ||
| 147 | { | ||
| 148 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
| 149 | goto err; | ||
| 150 | } | ||
| 151 | |||
| 152 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) | ||
| 153 | { | ||
| 154 | if (!EC_POINT_get_affine_coordinates_GFp(group, tmp, x, y, ctx)) | ||
| 155 | { | ||
| 156 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
| 157 | goto err; | ||
| 158 | } | ||
| 159 | } | ||
| 160 | else | ||
| 161 | { | ||
| 162 | if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y, ctx)) | ||
| 163 | { | ||
| 164 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE); | ||
| 165 | goto err; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | buflen = (EC_GROUP_get_degree(group) + 7)/8; | ||
| 170 | len = BN_num_bytes(x); | ||
| 171 | if (len > buflen) | ||
| 172 | { | ||
| 173 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_INTERNAL_ERROR); | ||
| 174 | goto err; | ||
| 175 | } | ||
| 176 | if ((buf = OPENSSL_malloc(buflen)) == NULL) | ||
| 177 | { | ||
| 178 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); | ||
| 179 | goto err; | ||
| 180 | } | ||
| 181 | |||
| 182 | memset(buf, 0, buflen - len); | ||
| 183 | if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) | ||
| 184 | { | ||
| 185 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 186 | goto err; | ||
| 187 | } | ||
| 188 | |||
| 189 | if (KDF != 0) | ||
| 190 | { | ||
| 191 | if (KDF(buf, buflen, out, &outlen) == NULL) | ||
| 192 | { | ||
| 193 | ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_KDF_FAILED); | ||
| 194 | goto err; | ||
| 195 | } | ||
| 196 | ret = outlen; | ||
| 197 | } | ||
| 198 | else | ||
| 199 | { | ||
| 200 | /* no KDF, just copy as much as we can */ | ||
| 201 | if (outlen > buflen) | ||
| 202 | outlen = buflen; | ||
| 203 | memcpy(out, buf, outlen); | ||
| 204 | ret = outlen; | ||
| 205 | } | ||
| 206 | |||
| 207 | err: | ||
| 208 | if (tmp) EC_POINT_free(tmp); | ||
| 209 | if (ctx) BN_CTX_end(ctx); | ||
| 210 | if (ctx) BN_CTX_free(ctx); | ||
| 211 | if (buf) OPENSSL_free(buf); | ||
| 212 | return(ret); | ||
| 213 | } | ||
diff --git a/src/lib/libcrypto/ecdsa/Makefile b/src/lib/libcrypto/ecdsa/Makefile new file mode 100644 index 0000000000..e89e0c010c --- /dev/null +++ b/src/lib/libcrypto/ecdsa/Makefile | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | # | ||
| 2 | # crypto/ecdsa/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= ecdsa | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
| 9 | CFLAG=-g -Wall | ||
| 10 | MAKEFILE= Makefile | ||
| 11 | AR= ar r | ||
| 12 | |||
| 13 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 14 | |||
| 15 | GENERAL=Makefile | ||
| 16 | TEST=ecdsatest.c | ||
| 17 | APPS= | ||
| 18 | |||
| 19 | LIB=$(TOP)/libcrypto.a | ||
| 20 | LIBSRC= ecs_lib.c ecs_asn1.c ecs_ossl.c ecs_sign.c ecs_vrf.c ecs_err.c | ||
| 21 | |||
| 22 | LIBOBJ= ecs_lib.o ecs_asn1.o ecs_ossl.o ecs_sign.o ecs_vrf.o ecs_err.o | ||
| 23 | |||
| 24 | SRC= $(LIBSRC) | ||
| 25 | |||
| 26 | EXHEADER= ecdsa.h | ||
| 27 | HEADER= ecs_locl.h $(EXHEADER) | ||
| 28 | |||
| 29 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 30 | |||
| 31 | top: | ||
| 32 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 33 | |||
| 34 | all: lib | ||
| 35 | |||
| 36 | lib: $(LIBOBJ) | ||
| 37 | $(AR) $(LIB) $(LIBOBJ) | ||
| 38 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 39 | @touch lib | ||
| 40 | |||
| 41 | files: | ||
| 42 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 43 | |||
| 44 | links: | ||
| 45 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 46 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 47 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 48 | |||
| 49 | install: | ||
| 50 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 51 | @headerlist="$(EXHEADER)"; for i in $$headerlist; \ | ||
| 52 | do \ | ||
| 53 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 54 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 55 | done; | ||
| 56 | |||
| 57 | tags: | ||
| 58 | ctags $(SRC) | ||
| 59 | |||
| 60 | tests: | ||
| 61 | |||
| 62 | lint: | ||
| 63 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 64 | |||
| 65 | depend: | ||
| 66 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 67 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 68 | |||
| 69 | dclean: | ||
| 70 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 71 | mv -f Makefile.new $(MAKEFILE) | ||
| 72 | |||
| 73 | clean: | ||
| 74 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 75 | |||
| 76 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 77 | |||
| 78 | ecs_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 79 | ecs_asn1.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
| 80 | ecs_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 81 | ecs_asn1.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 82 | ecs_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 83 | ecs_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 84 | ecs_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 85 | ecs_asn1.o: ../../include/openssl/symhacks.h ecs_asn1.c ecs_locl.h | ||
| 86 | ecs_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 87 | ecs_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 88 | ecs_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdsa.h | ||
| 89 | ecs_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 90 | ecs_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 91 | ecs_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 92 | ecs_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 93 | ecs_err.o: ecs_err.c | ||
| 94 | ecs_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 95 | ecs_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 96 | ecs_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 97 | ecs_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 98 | ecs_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h | ||
| 99 | ecs_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 100 | ecs_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 101 | ecs_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 102 | ecs_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 103 | ecs_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 104 | ecs_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 105 | ecs_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 106 | ecs_lib.o: ../../include/openssl/x509_vfy.h ecs_lib.c ecs_locl.h | ||
| 107 | ecs_ossl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 108 | ecs_ossl.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h | ||
| 109 | ecs_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 110 | ecs_ossl.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 111 | ecs_ossl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 112 | ecs_ossl.o: ../../include/openssl/opensslconf.h | ||
| 113 | ecs_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 114 | ecs_ossl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 115 | ecs_ossl.o: ../../include/openssl/symhacks.h ecs_locl.h ecs_ossl.c | ||
| 116 | ecs_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 117 | ecs_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 118 | ecs_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 119 | ecs_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 120 | ecs_sign.o: ../../include/openssl/engine.h ../../include/openssl/evp.h | ||
| 121 | ecs_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 122 | ecs_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 123 | ecs_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 124 | ecs_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
| 125 | ecs_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 126 | ecs_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 127 | ecs_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 128 | ecs_sign.o: ecs_locl.h ecs_sign.c | ||
| 129 | ecs_vrf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 130 | ecs_vrf.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 131 | ecs_vrf.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 132 | ecs_vrf.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 133 | ecs_vrf.o: ../../include/openssl/engine.h ../../include/openssl/evp.h | ||
| 134 | ecs_vrf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 135 | ecs_vrf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 136 | ecs_vrf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 137 | ecs_vrf.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 138 | ecs_vrf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 139 | ecs_vrf.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 140 | ecs_vrf.o: ../../include/openssl/x509_vfy.h ecs_locl.h ecs_vrf.c | ||
diff --git a/src/lib/libcrypto/ecdsa/ecdsatest.c b/src/lib/libcrypto/ecdsa/ecdsatest.c new file mode 100644 index 0000000000..aa4e1481a8 --- /dev/null +++ b/src/lib/libcrypto/ecdsa/ecdsatest.c | |||
| @@ -0,0 +1,500 @@ | |||
| 1 | /* crypto/ecdsa/ecdsatest.c */ | ||
| 2 | /* | ||
| 3 | * Written by Nils Larsch for the OpenSSL project. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | /* ==================================================================== | ||
| 59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 60 | * | ||
| 61 | * Portions of the attached software ("Contribution") are developed by | ||
| 62 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. | ||
| 63 | * | ||
| 64 | * The Contribution is licensed pursuant to the OpenSSL open source | ||
| 65 | * license provided above. | ||
| 66 | * | ||
| 67 | * The elliptic curve binary polynomial software is originally written by | ||
| 68 | * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. | ||
| 69 | * | ||
| 70 | */ | ||
| 71 | |||
| 72 | #include <stdio.h> | ||
| 73 | #include <stdlib.h> | ||
| 74 | #include <string.h> | ||
| 75 | |||
| 76 | #include <openssl/opensslconf.h> /* To see if OPENSSL_NO_ECDSA is defined */ | ||
| 77 | |||
| 78 | #ifdef OPENSSL_NO_ECDSA | ||
| 79 | int main(int argc, char * argv[]) | ||
| 80 | { | ||
| 81 | puts("Elliptic curves are disabled."); | ||
| 82 | return 0; | ||
| 83 | } | ||
| 84 | #else | ||
| 85 | |||
| 86 | #include <openssl/crypto.h> | ||
| 87 | #include <openssl/bio.h> | ||
| 88 | #include <openssl/evp.h> | ||
| 89 | #include <openssl/bn.h> | ||
| 90 | #include <openssl/ecdsa.h> | ||
| 91 | #ifndef OPENSSL_NO_ENGINE | ||
| 92 | #include <openssl/engine.h> | ||
| 93 | #endif | ||
| 94 | #include <openssl/err.h> | ||
| 95 | #include <openssl/rand.h> | ||
| 96 | |||
| 97 | static const char rnd_seed[] = "string to make the random number generator " | ||
| 98 | "think it has entropy"; | ||
| 99 | |||
| 100 | /* declaration of the test functions */ | ||
| 101 | int x9_62_tests(BIO *); | ||
| 102 | int x9_62_test_internal(BIO *out, int nid, const char *r, const char *s); | ||
| 103 | int test_builtin(BIO *); | ||
| 104 | |||
| 105 | /* functions to change the RAND_METHOD */ | ||
| 106 | int change_rand(void); | ||
| 107 | int restore_rand(void); | ||
| 108 | int fbytes(unsigned char *buf, int num); | ||
| 109 | |||
| 110 | RAND_METHOD fake_rand; | ||
| 111 | const RAND_METHOD *old_rand; | ||
| 112 | |||
| 113 | int change_rand(void) | ||
| 114 | { | ||
| 115 | /* save old rand method */ | ||
| 116 | if ((old_rand = RAND_get_rand_method()) == NULL) | ||
| 117 | return 0; | ||
| 118 | |||
| 119 | fake_rand.seed = old_rand->seed; | ||
| 120 | fake_rand.cleanup = old_rand->cleanup; | ||
| 121 | fake_rand.add = old_rand->add; | ||
| 122 | fake_rand.status = old_rand->status; | ||
| 123 | /* use own random function */ | ||
| 124 | fake_rand.bytes = fbytes; | ||
| 125 | fake_rand.pseudorand = old_rand->bytes; | ||
| 126 | /* set new RAND_METHOD */ | ||
| 127 | if (!RAND_set_rand_method(&fake_rand)) | ||
| 128 | return 0; | ||
| 129 | return 1; | ||
| 130 | } | ||
| 131 | |||
| 132 | int restore_rand(void) | ||
| 133 | { | ||
| 134 | if (!RAND_set_rand_method(old_rand)) | ||
| 135 | return 0; | ||
| 136 | else | ||
| 137 | return 1; | ||
| 138 | } | ||
| 139 | |||
| 140 | static int fbytes_counter = 0; | ||
| 141 | static const char *numbers[8] = { | ||
| 142 | "651056770906015076056810763456358567190100156695615665659", | ||
| 143 | "6140507067065001063065065565667405560006161556565665656654", | ||
| 144 | "8763001015071075675010661307616710783570106710677817767166" | ||
| 145 | "71676178726717", | ||
| 146 | "7000000175690566466555057817571571075705015757757057795755" | ||
| 147 | "55657156756655", | ||
| 148 | "1275552191113212300012030439187146164646146646466749494799", | ||
| 149 | "1542725565216523985789236956265265265235675811949404040041", | ||
| 150 | "1456427555219115346513212300075341203043918714616464614664" | ||
| 151 | "64667494947990", | ||
| 152 | "1712787255652165239672857892369562652652652356758119494040" | ||
| 153 | "40041670216363"}; | ||
| 154 | |||
| 155 | int fbytes(unsigned char *buf, int num) | ||
| 156 | { | ||
| 157 | int ret; | ||
| 158 | BIGNUM *tmp = NULL; | ||
| 159 | |||
| 160 | if (fbytes_counter >= 8) | ||
| 161 | return 0; | ||
| 162 | tmp = BN_new(); | ||
| 163 | if (!tmp) | ||
| 164 | return 0; | ||
| 165 | if (!BN_dec2bn(&tmp, numbers[fbytes_counter])) | ||
| 166 | { | ||
| 167 | BN_free(tmp); | ||
| 168 | return 0; | ||
| 169 | } | ||
| 170 | fbytes_counter ++; | ||
| 171 | ret = BN_bn2bin(tmp, buf); | ||
| 172 | if (ret == 0 || ret != num) | ||
| 173 | ret = 0; | ||
| 174 | else | ||
| 175 | ret = 1; | ||
| 176 | if (tmp) | ||
| 177 | BN_free(tmp); | ||
| 178 | return ret; | ||
| 179 | } | ||
| 180 | |||
| 181 | /* some tests from the X9.62 draft */ | ||
| 182 | int x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in) | ||
| 183 | { | ||
| 184 | int ret = 0; | ||
| 185 | const char message[] = "abc"; | ||
| 186 | unsigned char digest[20]; | ||
| 187 | unsigned int dgst_len = 0; | ||
| 188 | EVP_MD_CTX md_ctx; | ||
| 189 | EC_KEY *key = NULL; | ||
| 190 | ECDSA_SIG *signature = NULL; | ||
| 191 | BIGNUM *r = NULL, *s = NULL; | ||
| 192 | |||
| 193 | EVP_MD_CTX_init(&md_ctx); | ||
| 194 | /* get the message digest */ | ||
| 195 | EVP_DigestInit(&md_ctx, EVP_ecdsa()); | ||
| 196 | EVP_DigestUpdate(&md_ctx, (const void*)message, 3); | ||
| 197 | EVP_DigestFinal(&md_ctx, digest, &dgst_len); | ||
| 198 | |||
| 199 | BIO_printf(out, "testing %s: ", OBJ_nid2sn(nid)); | ||
| 200 | /* create the key */ | ||
| 201 | if ((key = EC_KEY_new_by_curve_name(nid)) == NULL) | ||
| 202 | goto x962_int_err; | ||
| 203 | if (!EC_KEY_generate_key(key)) | ||
| 204 | goto x962_int_err; | ||
| 205 | BIO_printf(out, "."); | ||
| 206 | (void)BIO_flush(out); | ||
| 207 | /* create the signature */ | ||
| 208 | signature = ECDSA_do_sign(digest, 20, key); | ||
| 209 | if (signature == NULL) | ||
| 210 | goto x962_int_err; | ||
| 211 | BIO_printf(out, "."); | ||
| 212 | (void)BIO_flush(out); | ||
| 213 | /* compare the created signature with the expected signature */ | ||
| 214 | if ((r = BN_new()) == NULL || (s = BN_new()) == NULL) | ||
| 215 | goto x962_int_err; | ||
| 216 | if (!BN_dec2bn(&r, r_in) || | ||
| 217 | !BN_dec2bn(&s, s_in)) | ||
| 218 | goto x962_int_err; | ||
| 219 | if (BN_cmp(signature->r ,r) || BN_cmp(signature->s, s)) | ||
| 220 | goto x962_int_err; | ||
| 221 | BIO_printf(out, "."); | ||
| 222 | (void)BIO_flush(out); | ||
| 223 | /* verify the signature */ | ||
| 224 | if (ECDSA_do_verify(digest, 20, signature, key) != 1) | ||
| 225 | goto x962_int_err; | ||
| 226 | BIO_printf(out, "."); | ||
| 227 | (void)BIO_flush(out); | ||
| 228 | |||
| 229 | BIO_printf(out, " ok\n"); | ||
| 230 | ret = 1; | ||
| 231 | x962_int_err: | ||
| 232 | if (!ret) | ||
| 233 | BIO_printf(out, " failed\n"); | ||
| 234 | if (key) | ||
| 235 | EC_KEY_free(key); | ||
| 236 | if (signature) | ||
| 237 | ECDSA_SIG_free(signature); | ||
| 238 | if (r) | ||
| 239 | BN_free(r); | ||
| 240 | if (s) | ||
| 241 | BN_free(s); | ||
| 242 | EVP_MD_CTX_cleanup(&md_ctx); | ||
| 243 | return ret; | ||
| 244 | } | ||
| 245 | |||
| 246 | int x9_62_tests(BIO *out) | ||
| 247 | { | ||
| 248 | int ret = 0; | ||
| 249 | |||
| 250 | BIO_printf(out, "some tests from X9.62:\n"); | ||
| 251 | |||
| 252 | /* set own rand method */ | ||
| 253 | if (!change_rand()) | ||
| 254 | goto x962_err; | ||
| 255 | |||
| 256 | if (!x9_62_test_internal(out, NID_X9_62_prime192v1, | ||
| 257 | "3342403536405981729393488334694600415596881826869351677613", | ||
| 258 | "5735822328888155254683894997897571951568553642892029982342")) | ||
| 259 | goto x962_err; | ||
| 260 | if (!x9_62_test_internal(out, NID_X9_62_prime239v1, | ||
| 261 | "3086361431751678114926225473006680188549593787585317781474" | ||
| 262 | "62058306432176", | ||
| 263 | "3238135532097973577080787768312505059318910517550078427819" | ||
| 264 | "78505179448783")) | ||
| 265 | goto x962_err; | ||
| 266 | if (!x9_62_test_internal(out, NID_X9_62_c2tnb191v1, | ||
| 267 | "87194383164871543355722284926904419997237591535066528048", | ||
| 268 | "308992691965804947361541664549085895292153777025772063598")) | ||
| 269 | goto x962_err; | ||
| 270 | if (!x9_62_test_internal(out, NID_X9_62_c2tnb239v1, | ||
| 271 | "2159633321041961198501834003903461262881815148684178964245" | ||
| 272 | "5876922391552", | ||
| 273 | "1970303740007316867383349976549972270528498040721988191026" | ||
| 274 | "49413465737174")) | ||
| 275 | goto x962_err; | ||
| 276 | |||
| 277 | ret = 1; | ||
| 278 | x962_err: | ||
| 279 | if (!restore_rand()) | ||
| 280 | ret = 0; | ||
| 281 | return ret; | ||
| 282 | } | ||
| 283 | |||
| 284 | int test_builtin(BIO *out) | ||
| 285 | { | ||
| 286 | EC_builtin_curve *curves = NULL; | ||
| 287 | size_t crv_len = 0, n = 0; | ||
| 288 | EC_KEY *eckey = NULL, *wrong_eckey = NULL; | ||
| 289 | EC_GROUP *group; | ||
| 290 | unsigned char digest[20], wrong_digest[20]; | ||
| 291 | unsigned char *signature = NULL; | ||
| 292 | unsigned int sig_len; | ||
| 293 | int nid, ret = 0; | ||
| 294 | |||
| 295 | /* fill digest values with some random data */ | ||
| 296 | if (!RAND_pseudo_bytes(digest, 20) || | ||
| 297 | !RAND_pseudo_bytes(wrong_digest, 20)) | ||
| 298 | { | ||
| 299 | BIO_printf(out, "ERROR: unable to get random data\n"); | ||
| 300 | goto builtin_err; | ||
| 301 | } | ||
| 302 | |||
| 303 | /* create and verify a ecdsa signature with every availble curve | ||
| 304 | * (with ) */ | ||
| 305 | BIO_printf(out, "\ntesting ECDSA_sign() and ECDSA_verify() " | ||
| 306 | "with some internal curves:\n"); | ||
| 307 | |||
| 308 | /* get a list of all internal curves */ | ||
| 309 | crv_len = EC_get_builtin_curves(NULL, 0); | ||
| 310 | |||
| 311 | curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len); | ||
| 312 | |||
| 313 | if (curves == NULL) | ||
| 314 | { | ||
| 315 | BIO_printf(out, "malloc error\n"); | ||
| 316 | goto builtin_err; | ||
| 317 | } | ||
| 318 | |||
| 319 | if (!EC_get_builtin_curves(curves, crv_len)) | ||
| 320 | { | ||
| 321 | BIO_printf(out, "unable to get internal curves\n"); | ||
| 322 | goto builtin_err; | ||
| 323 | } | ||
| 324 | |||
| 325 | /* now create and verify a signature for every curve */ | ||
| 326 | for (n = 0; n < crv_len; n++) | ||
| 327 | { | ||
| 328 | unsigned char dirt, offset; | ||
| 329 | |||
| 330 | nid = curves[n].nid; | ||
| 331 | if (nid == NID_ipsec4) | ||
| 332 | continue; | ||
| 333 | /* create new ecdsa key (== EC_KEY) */ | ||
| 334 | if ((eckey = EC_KEY_new()) == NULL) | ||
| 335 | goto builtin_err; | ||
| 336 | group = EC_GROUP_new_by_curve_name(nid); | ||
| 337 | if (group == NULL) | ||
| 338 | goto builtin_err; | ||
| 339 | if (EC_KEY_set_group(eckey, group) == 0) | ||
| 340 | goto builtin_err; | ||
| 341 | EC_GROUP_free(group); | ||
| 342 | if (EC_GROUP_get_degree(EC_KEY_get0_group(eckey)) < 160) | ||
| 343 | /* drop the curve */ | ||
| 344 | { | ||
| 345 | EC_KEY_free(eckey); | ||
| 346 | eckey = NULL; | ||
| 347 | continue; | ||
| 348 | } | ||
| 349 | BIO_printf(out, "%s: ", OBJ_nid2sn(nid)); | ||
| 350 | /* create key */ | ||
| 351 | if (!EC_KEY_generate_key(eckey)) | ||
| 352 | { | ||
| 353 | BIO_printf(out, " failed\n"); | ||
| 354 | goto builtin_err; | ||
| 355 | } | ||
| 356 | /* create second key */ | ||
| 357 | if ((wrong_eckey = EC_KEY_new()) == NULL) | ||
| 358 | goto builtin_err; | ||
| 359 | group = EC_GROUP_new_by_curve_name(nid); | ||
| 360 | if (group == NULL) | ||
| 361 | goto builtin_err; | ||
| 362 | if (EC_KEY_set_group(wrong_eckey, group) == 0) | ||
| 363 | goto builtin_err; | ||
| 364 | EC_GROUP_free(group); | ||
| 365 | if (!EC_KEY_generate_key(wrong_eckey)) | ||
| 366 | { | ||
| 367 | BIO_printf(out, " failed\n"); | ||
| 368 | goto builtin_err; | ||
| 369 | } | ||
| 370 | |||
| 371 | BIO_printf(out, "."); | ||
| 372 | (void)BIO_flush(out); | ||
| 373 | /* check key */ | ||
| 374 | if (!EC_KEY_check_key(eckey)) | ||
| 375 | { | ||
| 376 | BIO_printf(out, " failed\n"); | ||
| 377 | goto builtin_err; | ||
| 378 | } | ||
| 379 | BIO_printf(out, "."); | ||
| 380 | (void)BIO_flush(out); | ||
| 381 | /* create signature */ | ||
| 382 | sig_len = ECDSA_size(eckey); | ||
| 383 | if ((signature = OPENSSL_malloc(sig_len)) == NULL) | ||
| 384 | goto builtin_err; | ||
| 385 | if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey)) | ||
| 386 | { | ||
| 387 | BIO_printf(out, " failed\n"); | ||
| 388 | goto builtin_err; | ||
| 389 | } | ||
| 390 | BIO_printf(out, "."); | ||
| 391 | (void)BIO_flush(out); | ||
| 392 | /* verify signature */ | ||
| 393 | if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1) | ||
| 394 | { | ||
| 395 | BIO_printf(out, " failed\n"); | ||
| 396 | goto builtin_err; | ||
| 397 | } | ||
| 398 | BIO_printf(out, "."); | ||
| 399 | (void)BIO_flush(out); | ||
| 400 | /* verify signature with the wrong key */ | ||
| 401 | if (ECDSA_verify(0, digest, 20, signature, sig_len, | ||
| 402 | wrong_eckey) == 1) | ||
| 403 | { | ||
| 404 | BIO_printf(out, " failed\n"); | ||
| 405 | goto builtin_err; | ||
| 406 | } | ||
| 407 | BIO_printf(out, "."); | ||
| 408 | (void)BIO_flush(out); | ||
| 409 | /* wrong digest */ | ||
| 410 | if (ECDSA_verify(0, wrong_digest, 20, signature, sig_len, | ||
| 411 | eckey) == 1) | ||
| 412 | { | ||
| 413 | BIO_printf(out, " failed\n"); | ||
| 414 | goto builtin_err; | ||
| 415 | } | ||
| 416 | BIO_printf(out, "."); | ||
| 417 | (void)BIO_flush(out); | ||
| 418 | /* modify a single byte of the signature */ | ||
| 419 | offset = signature[10] % sig_len; | ||
| 420 | dirt = signature[11]; | ||
| 421 | signature[offset] ^= dirt ? dirt : 1; | ||
| 422 | if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1) | ||
| 423 | { | ||
| 424 | BIO_printf(out, " failed\n"); | ||
| 425 | goto builtin_err; | ||
| 426 | } | ||
| 427 | BIO_printf(out, "."); | ||
| 428 | (void)BIO_flush(out); | ||
| 429 | |||
| 430 | BIO_printf(out, " ok\n"); | ||
| 431 | /* cleanup */ | ||
| 432 | OPENSSL_free(signature); | ||
| 433 | signature = NULL; | ||
| 434 | EC_KEY_free(eckey); | ||
| 435 | eckey = NULL; | ||
| 436 | EC_KEY_free(wrong_eckey); | ||
| 437 | wrong_eckey = NULL; | ||
| 438 | } | ||
| 439 | |||
| 440 | ret = 1; | ||
| 441 | builtin_err: | ||
| 442 | if (eckey) | ||
| 443 | EC_KEY_free(eckey); | ||
| 444 | if (wrong_eckey) | ||
| 445 | EC_KEY_free(wrong_eckey); | ||
| 446 | if (signature) | ||
| 447 | OPENSSL_free(signature); | ||
| 448 | if (curves) | ||
| 449 | OPENSSL_free(curves); | ||
| 450 | |||
| 451 | return ret; | ||
| 452 | } | ||
| 453 | |||
| 454 | int main(void) | ||
| 455 | { | ||
| 456 | int ret = 1; | ||
| 457 | BIO *out; | ||
| 458 | |||
| 459 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | ||
| 460 | |||
| 461 | /* enable memory leak checking unless explicitly disabled */ | ||
| 462 | if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && | ||
| 463 | (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) | ||
| 464 | { | ||
| 465 | CRYPTO_malloc_debug_init(); | ||
| 466 | CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); | ||
| 467 | } | ||
| 468 | else | ||
| 469 | { | ||
| 470 | /* OPENSSL_DEBUG_MEMORY=off */ | ||
| 471 | CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0); | ||
| 472 | } | ||
| 473 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
| 474 | |||
| 475 | ERR_load_crypto_strings(); | ||
| 476 | |||
| 477 | /* initialize the prng */ | ||
| 478 | RAND_seed(rnd_seed, sizeof(rnd_seed)); | ||
| 479 | |||
| 480 | /* the tests */ | ||
| 481 | if (!x9_62_tests(out)) goto err; | ||
| 482 | if (!test_builtin(out)) goto err; | ||
| 483 | |||
| 484 | ret = 0; | ||
| 485 | err: | ||
| 486 | if (ret) | ||
| 487 | BIO_printf(out, "\nECDSA test failed\n"); | ||
| 488 | else | ||
| 489 | BIO_printf(out, "\nECDSA test passed\n"); | ||
| 490 | if (ret) | ||
| 491 | ERR_print_errors(out); | ||
| 492 | CRYPTO_cleanup_all_ex_data(); | ||
| 493 | ERR_remove_thread_state(NULL); | ||
| 494 | ERR_free_strings(); | ||
| 495 | CRYPTO_mem_leaks(out); | ||
| 496 | if (out != NULL) | ||
| 497 | BIO_free(out); | ||
| 498 | return ret; | ||
| 499 | } | ||
| 500 | #endif | ||
diff --git a/src/lib/libcrypto/engine/hw.ec b/src/lib/libcrypto/engine/hw.ec deleted file mode 100644 index 5481a43918..0000000000 --- a/src/lib/libcrypto/engine/hw.ec +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | L AEPHK hw_aep_err.h hw_aep_err.c | ||
| 2 | L ATALLA hw_atalla_err.h hw_atalla_err.c | ||
| 3 | L CSWIFT hw_cswift_err.h hw_cswift_err.c | ||
| 4 | L HWCRHK hw_ncipher_err.h hw_ncipher_err.c | ||
| 5 | L NURON hw_nuron_err.h hw_nuron_err.c | ||
| 6 | L SUREWARE hw_sureware_err.h hw_sureware_err.c | ||
| 7 | L UBSEC hw_ubsec_err.h hw_ubsec_err.c | ||
| 8 | L CCA4758 hw_4758_cca_err.h hw_4758_cca_err.c | ||
diff --git a/src/lib/libcrypto/engine/hw_4758_cca.c b/src/lib/libcrypto/engine/hw_4758_cca.c deleted file mode 100644 index 4f5ae8a46d..0000000000 --- a/src/lib/libcrypto/engine/hw_4758_cca.c +++ /dev/null | |||
| @@ -1,969 +0,0 @@ | |||
| 1 | /* Author: Maurice Gittens <maurice@gittens.nl> */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * licensing@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | #include <stdio.h> | ||
| 57 | #include <openssl/crypto.h> | ||
| 58 | /* #include <openssl/pem.h> */ | ||
| 59 | #include "cryptlib.h" | ||
| 60 | #include <openssl/dso.h> | ||
| 61 | #include <openssl/x509.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | #include <openssl/engine.h> | ||
| 64 | |||
| 65 | #ifndef OPENSSL_NO_HW | ||
| 66 | #ifndef OPENSSL_NO_HW_4758_CCA | ||
| 67 | |||
| 68 | #ifdef FLAT_INC | ||
| 69 | #include "hw_4758_cca.h" | ||
| 70 | #else | ||
| 71 | #include "vendor_defns/hw_4758_cca.h" | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #include "hw_4758_cca_err.c" | ||
| 75 | |||
| 76 | static int ibm_4758_cca_destroy(ENGINE *e); | ||
| 77 | static int ibm_4758_cca_init(ENGINE *e); | ||
| 78 | static int ibm_4758_cca_finish(ENGINE *e); | ||
| 79 | static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
| 80 | |||
| 81 | /* rsa functions */ | ||
| 82 | /*---------------*/ | ||
| 83 | #ifndef OPENSSL_NO_RSA | ||
| 84 | static int cca_rsa_pub_enc(int flen, const unsigned char *from, | ||
| 85 | unsigned char *to, RSA *rsa,int padding); | ||
| 86 | static int cca_rsa_priv_dec(int flen, const unsigned char *from, | ||
| 87 | unsigned char *to, RSA *rsa,int padding); | ||
| 88 | static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len, | ||
| 89 | unsigned char *sigret, unsigned int *siglen, const RSA *rsa); | ||
| 90 | static int cca_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len, | ||
| 91 | unsigned char *sigbuf, unsigned int siglen, const RSA *rsa); | ||
| 92 | |||
| 93 | /* utility functions */ | ||
| 94 | /*-----------------------*/ | ||
| 95 | static EVP_PKEY *ibm_4758_load_privkey(ENGINE*, const char*, | ||
| 96 | UI_METHOD *ui_method, void *callback_data); | ||
| 97 | static EVP_PKEY *ibm_4758_load_pubkey(ENGINE*, const char*, | ||
| 98 | UI_METHOD *ui_method, void *callback_data); | ||
| 99 | |||
| 100 | static int getModulusAndExponent(const unsigned char *token, long *exponentLength, | ||
| 101 | unsigned char *exponent, long *modulusLength, | ||
| 102 | long *modulusFieldLength, unsigned char *modulus); | ||
| 103 | #endif | ||
| 104 | |||
| 105 | /* RAND number functions */ | ||
| 106 | /*-----------------------*/ | ||
| 107 | static int cca_get_random_bytes(unsigned char*, int ); | ||
| 108 | static int cca_random_status(void); | ||
| 109 | |||
| 110 | static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
| 111 | int idx,long argl, void *argp); | ||
| 112 | |||
| 113 | /* Function pointers for CCA verbs */ | ||
| 114 | /*---------------------------------*/ | ||
| 115 | #ifndef OPENSSL_NO_RSA | ||
| 116 | static F_KEYRECORDREAD keyRecordRead; | ||
| 117 | static F_DIGITALSIGNATUREGENERATE digitalSignatureGenerate; | ||
| 118 | static F_DIGITALSIGNATUREVERIFY digitalSignatureVerify; | ||
| 119 | static F_PUBLICKEYEXTRACT publicKeyExtract; | ||
| 120 | static F_PKAENCRYPT pkaEncrypt; | ||
| 121 | static F_PKADECRYPT pkaDecrypt; | ||
| 122 | #endif | ||
| 123 | static F_RANDOMNUMBERGENERATE randomNumberGenerate; | ||
| 124 | |||
| 125 | /* static variables */ | ||
| 126 | /*------------------*/ | ||
| 127 | static const char *CCA4758_LIB_NAME = NULL; | ||
| 128 | static const char *get_CCA4758_LIB_NAME(void) | ||
| 129 | { | ||
| 130 | if(CCA4758_LIB_NAME) | ||
| 131 | return CCA4758_LIB_NAME; | ||
| 132 | return CCA_LIB_NAME; | ||
| 133 | } | ||
| 134 | static void free_CCA4758_LIB_NAME(void) | ||
| 135 | { | ||
| 136 | if(CCA4758_LIB_NAME) | ||
| 137 | OPENSSL_free((void*)CCA4758_LIB_NAME); | ||
| 138 | CCA4758_LIB_NAME = NULL; | ||
| 139 | } | ||
| 140 | static long set_CCA4758_LIB_NAME(const char *name) | ||
| 141 | { | ||
| 142 | free_CCA4758_LIB_NAME(); | ||
| 143 | return (((CCA4758_LIB_NAME = BUF_strdup(name)) != NULL) ? 1 : 0); | ||
| 144 | } | ||
| 145 | #ifndef OPENSSL_NO_RSA | ||
| 146 | static const char* n_keyRecordRead = CSNDKRR; | ||
| 147 | static const char* n_digitalSignatureGenerate = CSNDDSG; | ||
| 148 | static const char* n_digitalSignatureVerify = CSNDDSV; | ||
| 149 | static const char* n_publicKeyExtract = CSNDPKX; | ||
| 150 | static const char* n_pkaEncrypt = CSNDPKE; | ||
| 151 | static const char* n_pkaDecrypt = CSNDPKD; | ||
| 152 | #endif | ||
| 153 | static const char* n_randomNumberGenerate = CSNBRNG; | ||
| 154 | |||
| 155 | static int hndidx = -1; | ||
| 156 | static DSO *dso = NULL; | ||
| 157 | |||
| 158 | /* openssl engine initialization structures */ | ||
| 159 | /*------------------------------------------*/ | ||
| 160 | |||
| 161 | #define CCA4758_CMD_SO_PATH ENGINE_CMD_BASE | ||
| 162 | static const ENGINE_CMD_DEFN cca4758_cmd_defns[] = { | ||
| 163 | {CCA4758_CMD_SO_PATH, | ||
| 164 | "SO_PATH", | ||
| 165 | "Specifies the path to the '4758cca' shared library", | ||
| 166 | ENGINE_CMD_FLAG_STRING}, | ||
| 167 | {0, NULL, NULL, 0} | ||
| 168 | }; | ||
| 169 | |||
| 170 | #ifndef OPENSSL_NO_RSA | ||
| 171 | static RSA_METHOD ibm_4758_cca_rsa = | ||
| 172 | { | ||
| 173 | "IBM 4758 CCA RSA method", | ||
| 174 | cca_rsa_pub_enc, | ||
| 175 | NULL, | ||
| 176 | NULL, | ||
| 177 | cca_rsa_priv_dec, | ||
| 178 | NULL, /*rsa_mod_exp,*/ | ||
| 179 | NULL, /*mod_exp_mont,*/ | ||
| 180 | NULL, /* init */ | ||
| 181 | NULL, /* finish */ | ||
| 182 | RSA_FLAG_SIGN_VER, /* flags */ | ||
| 183 | NULL, /* app_data */ | ||
| 184 | cca_rsa_sign, /* rsa_sign */ | ||
| 185 | cca_rsa_verify /* rsa_verify */ | ||
| 186 | }; | ||
| 187 | #endif | ||
| 188 | |||
| 189 | static RAND_METHOD ibm_4758_cca_rand = | ||
| 190 | { | ||
| 191 | /* "IBM 4758 RAND method", */ | ||
| 192 | NULL, /* seed */ | ||
| 193 | cca_get_random_bytes, /* get random bytes from the card */ | ||
| 194 | NULL, /* cleanup */ | ||
| 195 | NULL, /* add */ | ||
| 196 | cca_get_random_bytes, /* pseudo rand */ | ||
| 197 | cca_random_status, /* status */ | ||
| 198 | }; | ||
| 199 | |||
| 200 | static const char *engine_4758_cca_id = "4758cca"; | ||
| 201 | static const char *engine_4758_cca_name = "IBM 4758 CCA hardware engine support"; | ||
| 202 | |||
| 203 | /* engine implementation */ | ||
| 204 | /*-----------------------*/ | ||
| 205 | static int bind_helper(ENGINE *e) | ||
| 206 | { | ||
| 207 | if(!ENGINE_set_id(e, engine_4758_cca_id) || | ||
| 208 | !ENGINE_set_name(e, engine_4758_cca_name) || | ||
| 209 | #ifndef OPENSSL_NO_RSA | ||
| 210 | !ENGINE_set_RSA(e, &ibm_4758_cca_rsa) || | ||
| 211 | #endif | ||
| 212 | !ENGINE_set_RAND(e, &ibm_4758_cca_rand) || | ||
| 213 | !ENGINE_set_destroy_function(e, ibm_4758_cca_destroy) || | ||
| 214 | !ENGINE_set_init_function(e, ibm_4758_cca_init) || | ||
| 215 | !ENGINE_set_finish_function(e, ibm_4758_cca_finish) || | ||
| 216 | !ENGINE_set_ctrl_function(e, ibm_4758_cca_ctrl) || | ||
| 217 | !ENGINE_set_load_privkey_function(e, ibm_4758_load_privkey) || | ||
| 218 | !ENGINE_set_load_pubkey_function(e, ibm_4758_load_pubkey) || | ||
| 219 | !ENGINE_set_cmd_defns(e, cca4758_cmd_defns)) | ||
| 220 | return 0; | ||
| 221 | /* Ensure the error handling is set up */ | ||
| 222 | ERR_load_CCA4758_strings(); | ||
| 223 | return 1; | ||
| 224 | } | ||
| 225 | |||
| 226 | #ifndef ENGINE_DYNAMIC_SUPPORT | ||
| 227 | static ENGINE *engine_4758_cca(void) | ||
| 228 | { | ||
| 229 | ENGINE *ret = ENGINE_new(); | ||
| 230 | if(!ret) | ||
| 231 | return NULL; | ||
| 232 | if(!bind_helper(ret)) | ||
| 233 | { | ||
| 234 | ENGINE_free(ret); | ||
| 235 | return NULL; | ||
| 236 | } | ||
| 237 | return ret; | ||
| 238 | } | ||
| 239 | |||
| 240 | void ENGINE_load_4758cca(void) | ||
| 241 | { | ||
| 242 | ENGINE *e_4758 = engine_4758_cca(); | ||
| 243 | if (!e_4758) return; | ||
| 244 | ENGINE_add(e_4758); | ||
| 245 | ENGINE_free(e_4758); | ||
| 246 | ERR_clear_error(); | ||
| 247 | } | ||
| 248 | #endif | ||
| 249 | |||
| 250 | static int ibm_4758_cca_destroy(ENGINE *e) | ||
| 251 | { | ||
| 252 | ERR_unload_CCA4758_strings(); | ||
| 253 | free_CCA4758_LIB_NAME(); | ||
| 254 | return 1; | ||
| 255 | } | ||
| 256 | |||
| 257 | static int ibm_4758_cca_init(ENGINE *e) | ||
| 258 | { | ||
| 259 | if(dso) | ||
| 260 | { | ||
| 261 | CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_ALREADY_LOADED); | ||
| 262 | goto err; | ||
| 263 | } | ||
| 264 | |||
| 265 | dso = DSO_load(NULL, get_CCA4758_LIB_NAME(), NULL, 0); | ||
| 266 | if(!dso) | ||
| 267 | { | ||
| 268 | CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE); | ||
| 269 | goto err; | ||
| 270 | } | ||
| 271 | |||
| 272 | #ifndef OPENSSL_NO_RSA | ||
| 273 | if(!(keyRecordRead = (F_KEYRECORDREAD) | ||
| 274 | DSO_bind_func(dso, n_keyRecordRead)) || | ||
| 275 | !(randomNumberGenerate = (F_RANDOMNUMBERGENERATE) | ||
| 276 | DSO_bind_func(dso, n_randomNumberGenerate)) || | ||
| 277 | !(digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE) | ||
| 278 | DSO_bind_func(dso, n_digitalSignatureGenerate)) || | ||
| 279 | !(digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY) | ||
| 280 | DSO_bind_func(dso, n_digitalSignatureVerify)) || | ||
| 281 | !(publicKeyExtract = (F_PUBLICKEYEXTRACT) | ||
| 282 | DSO_bind_func(dso, n_publicKeyExtract)) || | ||
| 283 | !(pkaEncrypt = (F_PKAENCRYPT) | ||
| 284 | DSO_bind_func(dso, n_pkaEncrypt)) || | ||
| 285 | !(pkaDecrypt = (F_PKADECRYPT) | ||
| 286 | DSO_bind_func(dso, n_pkaDecrypt))) | ||
| 287 | { | ||
| 288 | CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE); | ||
| 289 | goto err; | ||
| 290 | } | ||
| 291 | #else | ||
| 292 | if(!(randomNumberGenerate = (F_RANDOMNUMBERGENERATE) | ||
| 293 | DSO_bind_func(dso, n_randomNumberGenerate))) | ||
| 294 | { | ||
| 295 | CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE); | ||
| 296 | goto err; | ||
| 297 | } | ||
| 298 | #endif | ||
| 299 | |||
| 300 | hndidx = RSA_get_ex_new_index(0, "IBM 4758 CCA RSA key handle", | ||
| 301 | NULL, NULL, cca_ex_free); | ||
| 302 | |||
| 303 | return 1; | ||
| 304 | err: | ||
| 305 | if(dso) | ||
| 306 | DSO_free(dso); | ||
| 307 | dso = NULL; | ||
| 308 | |||
| 309 | keyRecordRead = (F_KEYRECORDREAD)0; | ||
| 310 | randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0; | ||
| 311 | digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0; | ||
| 312 | digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)0; | ||
| 313 | publicKeyExtract = (F_PUBLICKEYEXTRACT)0; | ||
| 314 | pkaEncrypt = (F_PKAENCRYPT)0; | ||
| 315 | pkaDecrypt = (F_PKADECRYPT)0; | ||
| 316 | return 0; | ||
| 317 | } | ||
| 318 | |||
| 319 | static int ibm_4758_cca_finish(ENGINE *e) | ||
| 320 | { | ||
| 321 | free_CCA4758_LIB_NAME(); | ||
| 322 | if(!dso) | ||
| 323 | { | ||
| 324 | CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH, | ||
| 325 | CCA4758_R_NOT_LOADED); | ||
| 326 | return 0; | ||
| 327 | } | ||
| 328 | if(!DSO_free(dso)) | ||
| 329 | { | ||
| 330 | CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH, | ||
| 331 | CCA4758_R_UNIT_FAILURE); | ||
| 332 | return 0; | ||
| 333 | } | ||
| 334 | dso = NULL; | ||
| 335 | keyRecordRead = (F_KEYRECORDREAD)0; | ||
| 336 | randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0; | ||
| 337 | digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0; | ||
| 338 | digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)0; | ||
| 339 | publicKeyExtract = (F_PUBLICKEYEXTRACT)0; | ||
| 340 | pkaEncrypt = (F_PKAENCRYPT)0; | ||
| 341 | pkaDecrypt = (F_PKADECRYPT)0; | ||
| 342 | return 1; | ||
| 343 | } | ||
| 344 | |||
| 345 | static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
| 346 | { | ||
| 347 | int initialised = ((dso == NULL) ? 0 : 1); | ||
| 348 | switch(cmd) | ||
| 349 | { | ||
| 350 | case CCA4758_CMD_SO_PATH: | ||
| 351 | if(p == NULL) | ||
| 352 | { | ||
| 353 | CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL, | ||
| 354 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 355 | return 0; | ||
| 356 | } | ||
| 357 | if(initialised) | ||
| 358 | { | ||
| 359 | CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL, | ||
| 360 | CCA4758_R_ALREADY_LOADED); | ||
| 361 | return 0; | ||
| 362 | } | ||
| 363 | return set_CCA4758_LIB_NAME((const char *)p); | ||
| 364 | default: | ||
| 365 | break; | ||
| 366 | } | ||
| 367 | CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL, | ||
| 368 | CCA4758_R_COMMAND_NOT_IMPLEMENTED); | ||
| 369 | return 0; | ||
| 370 | } | ||
| 371 | |||
| 372 | #ifndef OPENSSL_NO_RSA | ||
| 373 | |||
| 374 | #define MAX_CCA_PKA_TOKEN_SIZE 2500 | ||
| 375 | |||
| 376 | static EVP_PKEY *ibm_4758_load_privkey(ENGINE* e, const char* key_id, | ||
| 377 | UI_METHOD *ui_method, void *callback_data) | ||
| 378 | { | ||
| 379 | RSA *rtmp = NULL; | ||
| 380 | EVP_PKEY *res = NULL; | ||
| 381 | unsigned char* keyToken = NULL; | ||
| 382 | unsigned char pubKeyToken[MAX_CCA_PKA_TOKEN_SIZE]; | ||
| 383 | long pubKeyTokenLength = MAX_CCA_PKA_TOKEN_SIZE; | ||
| 384 | long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE; | ||
| 385 | long returnCode; | ||
| 386 | long reasonCode; | ||
| 387 | long exitDataLength = 0; | ||
| 388 | long ruleArrayLength = 0; | ||
| 389 | unsigned char exitData[8]; | ||
| 390 | unsigned char ruleArray[8]; | ||
| 391 | unsigned char keyLabel[64]; | ||
| 392 | long keyLabelLength = strlen(key_id); | ||
| 393 | unsigned char modulus[256]; | ||
| 394 | long modulusFieldLength = sizeof(modulus); | ||
| 395 | long modulusLength = 0; | ||
| 396 | unsigned char exponent[256]; | ||
| 397 | long exponentLength = sizeof(exponent); | ||
| 398 | |||
| 399 | if (keyLabelLength > sizeof(keyLabel)) | ||
| 400 | { | ||
| 401 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
| 402 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
| 403 | return NULL; | ||
| 404 | } | ||
| 405 | |||
| 406 | memset(keyLabel,' ', sizeof(keyLabel)); | ||
| 407 | memcpy(keyLabel, key_id, keyLabelLength); | ||
| 408 | |||
| 409 | keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long)); | ||
| 410 | if (!keyToken) | ||
| 411 | { | ||
| 412 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
| 413 | ERR_R_MALLOC_FAILURE); | ||
| 414 | goto err; | ||
| 415 | } | ||
| 416 | |||
| 417 | keyRecordRead(&returnCode, &reasonCode, &exitDataLength, | ||
| 418 | exitData, &ruleArrayLength, ruleArray, keyLabel, | ||
| 419 | &keyTokenLength, keyToken+sizeof(long)); | ||
| 420 | |||
| 421 | if (returnCode) | ||
| 422 | { | ||
| 423 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
| 424 | CCA4758_R_FAILED_LOADING_PRIVATE_KEY); | ||
| 425 | goto err; | ||
| 426 | } | ||
| 427 | |||
| 428 | publicKeyExtract(&returnCode, &reasonCode, &exitDataLength, | ||
| 429 | exitData, &ruleArrayLength, ruleArray, &keyTokenLength, | ||
| 430 | keyToken+sizeof(long), &pubKeyTokenLength, pubKeyToken); | ||
| 431 | |||
| 432 | if (returnCode) | ||
| 433 | { | ||
| 434 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
| 435 | CCA4758_R_FAILED_LOADING_PRIVATE_KEY); | ||
| 436 | goto err; | ||
| 437 | } | ||
| 438 | |||
| 439 | if (!getModulusAndExponent(pubKeyToken, &exponentLength, | ||
| 440 | exponent, &modulusLength, &modulusFieldLength, | ||
| 441 | modulus)) | ||
| 442 | { | ||
| 443 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
| 444 | CCA4758_R_FAILED_LOADING_PRIVATE_KEY); | ||
| 445 | goto err; | ||
| 446 | } | ||
| 447 | |||
| 448 | (*(long*)keyToken) = keyTokenLength; | ||
| 449 | rtmp = RSA_new_method(e); | ||
| 450 | RSA_set_ex_data(rtmp, hndidx, (char *)keyToken); | ||
| 451 | |||
| 452 | rtmp->e = BN_bin2bn(exponent, exponentLength, NULL); | ||
| 453 | rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL); | ||
| 454 | rtmp->flags |= RSA_FLAG_EXT_PKEY; | ||
| 455 | |||
| 456 | res = EVP_PKEY_new(); | ||
| 457 | EVP_PKEY_assign_RSA(res, rtmp); | ||
| 458 | |||
| 459 | return res; | ||
| 460 | err: | ||
| 461 | if (keyToken) | ||
| 462 | OPENSSL_free(keyToken); | ||
| 463 | if (res) | ||
| 464 | EVP_PKEY_free(res); | ||
| 465 | if (rtmp) | ||
| 466 | RSA_free(rtmp); | ||
| 467 | return NULL; | ||
| 468 | } | ||
| 469 | |||
| 470 | static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id, | ||
| 471 | UI_METHOD *ui_method, void *callback_data) | ||
| 472 | { | ||
| 473 | RSA *rtmp = NULL; | ||
| 474 | EVP_PKEY *res = NULL; | ||
| 475 | unsigned char* keyToken = NULL; | ||
| 476 | long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE; | ||
| 477 | long returnCode; | ||
| 478 | long reasonCode; | ||
| 479 | long exitDataLength = 0; | ||
| 480 | long ruleArrayLength = 0; | ||
| 481 | unsigned char exitData[8]; | ||
| 482 | unsigned char ruleArray[8]; | ||
| 483 | unsigned char keyLabel[64]; | ||
| 484 | long keyLabelLength = strlen(key_id); | ||
| 485 | unsigned char modulus[512]; | ||
| 486 | long modulusFieldLength = sizeof(modulus); | ||
| 487 | long modulusLength = 0; | ||
| 488 | unsigned char exponent[512]; | ||
| 489 | long exponentLength = sizeof(exponent); | ||
| 490 | |||
| 491 | if (keyLabelLength > sizeof(keyLabel)) | ||
| 492 | { | ||
| 493 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
| 494 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
| 495 | return NULL; | ||
| 496 | } | ||
| 497 | |||
| 498 | memset(keyLabel,' ', sizeof(keyLabel)); | ||
| 499 | memcpy(keyLabel, key_id, keyLabelLength); | ||
| 500 | |||
| 501 | keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long)); | ||
| 502 | if (!keyToken) | ||
| 503 | { | ||
| 504 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY, | ||
| 505 | ERR_R_MALLOC_FAILURE); | ||
| 506 | goto err; | ||
| 507 | } | ||
| 508 | |||
| 509 | keyRecordRead(&returnCode, &reasonCode, &exitDataLength, exitData, | ||
| 510 | &ruleArrayLength, ruleArray, keyLabel, &keyTokenLength, | ||
| 511 | keyToken+sizeof(long)); | ||
| 512 | |||
| 513 | if (returnCode) | ||
| 514 | { | ||
| 515 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
| 516 | ERR_R_MALLOC_FAILURE); | ||
| 517 | goto err; | ||
| 518 | } | ||
| 519 | |||
| 520 | if (!getModulusAndExponent(keyToken+sizeof(long), &exponentLength, | ||
| 521 | exponent, &modulusLength, &modulusFieldLength, modulus)) | ||
| 522 | { | ||
| 523 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
| 524 | CCA4758_R_FAILED_LOADING_PUBLIC_KEY); | ||
| 525 | goto err; | ||
| 526 | } | ||
| 527 | |||
| 528 | (*(long*)keyToken) = keyTokenLength; | ||
| 529 | rtmp = RSA_new_method(e); | ||
| 530 | RSA_set_ex_data(rtmp, hndidx, (char *)keyToken); | ||
| 531 | rtmp->e = BN_bin2bn(exponent, exponentLength, NULL); | ||
| 532 | rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL); | ||
| 533 | rtmp->flags |= RSA_FLAG_EXT_PKEY; | ||
| 534 | res = EVP_PKEY_new(); | ||
| 535 | EVP_PKEY_assign_RSA(res, rtmp); | ||
| 536 | |||
| 537 | return res; | ||
| 538 | err: | ||
| 539 | if (keyToken) | ||
| 540 | OPENSSL_free(keyToken); | ||
| 541 | if (res) | ||
| 542 | EVP_PKEY_free(res); | ||
| 543 | if (rtmp) | ||
| 544 | RSA_free(rtmp); | ||
| 545 | return NULL; | ||
| 546 | } | ||
| 547 | |||
| 548 | static int cca_rsa_pub_enc(int flen, const unsigned char *from, | ||
| 549 | unsigned char *to, RSA *rsa,int padding) | ||
| 550 | { | ||
| 551 | long returnCode; | ||
| 552 | long reasonCode; | ||
| 553 | long lflen = flen; | ||
| 554 | long exitDataLength = 0; | ||
| 555 | unsigned char exitData[8]; | ||
| 556 | long ruleArrayLength = 1; | ||
| 557 | unsigned char ruleArray[8] = "PKCS-1.2"; | ||
| 558 | long dataStructureLength = 0; | ||
| 559 | unsigned char dataStructure[8]; | ||
| 560 | long outputLength = RSA_size(rsa); | ||
| 561 | long keyTokenLength; | ||
| 562 | unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx); | ||
| 563 | |||
| 564 | keyTokenLength = *(long*)keyToken; | ||
| 565 | keyToken+=sizeof(long); | ||
| 566 | |||
| 567 | pkaEncrypt(&returnCode, &reasonCode, &exitDataLength, exitData, | ||
| 568 | &ruleArrayLength, ruleArray, &lflen, (unsigned char*)from, | ||
| 569 | &dataStructureLength, dataStructure, &keyTokenLength, | ||
| 570 | keyToken, &outputLength, to); | ||
| 571 | |||
| 572 | if (returnCode || reasonCode) | ||
| 573 | return -(returnCode << 16 | reasonCode); | ||
| 574 | return outputLength; | ||
| 575 | } | ||
| 576 | |||
| 577 | static int cca_rsa_priv_dec(int flen, const unsigned char *from, | ||
| 578 | unsigned char *to, RSA *rsa,int padding) | ||
| 579 | { | ||
| 580 | long returnCode; | ||
| 581 | long reasonCode; | ||
| 582 | long lflen = flen; | ||
| 583 | long exitDataLength = 0; | ||
| 584 | unsigned char exitData[8]; | ||
| 585 | long ruleArrayLength = 1; | ||
| 586 | unsigned char ruleArray[8] = "PKCS-1.2"; | ||
| 587 | long dataStructureLength = 0; | ||
| 588 | unsigned char dataStructure[8]; | ||
| 589 | long outputLength = RSA_size(rsa); | ||
| 590 | long keyTokenLength; | ||
| 591 | unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx); | ||
| 592 | |||
| 593 | keyTokenLength = *(long*)keyToken; | ||
| 594 | keyToken+=sizeof(long); | ||
| 595 | |||
| 596 | pkaDecrypt(&returnCode, &reasonCode, &exitDataLength, exitData, | ||
| 597 | &ruleArrayLength, ruleArray, &lflen, (unsigned char*)from, | ||
| 598 | &dataStructureLength, dataStructure, &keyTokenLength, | ||
| 599 | keyToken, &outputLength, to); | ||
| 600 | |||
| 601 | return (returnCode | reasonCode) ? 0 : 1; | ||
| 602 | } | ||
| 603 | |||
| 604 | #define SSL_SIG_LEN 36 | ||
| 605 | |||
| 606 | static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len, | ||
| 607 | unsigned char *sigbuf, unsigned int siglen, const RSA *rsa) | ||
| 608 | { | ||
| 609 | long returnCode; | ||
| 610 | long reasonCode; | ||
| 611 | long lsiglen = siglen; | ||
| 612 | long exitDataLength = 0; | ||
| 613 | unsigned char exitData[8]; | ||
| 614 | long ruleArrayLength = 1; | ||
| 615 | unsigned char ruleArray[8] = "PKCS-1.1"; | ||
| 616 | long keyTokenLength; | ||
| 617 | unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx); | ||
| 618 | long length = SSL_SIG_LEN; | ||
| 619 | long keyLength ; | ||
| 620 | unsigned char *hashBuffer = NULL; | ||
| 621 | X509_SIG sig; | ||
| 622 | ASN1_TYPE parameter; | ||
| 623 | X509_ALGOR algorithm; | ||
| 624 | ASN1_OCTET_STRING digest; | ||
| 625 | |||
| 626 | keyTokenLength = *(long*)keyToken; | ||
| 627 | keyToken+=sizeof(long); | ||
| 628 | |||
| 629 | if (type == NID_md5 || type == NID_sha1) | ||
| 630 | { | ||
| 631 | sig.algor = &algorithm; | ||
| 632 | algorithm.algorithm = OBJ_nid2obj(type); | ||
| 633 | |||
| 634 | if (!algorithm.algorithm) | ||
| 635 | { | ||
| 636 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
| 637 | CCA4758_R_UNKNOWN_ALGORITHM_TYPE); | ||
| 638 | return 0; | ||
| 639 | } | ||
| 640 | |||
| 641 | if (!algorithm.algorithm->length) | ||
| 642 | { | ||
| 643 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
| 644 | CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD); | ||
| 645 | return 0; | ||
| 646 | } | ||
| 647 | |||
| 648 | parameter.type = V_ASN1_NULL; | ||
| 649 | parameter.value.ptr = NULL; | ||
| 650 | algorithm.parameter = ¶meter; | ||
| 651 | |||
| 652 | sig.digest = &digest; | ||
| 653 | sig.digest->data = (unsigned char*)m; | ||
| 654 | sig.digest->length = m_len; | ||
| 655 | |||
| 656 | length = i2d_X509_SIG(&sig, NULL); | ||
| 657 | } | ||
| 658 | |||
| 659 | keyLength = RSA_size(rsa); | ||
| 660 | |||
| 661 | if (length - RSA_PKCS1_PADDING > keyLength) | ||
| 662 | { | ||
| 663 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
| 664 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
| 665 | return 0; | ||
| 666 | } | ||
| 667 | |||
| 668 | switch (type) | ||
| 669 | { | ||
| 670 | case NID_md5_sha1 : | ||
| 671 | if (m_len != SSL_SIG_LEN) | ||
| 672 | { | ||
| 673 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
| 674 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
| 675 | return 0; | ||
| 676 | } | ||
| 677 | |||
| 678 | hashBuffer = (unsigned char *)m; | ||
| 679 | length = m_len; | ||
| 680 | break; | ||
| 681 | case NID_md5 : | ||
| 682 | { | ||
| 683 | unsigned char *ptr; | ||
| 684 | ptr = hashBuffer = OPENSSL_malloc( | ||
| 685 | (unsigned int)keyLength+1); | ||
| 686 | if (!hashBuffer) | ||
| 687 | { | ||
| 688 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
| 689 | ERR_R_MALLOC_FAILURE); | ||
| 690 | return 0; | ||
| 691 | } | ||
| 692 | |||
| 693 | i2d_X509_SIG(&sig, &ptr); | ||
| 694 | } | ||
| 695 | break; | ||
| 696 | case NID_sha1 : | ||
| 697 | { | ||
| 698 | unsigned char *ptr; | ||
| 699 | ptr = hashBuffer = OPENSSL_malloc( | ||
| 700 | (unsigned int)keyLength+1); | ||
| 701 | if (!hashBuffer) | ||
| 702 | { | ||
| 703 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
| 704 | ERR_R_MALLOC_FAILURE); | ||
| 705 | return 0; | ||
| 706 | } | ||
| 707 | i2d_X509_SIG(&sig, &ptr); | ||
| 708 | } | ||
| 709 | break; | ||
| 710 | default: | ||
| 711 | return 0; | ||
| 712 | } | ||
| 713 | |||
| 714 | digitalSignatureVerify(&returnCode, &reasonCode, &exitDataLength, | ||
| 715 | exitData, &ruleArrayLength, ruleArray, &keyTokenLength, | ||
| 716 | keyToken, &length, hashBuffer, &lsiglen, sigbuf); | ||
| 717 | |||
| 718 | if (type == NID_sha1 || type == NID_md5) | ||
| 719 | { | ||
| 720 | OPENSSL_cleanse(hashBuffer, keyLength+1); | ||
| 721 | OPENSSL_free(hashBuffer); | ||
| 722 | } | ||
| 723 | |||
| 724 | return ((returnCode || reasonCode) ? 0 : 1); | ||
| 725 | } | ||
| 726 | |||
| 727 | #define SSL_SIG_LEN 36 | ||
| 728 | |||
| 729 | static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len, | ||
| 730 | unsigned char *sigret, unsigned int *siglen, const RSA *rsa) | ||
| 731 | { | ||
| 732 | long returnCode; | ||
| 733 | long reasonCode; | ||
| 734 | long exitDataLength = 0; | ||
| 735 | unsigned char exitData[8]; | ||
| 736 | long ruleArrayLength = 1; | ||
| 737 | unsigned char ruleArray[8] = "PKCS-1.1"; | ||
| 738 | long outputLength=256; | ||
| 739 | long outputBitLength; | ||
| 740 | long keyTokenLength; | ||
| 741 | unsigned char *hashBuffer = NULL; | ||
| 742 | unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx); | ||
| 743 | long length = SSL_SIG_LEN; | ||
| 744 | long keyLength ; | ||
| 745 | X509_SIG sig; | ||
| 746 | ASN1_TYPE parameter; | ||
| 747 | X509_ALGOR algorithm; | ||
| 748 | ASN1_OCTET_STRING digest; | ||
| 749 | |||
| 750 | keyTokenLength = *(long*)keyToken; | ||
| 751 | keyToken+=sizeof(long); | ||
| 752 | |||
| 753 | if (type == NID_md5 || type == NID_sha1) | ||
| 754 | { | ||
| 755 | sig.algor = &algorithm; | ||
| 756 | algorithm.algorithm = OBJ_nid2obj(type); | ||
| 757 | |||
| 758 | if (!algorithm.algorithm) | ||
| 759 | { | ||
| 760 | CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, | ||
| 761 | CCA4758_R_UNKNOWN_ALGORITHM_TYPE); | ||
| 762 | return 0; | ||
| 763 | } | ||
| 764 | |||
| 765 | if (!algorithm.algorithm->length) | ||
| 766 | { | ||
| 767 | CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, | ||
| 768 | CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD); | ||
| 769 | return 0; | ||
| 770 | } | ||
| 771 | |||
| 772 | parameter.type = V_ASN1_NULL; | ||
| 773 | parameter.value.ptr = NULL; | ||
| 774 | algorithm.parameter = ¶meter; | ||
| 775 | |||
| 776 | sig.digest = &digest; | ||
| 777 | sig.digest->data = (unsigned char*)m; | ||
| 778 | sig.digest->length = m_len; | ||
| 779 | |||
| 780 | length = i2d_X509_SIG(&sig, NULL); | ||
| 781 | } | ||
| 782 | |||
| 783 | keyLength = RSA_size(rsa); | ||
| 784 | |||
| 785 | if (length - RSA_PKCS1_PADDING > keyLength) | ||
| 786 | { | ||
| 787 | CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, | ||
| 788 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
| 789 | return 0; | ||
| 790 | } | ||
| 791 | |||
| 792 | switch (type) | ||
| 793 | { | ||
| 794 | case NID_md5_sha1 : | ||
| 795 | if (m_len != SSL_SIG_LEN) | ||
| 796 | { | ||
| 797 | CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, | ||
| 798 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
| 799 | return 0; | ||
| 800 | } | ||
| 801 | hashBuffer = (unsigned char*)m; | ||
| 802 | length = m_len; | ||
| 803 | break; | ||
| 804 | case NID_md5 : | ||
| 805 | { | ||
| 806 | unsigned char *ptr; | ||
| 807 | ptr = hashBuffer = OPENSSL_malloc( | ||
| 808 | (unsigned int)keyLength+1); | ||
| 809 | if (!hashBuffer) | ||
| 810 | { | ||
| 811 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
| 812 | ERR_R_MALLOC_FAILURE); | ||
| 813 | return 0; | ||
| 814 | } | ||
| 815 | i2d_X509_SIG(&sig, &ptr); | ||
| 816 | } | ||
| 817 | break; | ||
| 818 | case NID_sha1 : | ||
| 819 | { | ||
| 820 | unsigned char *ptr; | ||
| 821 | ptr = hashBuffer = OPENSSL_malloc( | ||
| 822 | (unsigned int)keyLength+1); | ||
| 823 | if (!hashBuffer) | ||
| 824 | { | ||
| 825 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
| 826 | ERR_R_MALLOC_FAILURE); | ||
| 827 | return 0; | ||
| 828 | } | ||
| 829 | i2d_X509_SIG(&sig, &ptr); | ||
| 830 | } | ||
| 831 | break; | ||
| 832 | default: | ||
| 833 | return 0; | ||
| 834 | } | ||
| 835 | |||
| 836 | digitalSignatureGenerate(&returnCode, &reasonCode, &exitDataLength, | ||
| 837 | exitData, &ruleArrayLength, ruleArray, &keyTokenLength, | ||
| 838 | keyToken, &length, hashBuffer, &outputLength, &outputBitLength, | ||
| 839 | sigret); | ||
| 840 | |||
| 841 | if (type == NID_sha1 || type == NID_md5) | ||
| 842 | { | ||
| 843 | OPENSSL_cleanse(hashBuffer, keyLength+1); | ||
| 844 | OPENSSL_free(hashBuffer); | ||
| 845 | } | ||
| 846 | |||
| 847 | *siglen = outputLength; | ||
| 848 | |||
| 849 | return ((returnCode || reasonCode) ? 0 : 1); | ||
| 850 | } | ||
| 851 | |||
| 852 | static int getModulusAndExponent(const unsigned char*token, long *exponentLength, | ||
| 853 | unsigned char *exponent, long *modulusLength, long *modulusFieldLength, | ||
| 854 | unsigned char *modulus) | ||
| 855 | { | ||
| 856 | unsigned long len; | ||
| 857 | |||
| 858 | if (*token++ != (char)0x1E) /* internal PKA token? */ | ||
| 859 | return 0; | ||
| 860 | |||
| 861 | if (*token++) /* token version must be zero */ | ||
| 862 | return 0; | ||
| 863 | |||
| 864 | len = *token++; | ||
| 865 | len = len << 8; | ||
| 866 | len |= (unsigned char)*token++; | ||
| 867 | |||
| 868 | token += 4; /* skip reserved bytes */ | ||
| 869 | |||
| 870 | if (*token++ == (char)0x04) | ||
| 871 | { | ||
| 872 | if (*token++) /* token version must be zero */ | ||
| 873 | return 0; | ||
| 874 | |||
| 875 | len = *token++; | ||
| 876 | len = len << 8; | ||
| 877 | len |= (unsigned char)*token++; | ||
| 878 | |||
| 879 | token+=2; /* skip reserved section */ | ||
| 880 | |||
| 881 | len = *token++; | ||
| 882 | len = len << 8; | ||
| 883 | len |= (unsigned char)*token++; | ||
| 884 | |||
| 885 | *exponentLength = len; | ||
| 886 | |||
| 887 | len = *token++; | ||
| 888 | len = len << 8; | ||
| 889 | len |= (unsigned char)*token++; | ||
| 890 | |||
| 891 | *modulusLength = len; | ||
| 892 | |||
| 893 | len = *token++; | ||
| 894 | len = len << 8; | ||
| 895 | len |= (unsigned char)*token++; | ||
| 896 | |||
| 897 | *modulusFieldLength = len; | ||
| 898 | |||
| 899 | memcpy(exponent, token, *exponentLength); | ||
| 900 | token+= *exponentLength; | ||
| 901 | |||
| 902 | memcpy(modulus, token, *modulusFieldLength); | ||
| 903 | return 1; | ||
| 904 | } | ||
| 905 | return 0; | ||
| 906 | } | ||
| 907 | |||
| 908 | #endif /* OPENSSL_NO_RSA */ | ||
| 909 | |||
| 910 | static int cca_random_status(void) | ||
| 911 | { | ||
| 912 | return 1; | ||
| 913 | } | ||
| 914 | |||
| 915 | static int cca_get_random_bytes(unsigned char* buf, int num) | ||
| 916 | { | ||
| 917 | long ret_code; | ||
| 918 | long reason_code; | ||
| 919 | long exit_data_length; | ||
| 920 | unsigned char exit_data[4]; | ||
| 921 | unsigned char form[] = "RANDOM "; | ||
| 922 | unsigned char rand_buf[8]; | ||
| 923 | |||
| 924 | while(num >= sizeof(rand_buf)) | ||
| 925 | { | ||
| 926 | randomNumberGenerate(&ret_code, &reason_code, &exit_data_length, | ||
| 927 | exit_data, form, rand_buf); | ||
| 928 | if (ret_code) | ||
| 929 | return 0; | ||
| 930 | num -= sizeof(rand_buf); | ||
| 931 | memcpy(buf, rand_buf, sizeof(rand_buf)); | ||
| 932 | buf += sizeof(rand_buf); | ||
| 933 | } | ||
| 934 | |||
| 935 | if (num) | ||
| 936 | { | ||
| 937 | randomNumberGenerate(&ret_code, &reason_code, NULL, NULL, | ||
| 938 | form, rand_buf); | ||
| 939 | if (ret_code) | ||
| 940 | return 0; | ||
| 941 | memcpy(buf, rand_buf, num); | ||
| 942 | } | ||
| 943 | |||
| 944 | return 1; | ||
| 945 | } | ||
| 946 | |||
| 947 | static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, int idx, | ||
| 948 | long argl, void *argp) | ||
| 949 | { | ||
| 950 | if (item) | ||
| 951 | OPENSSL_free(item); | ||
| 952 | } | ||
| 953 | |||
| 954 | /* Goo to handle building as a dynamic engine */ | ||
| 955 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
| 956 | static int bind_fn(ENGINE *e, const char *id) | ||
| 957 | { | ||
| 958 | if(id && (strcmp(id, engine_4758_cca_id) != 0)) | ||
| 959 | return 0; | ||
| 960 | if(!bind_helper(e)) | ||
| 961 | return 0; | ||
| 962 | return 1; | ||
| 963 | } | ||
| 964 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
| 965 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | ||
| 966 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | ||
| 967 | |||
| 968 | #endif /* !OPENSSL_NO_HW_4758_CCA */ | ||
| 969 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_aep.c b/src/lib/libcrypto/engine/hw_aep.c deleted file mode 100644 index 5f1772ea99..0000000000 --- a/src/lib/libcrypto/engine/hw_aep.c +++ /dev/null | |||
| @@ -1,1120 +0,0 @@ | |||
| 1 | /* crypto/engine/hw_aep.c */ | ||
| 2 | /* | ||
| 3 | */ | ||
| 4 | /* ==================================================================== | ||
| 5 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * | ||
| 14 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 15 | * notice, this list of conditions and the following disclaimer in | ||
| 16 | * the documentation and/or other materials provided with the | ||
| 17 | * distribution. | ||
| 18 | * | ||
| 19 | * 3. All advertising materials mentioning features or use of this | ||
| 20 | * software must display the following acknowledgment: | ||
| 21 | * "This product includes software developed by the OpenSSL Project | ||
| 22 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 23 | * | ||
| 24 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 25 | * endorse or promote products derived from this software without | ||
| 26 | * prior written permission. For written permission, please contact | ||
| 27 | * licensing@OpenSSL.org. | ||
| 28 | * | ||
| 29 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 30 | * nor may "OpenSSL" appear in their names without prior written | ||
| 31 | * permission of the OpenSSL Project. | ||
| 32 | * | ||
| 33 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 34 | * acknowledgment: | ||
| 35 | * "This product includes software developed by the OpenSSL Project | ||
| 36 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 37 | * | ||
| 38 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 39 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 40 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 41 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 42 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 44 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 45 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 46 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 47 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 48 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 49 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 50 | * ==================================================================== | ||
| 51 | * | ||
| 52 | * This product includes cryptographic software written by Eric Young | ||
| 53 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 54 | * Hudson (tjh@cryptsoft.com). | ||
| 55 | * | ||
| 56 | */ | ||
| 57 | |||
| 58 | #include <stdio.h> | ||
| 59 | #include <openssl/bn.h> | ||
| 60 | #include <string.h> | ||
| 61 | |||
| 62 | #include <openssl/e_os2.h> | ||
| 63 | #if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__) | ||
| 64 | #include <sys/types.h> | ||
| 65 | #include <unistd.h> | ||
| 66 | #else | ||
| 67 | #include <process.h> | ||
| 68 | typedef int pid_t; | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #include <openssl/crypto.h> | ||
| 72 | #include <openssl/dso.h> | ||
| 73 | #include <openssl/engine.h> | ||
| 74 | #include <openssl/buffer.h> | ||
| 75 | |||
| 76 | #ifndef OPENSSL_NO_HW | ||
| 77 | #ifndef OPENSSL_NO_HW_AEP | ||
| 78 | #ifdef FLAT_INC | ||
| 79 | #include "aep.h" | ||
| 80 | #else | ||
| 81 | #include "vendor_defns/aep.h" | ||
| 82 | #endif | ||
| 83 | |||
| 84 | #define AEP_LIB_NAME "aep engine" | ||
| 85 | #define FAIL_TO_SW 0x10101010 | ||
| 86 | |||
| 87 | #include "hw_aep_err.c" | ||
| 88 | |||
| 89 | static int aep_init(ENGINE *e); | ||
| 90 | static int aep_finish(ENGINE *e); | ||
| 91 | static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
| 92 | static int aep_destroy(ENGINE *e); | ||
| 93 | |||
| 94 | static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR hConnection); | ||
| 95 | static AEP_RV aep_return_connection(AEP_CONNECTION_HNDL hConnection); | ||
| 96 | static AEP_RV aep_close_connection(AEP_CONNECTION_HNDL hConnection); | ||
| 97 | static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use); | ||
| 98 | |||
| 99 | /* BIGNUM stuff */ | ||
| 100 | static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 101 | const BIGNUM *m, BN_CTX *ctx); | ||
| 102 | |||
| 103 | static AEP_RV aep_mod_exp_crt(BIGNUM *r,const BIGNUM *a, const BIGNUM *p, | ||
| 104 | const BIGNUM *q, const BIGNUM *dmp1,const BIGNUM *dmq1, | ||
| 105 | const BIGNUM *iqmp, BN_CTX *ctx); | ||
| 106 | |||
| 107 | /* RSA stuff */ | ||
| 108 | #ifndef OPENSSL_NO_RSA | ||
| 109 | static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa); | ||
| 110 | #endif | ||
| 111 | |||
| 112 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
| 113 | static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 114 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 115 | |||
| 116 | /* DSA stuff */ | ||
| 117 | #ifndef OPENSSL_NO_DSA | ||
| 118 | static int aep_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
| 119 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
| 120 | BN_CTX *ctx, BN_MONT_CTX *in_mont); | ||
| 121 | |||
| 122 | static int aep_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
| 123 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 124 | BN_MONT_CTX *m_ctx); | ||
| 125 | #endif | ||
| 126 | |||
| 127 | /* DH stuff */ | ||
| 128 | /* This function is aliased to mod_exp (with the DH and mont dropped). */ | ||
| 129 | #ifndef OPENSSL_NO_DH | ||
| 130 | static int aep_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 131 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 132 | #endif | ||
| 133 | |||
| 134 | /* rand stuff */ | ||
| 135 | #ifdef AEPRAND | ||
| 136 | static int aep_rand(unsigned char *buf, int num); | ||
| 137 | static int aep_rand_status(void); | ||
| 138 | #endif | ||
| 139 | |||
| 140 | /* Bignum conversion stuff */ | ||
| 141 | static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize); | ||
| 142 | static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize, | ||
| 143 | unsigned char* AEP_BigNum); | ||
| 144 | static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize, | ||
| 145 | unsigned char* AEP_BigNum); | ||
| 146 | |||
| 147 | /* The definitions for control commands specific to this engine */ | ||
| 148 | #define AEP_CMD_SO_PATH ENGINE_CMD_BASE | ||
| 149 | static const ENGINE_CMD_DEFN aep_cmd_defns[] = | ||
| 150 | { | ||
| 151 | { AEP_CMD_SO_PATH, | ||
| 152 | "SO_PATH", | ||
| 153 | "Specifies the path to the 'aep' shared library", | ||
| 154 | ENGINE_CMD_FLAG_STRING | ||
| 155 | }, | ||
| 156 | {0, NULL, NULL, 0} | ||
| 157 | }; | ||
| 158 | |||
| 159 | #ifndef OPENSSL_NO_RSA | ||
| 160 | /* Our internal RSA_METHOD that we provide pointers to */ | ||
| 161 | static RSA_METHOD aep_rsa = | ||
| 162 | { | ||
| 163 | "Aep RSA method", | ||
| 164 | NULL, /*rsa_pub_encrypt*/ | ||
| 165 | NULL, /*rsa_pub_decrypt*/ | ||
| 166 | NULL, /*rsa_priv_encrypt*/ | ||
| 167 | NULL, /*rsa_priv_encrypt*/ | ||
| 168 | aep_rsa_mod_exp, /*rsa_mod_exp*/ | ||
| 169 | aep_mod_exp_mont, /*bn_mod_exp*/ | ||
| 170 | NULL, /*init*/ | ||
| 171 | NULL, /*finish*/ | ||
| 172 | 0, /*flags*/ | ||
| 173 | NULL, /*app_data*/ | ||
| 174 | NULL, /*rsa_sign*/ | ||
| 175 | NULL /*rsa_verify*/ | ||
| 176 | }; | ||
| 177 | #endif | ||
| 178 | |||
| 179 | #ifndef OPENSSL_NO_DSA | ||
| 180 | /* Our internal DSA_METHOD that we provide pointers to */ | ||
| 181 | static DSA_METHOD aep_dsa = | ||
| 182 | { | ||
| 183 | "Aep DSA method", | ||
| 184 | NULL, /* dsa_do_sign */ | ||
| 185 | NULL, /* dsa_sign_setup */ | ||
| 186 | NULL, /* dsa_do_verify */ | ||
| 187 | aep_dsa_mod_exp, /* dsa_mod_exp */ | ||
| 188 | aep_mod_exp_dsa, /* bn_mod_exp */ | ||
| 189 | NULL, /* init */ | ||
| 190 | NULL, /* finish */ | ||
| 191 | 0, /* flags */ | ||
| 192 | NULL /* app_data */ | ||
| 193 | }; | ||
| 194 | #endif | ||
| 195 | |||
| 196 | #ifndef OPENSSL_NO_DH | ||
| 197 | /* Our internal DH_METHOD that we provide pointers to */ | ||
| 198 | static DH_METHOD aep_dh = | ||
| 199 | { | ||
| 200 | "Aep DH method", | ||
| 201 | NULL, | ||
| 202 | NULL, | ||
| 203 | aep_mod_exp_dh, | ||
| 204 | NULL, | ||
| 205 | NULL, | ||
| 206 | 0, | ||
| 207 | NULL | ||
| 208 | }; | ||
| 209 | #endif | ||
| 210 | |||
| 211 | #ifdef AEPRAND | ||
| 212 | /* our internal RAND_method that we provide pointers to */ | ||
| 213 | static RAND_METHOD aep_random = | ||
| 214 | { | ||
| 215 | /*"AEP RAND method", */ | ||
| 216 | NULL, | ||
| 217 | aep_rand, | ||
| 218 | NULL, | ||
| 219 | NULL, | ||
| 220 | aep_rand, | ||
| 221 | aep_rand_status, | ||
| 222 | }; | ||
| 223 | #endif | ||
| 224 | |||
| 225 | /*Define an array of structures to hold connections*/ | ||
| 226 | static AEP_CONNECTION_ENTRY aep_app_conn_table[MAX_PROCESS_CONNECTIONS]; | ||
| 227 | |||
| 228 | /*Used to determine if this is a new process*/ | ||
| 229 | static pid_t recorded_pid = 0; | ||
| 230 | |||
| 231 | #ifdef AEPRAND | ||
| 232 | static AEP_U8 rand_block[RAND_BLK_SIZE]; | ||
| 233 | static AEP_U32 rand_block_bytes = 0; | ||
| 234 | #endif | ||
| 235 | |||
| 236 | /* Constants used when creating the ENGINE */ | ||
| 237 | static const char *engine_aep_id = "aep"; | ||
| 238 | static const char *engine_aep_name = "Aep hardware engine support"; | ||
| 239 | |||
| 240 | static int max_key_len = 2176; | ||
| 241 | |||
| 242 | |||
| 243 | /* This internal function is used by ENGINE_aep() and possibly by the | ||
| 244 | * "dynamic" ENGINE support too */ | ||
| 245 | static int bind_aep(ENGINE *e) | ||
| 246 | { | ||
| 247 | #ifndef OPENSSL_NO_RSA | ||
| 248 | const RSA_METHOD *meth1; | ||
| 249 | #endif | ||
| 250 | #ifndef OPENSSL_NO_DSA | ||
| 251 | const DSA_METHOD *meth2; | ||
| 252 | #endif | ||
| 253 | #ifndef OPENSSL_NO_DH | ||
| 254 | const DH_METHOD *meth3; | ||
| 255 | #endif | ||
| 256 | |||
| 257 | if(!ENGINE_set_id(e, engine_aep_id) || | ||
| 258 | !ENGINE_set_name(e, engine_aep_name) || | ||
| 259 | #ifndef OPENSSL_NO_RSA | ||
| 260 | !ENGINE_set_RSA(e, &aep_rsa) || | ||
| 261 | #endif | ||
| 262 | #ifndef OPENSSL_NO_DSA | ||
| 263 | !ENGINE_set_DSA(e, &aep_dsa) || | ||
| 264 | #endif | ||
| 265 | #ifndef OPENSSL_NO_DH | ||
| 266 | !ENGINE_set_DH(e, &aep_dh) || | ||
| 267 | #endif | ||
| 268 | #ifdef AEPRAND | ||
| 269 | !ENGINE_set_RAND(e, &aep_random) || | ||
| 270 | #endif | ||
| 271 | !ENGINE_set_init_function(e, aep_init) || | ||
| 272 | !ENGINE_set_destroy_function(e, aep_destroy) || | ||
| 273 | !ENGINE_set_finish_function(e, aep_finish) || | ||
| 274 | !ENGINE_set_ctrl_function(e, aep_ctrl) || | ||
| 275 | !ENGINE_set_cmd_defns(e, aep_cmd_defns)) | ||
| 276 | return 0; | ||
| 277 | |||
| 278 | #ifndef OPENSSL_NO_RSA | ||
| 279 | /* We know that the "PKCS1_SSLeay()" functions hook properly | ||
| 280 | * to the aep-specific mod_exp and mod_exp_crt so we use | ||
| 281 | * those functions. NB: We don't use ENGINE_openssl() or | ||
| 282 | * anything "more generic" because something like the RSAref | ||
| 283 | * code may not hook properly, and if you own one of these | ||
| 284 | * cards then you have the right to do RSA operations on it | ||
| 285 | * anyway! */ | ||
| 286 | meth1 = RSA_PKCS1_SSLeay(); | ||
| 287 | aep_rsa.rsa_pub_enc = meth1->rsa_pub_enc; | ||
| 288 | aep_rsa.rsa_pub_dec = meth1->rsa_pub_dec; | ||
| 289 | aep_rsa.rsa_priv_enc = meth1->rsa_priv_enc; | ||
| 290 | aep_rsa.rsa_priv_dec = meth1->rsa_priv_dec; | ||
| 291 | #endif | ||
| 292 | |||
| 293 | |||
| 294 | #ifndef OPENSSL_NO_DSA | ||
| 295 | /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish | ||
| 296 | * bits. */ | ||
| 297 | meth2 = DSA_OpenSSL(); | ||
| 298 | aep_dsa.dsa_do_sign = meth2->dsa_do_sign; | ||
| 299 | aep_dsa.dsa_sign_setup = meth2->dsa_sign_setup; | ||
| 300 | aep_dsa.dsa_do_verify = meth2->dsa_do_verify; | ||
| 301 | |||
| 302 | aep_dsa = *DSA_get_default_method(); | ||
| 303 | aep_dsa.dsa_mod_exp = aep_dsa_mod_exp; | ||
| 304 | aep_dsa.bn_mod_exp = aep_mod_exp_dsa; | ||
| 305 | #endif | ||
| 306 | |||
| 307 | #ifndef OPENSSL_NO_DH | ||
| 308 | /* Much the same for Diffie-Hellman */ | ||
| 309 | meth3 = DH_OpenSSL(); | ||
| 310 | aep_dh.generate_key = meth3->generate_key; | ||
| 311 | aep_dh.compute_key = meth3->compute_key; | ||
| 312 | aep_dh.bn_mod_exp = meth3->bn_mod_exp; | ||
| 313 | #endif | ||
| 314 | |||
| 315 | /* Ensure the aep error handling is set up */ | ||
| 316 | ERR_load_AEPHK_strings(); | ||
| 317 | |||
| 318 | return 1; | ||
| 319 | } | ||
| 320 | |||
| 321 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
| 322 | static int bind_helper(ENGINE *e, const char *id) | ||
| 323 | { | ||
| 324 | if(id && (strcmp(id, engine_aep_id) != 0)) | ||
| 325 | return 0; | ||
| 326 | if(!bind_aep(e)) | ||
| 327 | return 0; | ||
| 328 | return 1; | ||
| 329 | } | ||
| 330 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
| 331 | IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) | ||
| 332 | #else | ||
| 333 | static ENGINE *engine_aep(void) | ||
| 334 | { | ||
| 335 | ENGINE *ret = ENGINE_new(); | ||
| 336 | if(!ret) | ||
| 337 | return NULL; | ||
| 338 | if(!bind_aep(ret)) | ||
| 339 | { | ||
| 340 | ENGINE_free(ret); | ||
| 341 | return NULL; | ||
| 342 | } | ||
| 343 | return ret; | ||
| 344 | } | ||
| 345 | |||
| 346 | void ENGINE_load_aep(void) | ||
| 347 | { | ||
| 348 | /* Copied from eng_[openssl|dyn].c */ | ||
| 349 | ENGINE *toadd = engine_aep(); | ||
| 350 | if(!toadd) return; | ||
| 351 | ENGINE_add(toadd); | ||
| 352 | ENGINE_free(toadd); | ||
| 353 | ERR_clear_error(); | ||
| 354 | } | ||
| 355 | #endif | ||
| 356 | |||
| 357 | /* This is a process-global DSO handle used for loading and unloading | ||
| 358 | * the Aep library. NB: This is only set (or unset) during an | ||
| 359 | * init() or finish() call (reference counts permitting) and they're | ||
| 360 | * operating with global locks, so this should be thread-safe | ||
| 361 | * implicitly. */ | ||
| 362 | static DSO *aep_dso = NULL; | ||
| 363 | |||
| 364 | /* These are the static string constants for the DSO file name and the function | ||
| 365 | * symbol names to bind to. | ||
| 366 | */ | ||
| 367 | static const char *AEP_LIBNAME = NULL; | ||
| 368 | static const char *get_AEP_LIBNAME(void) | ||
| 369 | { | ||
| 370 | if(AEP_LIBNAME) | ||
| 371 | return AEP_LIBNAME; | ||
| 372 | return "aep"; | ||
| 373 | } | ||
| 374 | static void free_AEP_LIBNAME(void) | ||
| 375 | { | ||
| 376 | if(AEP_LIBNAME) | ||
| 377 | OPENSSL_free((void*)AEP_LIBNAME); | ||
| 378 | AEP_LIBNAME = NULL; | ||
| 379 | } | ||
| 380 | static long set_AEP_LIBNAME(const char *name) | ||
| 381 | { | ||
| 382 | free_AEP_LIBNAME(); | ||
| 383 | return ((AEP_LIBNAME = BUF_strdup(name)) != NULL ? 1 : 0); | ||
| 384 | } | ||
| 385 | |||
| 386 | static const char *AEP_F1 = "AEP_ModExp"; | ||
| 387 | static const char *AEP_F2 = "AEP_ModExpCrt"; | ||
| 388 | #ifdef AEPRAND | ||
| 389 | static const char *AEP_F3 = "AEP_GenRandom"; | ||
| 390 | #endif | ||
| 391 | static const char *AEP_F4 = "AEP_Finalize"; | ||
| 392 | static const char *AEP_F5 = "AEP_Initialize"; | ||
| 393 | static const char *AEP_F6 = "AEP_OpenConnection"; | ||
| 394 | static const char *AEP_F7 = "AEP_SetBNCallBacks"; | ||
| 395 | static const char *AEP_F8 = "AEP_CloseConnection"; | ||
| 396 | |||
| 397 | /* These are the function pointers that are (un)set when the library has | ||
| 398 | * successfully (un)loaded. */ | ||
| 399 | static t_AEP_OpenConnection *p_AEP_OpenConnection = NULL; | ||
| 400 | static t_AEP_CloseConnection *p_AEP_CloseConnection = NULL; | ||
| 401 | static t_AEP_ModExp *p_AEP_ModExp = NULL; | ||
| 402 | static t_AEP_ModExpCrt *p_AEP_ModExpCrt = NULL; | ||
| 403 | #ifdef AEPRAND | ||
| 404 | static t_AEP_GenRandom *p_AEP_GenRandom = NULL; | ||
| 405 | #endif | ||
| 406 | static t_AEP_Initialize *p_AEP_Initialize = NULL; | ||
| 407 | static t_AEP_Finalize *p_AEP_Finalize = NULL; | ||
| 408 | static t_AEP_SetBNCallBacks *p_AEP_SetBNCallBacks = NULL; | ||
| 409 | |||
| 410 | /* (de)initialisation functions. */ | ||
| 411 | static int aep_init(ENGINE *e) | ||
| 412 | { | ||
| 413 | t_AEP_ModExp *p1; | ||
| 414 | t_AEP_ModExpCrt *p2; | ||
| 415 | #ifdef AEPRAND | ||
| 416 | t_AEP_GenRandom *p3; | ||
| 417 | #endif | ||
| 418 | t_AEP_Finalize *p4; | ||
| 419 | t_AEP_Initialize *p5; | ||
| 420 | t_AEP_OpenConnection *p6; | ||
| 421 | t_AEP_SetBNCallBacks *p7; | ||
| 422 | t_AEP_CloseConnection *p8; | ||
| 423 | |||
| 424 | int to_return = 0; | ||
| 425 | |||
| 426 | if(aep_dso != NULL) | ||
| 427 | { | ||
| 428 | AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_ALREADY_LOADED); | ||
| 429 | goto err; | ||
| 430 | } | ||
| 431 | /* Attempt to load libaep.so. */ | ||
| 432 | |||
| 433 | aep_dso = DSO_load(NULL, get_AEP_LIBNAME(), NULL, 0); | ||
| 434 | |||
| 435 | if(aep_dso == NULL) | ||
| 436 | { | ||
| 437 | AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED); | ||
| 438 | goto err; | ||
| 439 | } | ||
| 440 | |||
| 441 | if( !(p1 = (t_AEP_ModExp *) DSO_bind_func( aep_dso,AEP_F1)) || | ||
| 442 | !(p2 = (t_AEP_ModExpCrt*) DSO_bind_func( aep_dso,AEP_F2)) || | ||
| 443 | #ifdef AEPRAND | ||
| 444 | !(p3 = (t_AEP_GenRandom*) DSO_bind_func( aep_dso,AEP_F3)) || | ||
| 445 | #endif | ||
| 446 | !(p4 = (t_AEP_Finalize*) DSO_bind_func( aep_dso,AEP_F4)) || | ||
| 447 | !(p5 = (t_AEP_Initialize*) DSO_bind_func( aep_dso,AEP_F5)) || | ||
| 448 | !(p6 = (t_AEP_OpenConnection*) DSO_bind_func( aep_dso,AEP_F6)) || | ||
| 449 | !(p7 = (t_AEP_SetBNCallBacks*) DSO_bind_func( aep_dso,AEP_F7)) || | ||
| 450 | !(p8 = (t_AEP_CloseConnection*) DSO_bind_func( aep_dso,AEP_F8))) | ||
| 451 | { | ||
| 452 | AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED); | ||
| 453 | goto err; | ||
| 454 | } | ||
| 455 | |||
| 456 | /* Copy the pointers */ | ||
| 457 | |||
| 458 | p_AEP_ModExp = p1; | ||
| 459 | p_AEP_ModExpCrt = p2; | ||
| 460 | #ifdef AEPRAND | ||
| 461 | p_AEP_GenRandom = p3; | ||
| 462 | #endif | ||
| 463 | p_AEP_Finalize = p4; | ||
| 464 | p_AEP_Initialize = p5; | ||
| 465 | p_AEP_OpenConnection = p6; | ||
| 466 | p_AEP_SetBNCallBacks = p7; | ||
| 467 | p_AEP_CloseConnection = p8; | ||
| 468 | |||
| 469 | to_return = 1; | ||
| 470 | |||
| 471 | return to_return; | ||
| 472 | |||
| 473 | err: | ||
| 474 | |||
| 475 | if(aep_dso) | ||
| 476 | DSO_free(aep_dso); | ||
| 477 | aep_dso = NULL; | ||
| 478 | |||
| 479 | p_AEP_OpenConnection = NULL; | ||
| 480 | p_AEP_ModExp = NULL; | ||
| 481 | p_AEP_ModExpCrt = NULL; | ||
| 482 | #ifdef AEPRAND | ||
| 483 | p_AEP_GenRandom = NULL; | ||
| 484 | #endif | ||
| 485 | p_AEP_Initialize = NULL; | ||
| 486 | p_AEP_Finalize = NULL; | ||
| 487 | p_AEP_SetBNCallBacks = NULL; | ||
| 488 | p_AEP_CloseConnection = NULL; | ||
| 489 | |||
| 490 | return to_return; | ||
| 491 | } | ||
| 492 | |||
| 493 | /* Destructor (complements the "ENGINE_aep()" constructor) */ | ||
| 494 | static int aep_destroy(ENGINE *e) | ||
| 495 | { | ||
| 496 | free_AEP_LIBNAME(); | ||
| 497 | ERR_unload_AEPHK_strings(); | ||
| 498 | return 1; | ||
| 499 | } | ||
| 500 | |||
| 501 | static int aep_finish(ENGINE *e) | ||
| 502 | { | ||
| 503 | int to_return = 0, in_use; | ||
| 504 | AEP_RV rv; | ||
| 505 | |||
| 506 | if(aep_dso == NULL) | ||
| 507 | { | ||
| 508 | AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_NOT_LOADED); | ||
| 509 | goto err; | ||
| 510 | } | ||
| 511 | |||
| 512 | rv = aep_close_all_connections(0, &in_use); | ||
| 513 | if (rv != AEP_R_OK) | ||
| 514 | { | ||
| 515 | AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_CLOSE_HANDLES_FAILED); | ||
| 516 | goto err; | ||
| 517 | } | ||
| 518 | if (in_use) | ||
| 519 | { | ||
| 520 | AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_CONNECTIONS_IN_USE); | ||
| 521 | goto err; | ||
| 522 | } | ||
| 523 | |||
| 524 | rv = p_AEP_Finalize(); | ||
| 525 | if (rv != AEP_R_OK) | ||
| 526 | { | ||
| 527 | AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_FINALIZE_FAILED); | ||
| 528 | goto err; | ||
| 529 | } | ||
| 530 | |||
| 531 | if(!DSO_free(aep_dso)) | ||
| 532 | { | ||
| 533 | AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_UNIT_FAILURE); | ||
| 534 | goto err; | ||
| 535 | } | ||
| 536 | |||
| 537 | aep_dso = NULL; | ||
| 538 | p_AEP_CloseConnection = NULL; | ||
| 539 | p_AEP_OpenConnection = NULL; | ||
| 540 | p_AEP_ModExp = NULL; | ||
| 541 | p_AEP_ModExpCrt = NULL; | ||
| 542 | #ifdef AEPRAND | ||
| 543 | p_AEP_GenRandom = NULL; | ||
| 544 | #endif | ||
| 545 | p_AEP_Initialize = NULL; | ||
| 546 | p_AEP_Finalize = NULL; | ||
| 547 | p_AEP_SetBNCallBacks = NULL; | ||
| 548 | |||
| 549 | to_return = 1; | ||
| 550 | err: | ||
| 551 | return to_return; | ||
| 552 | } | ||
| 553 | |||
| 554 | static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
| 555 | { | ||
| 556 | int initialised = ((aep_dso == NULL) ? 0 : 1); | ||
| 557 | switch(cmd) | ||
| 558 | { | ||
| 559 | case AEP_CMD_SO_PATH: | ||
| 560 | if(p == NULL) | ||
| 561 | { | ||
| 562 | AEPHKerr(AEPHK_F_AEP_CTRL, | ||
| 563 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 564 | return 0; | ||
| 565 | } | ||
| 566 | if(initialised) | ||
| 567 | { | ||
| 568 | AEPHKerr(AEPHK_F_AEP_CTRL, | ||
| 569 | AEPHK_R_ALREADY_LOADED); | ||
| 570 | return 0; | ||
| 571 | } | ||
| 572 | return set_AEP_LIBNAME((const char*)p); | ||
| 573 | default: | ||
| 574 | break; | ||
| 575 | } | ||
| 576 | AEPHKerr(AEPHK_F_AEP_CTRL,AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
| 577 | return 0; | ||
| 578 | } | ||
| 579 | |||
| 580 | static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 581 | const BIGNUM *m, BN_CTX *ctx) | ||
| 582 | { | ||
| 583 | int to_return = 0; | ||
| 584 | int r_len = 0; | ||
| 585 | AEP_CONNECTION_HNDL hConnection; | ||
| 586 | AEP_RV rv; | ||
| 587 | |||
| 588 | r_len = BN_num_bits(m); | ||
| 589 | |||
| 590 | /* Perform in software if modulus is too large for hardware. */ | ||
| 591 | |||
| 592 | if (r_len > max_key_len){ | ||
| 593 | AEPHKerr(AEPHK_F_AEP_MOD_EXP, AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
| 594 | return BN_mod_exp(r, a, p, m, ctx); | ||
| 595 | } | ||
| 596 | |||
| 597 | /*Grab a connection from the pool*/ | ||
| 598 | rv = aep_get_connection(&hConnection); | ||
| 599 | if (rv != AEP_R_OK) | ||
| 600 | { | ||
| 601 | AEPHKerr(AEPHK_F_AEP_MOD_EXP,AEPHK_R_GET_HANDLE_FAILED); | ||
| 602 | return BN_mod_exp(r, a, p, m, ctx); | ||
| 603 | } | ||
| 604 | |||
| 605 | /*To the card with the mod exp*/ | ||
| 606 | rv = p_AEP_ModExp(hConnection,(void*)a, (void*)p,(void*)m, (void*)r,NULL); | ||
| 607 | |||
| 608 | if (rv != AEP_R_OK) | ||
| 609 | { | ||
| 610 | AEPHKerr(AEPHK_F_AEP_MOD_EXP,AEPHK_R_MOD_EXP_FAILED); | ||
| 611 | rv = aep_close_connection(hConnection); | ||
| 612 | return BN_mod_exp(r, a, p, m, ctx); | ||
| 613 | } | ||
| 614 | |||
| 615 | /*Return the connection to the pool*/ | ||
| 616 | rv = aep_return_connection(hConnection); | ||
| 617 | if (rv != AEP_R_OK) | ||
| 618 | { | ||
| 619 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED); | ||
| 620 | goto err; | ||
| 621 | } | ||
| 622 | |||
| 623 | to_return = 1; | ||
| 624 | err: | ||
| 625 | return to_return; | ||
| 626 | } | ||
| 627 | |||
| 628 | static AEP_RV aep_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 629 | const BIGNUM *q, const BIGNUM *dmp1, | ||
| 630 | const BIGNUM *dmq1,const BIGNUM *iqmp, BN_CTX *ctx) | ||
| 631 | { | ||
| 632 | AEP_RV rv = AEP_R_OK; | ||
| 633 | AEP_CONNECTION_HNDL hConnection; | ||
| 634 | |||
| 635 | /*Grab a connection from the pool*/ | ||
| 636 | rv = aep_get_connection(&hConnection); | ||
| 637 | if (rv != AEP_R_OK) | ||
| 638 | { | ||
| 639 | AEPHKerr(AEPHK_F_AEP_MOD_EXP_CRT,AEPHK_R_GET_HANDLE_FAILED); | ||
| 640 | return FAIL_TO_SW; | ||
| 641 | } | ||
| 642 | |||
| 643 | /*To the card with the mod exp*/ | ||
| 644 | rv = p_AEP_ModExpCrt(hConnection,(void*)a, (void*)p, (void*)q, (void*)dmp1,(void*)dmq1, | ||
| 645 | (void*)iqmp,(void*)r,NULL); | ||
| 646 | if (rv != AEP_R_OK) | ||
| 647 | { | ||
| 648 | AEPHKerr(AEPHK_F_AEP_MOD_EXP_CRT,AEPHK_R_MOD_EXP_CRT_FAILED); | ||
| 649 | rv = aep_close_connection(hConnection); | ||
| 650 | return FAIL_TO_SW; | ||
| 651 | } | ||
| 652 | |||
| 653 | /*Return the connection to the pool*/ | ||
| 654 | rv = aep_return_connection(hConnection); | ||
| 655 | if (rv != AEP_R_OK) | ||
| 656 | { | ||
| 657 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED); | ||
| 658 | goto err; | ||
| 659 | } | ||
| 660 | |||
| 661 | err: | ||
| 662 | return rv; | ||
| 663 | } | ||
| 664 | |||
| 665 | |||
| 666 | #ifdef AEPRAND | ||
| 667 | static int aep_rand(unsigned char *buf,int len ) | ||
| 668 | { | ||
| 669 | AEP_RV rv = AEP_R_OK; | ||
| 670 | AEP_CONNECTION_HNDL hConnection; | ||
| 671 | |||
| 672 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); | ||
| 673 | |||
| 674 | /*Can the request be serviced with what's already in the buffer?*/ | ||
| 675 | if (len <= rand_block_bytes) | ||
| 676 | { | ||
| 677 | memcpy(buf, &rand_block[RAND_BLK_SIZE - rand_block_bytes], len); | ||
| 678 | rand_block_bytes -= len; | ||
| 679 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | ||
| 680 | } | ||
| 681 | else | ||
| 682 | /*If not the get another block of random bytes*/ | ||
| 683 | { | ||
| 684 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | ||
| 685 | |||
| 686 | rv = aep_get_connection(&hConnection); | ||
| 687 | if (rv != AEP_R_OK) | ||
| 688 | { | ||
| 689 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_HANDLE_FAILED); | ||
| 690 | goto err_nounlock; | ||
| 691 | } | ||
| 692 | |||
| 693 | if (len > RAND_BLK_SIZE) | ||
| 694 | { | ||
| 695 | rv = p_AEP_GenRandom(hConnection, len, 2, buf, NULL); | ||
| 696 | if (rv != AEP_R_OK) | ||
| 697 | { | ||
| 698 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_RANDOM_FAILED); | ||
| 699 | goto err_nounlock; | ||
| 700 | } | ||
| 701 | } | ||
| 702 | else | ||
| 703 | { | ||
| 704 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); | ||
| 705 | |||
| 706 | rv = p_AEP_GenRandom(hConnection, RAND_BLK_SIZE, 2, &rand_block[0], NULL); | ||
| 707 | if (rv != AEP_R_OK) | ||
| 708 | { | ||
| 709 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_RANDOM_FAILED); | ||
| 710 | |||
| 711 | goto err; | ||
| 712 | } | ||
| 713 | |||
| 714 | rand_block_bytes = RAND_BLK_SIZE; | ||
| 715 | |||
| 716 | memcpy(buf, &rand_block[RAND_BLK_SIZE - rand_block_bytes], len); | ||
| 717 | rand_block_bytes -= len; | ||
| 718 | |||
| 719 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | ||
| 720 | } | ||
| 721 | |||
| 722 | rv = aep_return_connection(hConnection); | ||
| 723 | if (rv != AEP_R_OK) | ||
| 724 | { | ||
| 725 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED); | ||
| 726 | |||
| 727 | goto err_nounlock; | ||
| 728 | } | ||
| 729 | } | ||
| 730 | |||
| 731 | return 1; | ||
| 732 | err: | ||
| 733 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | ||
| 734 | err_nounlock: | ||
| 735 | return 0; | ||
| 736 | } | ||
| 737 | |||
| 738 | static int aep_rand_status(void) | ||
| 739 | { | ||
| 740 | return 1; | ||
| 741 | } | ||
| 742 | #endif | ||
| 743 | |||
| 744 | #ifndef OPENSSL_NO_RSA | ||
| 745 | static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | ||
| 746 | { | ||
| 747 | BN_CTX *ctx = NULL; | ||
| 748 | int to_return = 0; | ||
| 749 | AEP_RV rv = AEP_R_OK; | ||
| 750 | |||
| 751 | if ((ctx = BN_CTX_new()) == NULL) | ||
| 752 | goto err; | ||
| 753 | |||
| 754 | if (!aep_dso) | ||
| 755 | { | ||
| 756 | AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_NOT_LOADED); | ||
| 757 | goto err; | ||
| 758 | } | ||
| 759 | |||
| 760 | /*See if we have all the necessary bits for a crt*/ | ||
| 761 | if (rsa->q && rsa->dmp1 && rsa->dmq1 && rsa->iqmp) | ||
| 762 | { | ||
| 763 | rv = aep_mod_exp_crt(r0,I,rsa->p,rsa->q, rsa->dmp1,rsa->dmq1,rsa->iqmp,ctx); | ||
| 764 | |||
| 765 | if (rv == FAIL_TO_SW){ | ||
| 766 | const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 767 | to_return = (*meth->rsa_mod_exp)(r0, I, rsa); | ||
| 768 | goto err; | ||
| 769 | } | ||
| 770 | else if (rv != AEP_R_OK) | ||
| 771 | goto err; | ||
| 772 | } | ||
| 773 | else | ||
| 774 | { | ||
| 775 | if (!rsa->d || !rsa->n) | ||
| 776 | { | ||
| 777 | AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_MISSING_KEY_COMPONENTS); | ||
| 778 | goto err; | ||
| 779 | } | ||
| 780 | |||
| 781 | rv = aep_mod_exp(r0,I,rsa->d,rsa->n,ctx); | ||
| 782 | if (rv != AEP_R_OK) | ||
| 783 | goto err; | ||
| 784 | |||
| 785 | } | ||
| 786 | |||
| 787 | to_return = 1; | ||
| 788 | |||
| 789 | err: | ||
| 790 | if(ctx) | ||
| 791 | BN_CTX_free(ctx); | ||
| 792 | return to_return; | ||
| 793 | } | ||
| 794 | #endif | ||
| 795 | |||
| 796 | #ifndef OPENSSL_NO_DSA | ||
| 797 | static int aep_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
| 798 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
| 799 | BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
| 800 | { | ||
| 801 | BIGNUM t; | ||
| 802 | int to_return = 0; | ||
| 803 | BN_init(&t); | ||
| 804 | |||
| 805 | /* let rr = a1 ^ p1 mod m */ | ||
| 806 | if (!aep_mod_exp(rr,a1,p1,m,ctx)) goto end; | ||
| 807 | /* let t = a2 ^ p2 mod m */ | ||
| 808 | if (!aep_mod_exp(&t,a2,p2,m,ctx)) goto end; | ||
| 809 | /* let rr = rr * t mod m */ | ||
| 810 | if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end; | ||
| 811 | to_return = 1; | ||
| 812 | end: | ||
| 813 | BN_free(&t); | ||
| 814 | return to_return; | ||
| 815 | } | ||
| 816 | |||
| 817 | static int aep_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
| 818 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 819 | BN_MONT_CTX *m_ctx) | ||
| 820 | { | ||
| 821 | return aep_mod_exp(r, a, p, m, ctx); | ||
| 822 | } | ||
| 823 | #endif | ||
| 824 | |||
| 825 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
| 826 | static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 827 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
| 828 | { | ||
| 829 | return aep_mod_exp(r, a, p, m, ctx); | ||
| 830 | } | ||
| 831 | |||
| 832 | #ifndef OPENSSL_NO_DH | ||
| 833 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | ||
| 834 | static int aep_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 835 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 836 | BN_MONT_CTX *m_ctx) | ||
| 837 | { | ||
| 838 | return aep_mod_exp(r, a, p, m, ctx); | ||
| 839 | } | ||
| 840 | #endif | ||
| 841 | |||
| 842 | static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR phConnection) | ||
| 843 | { | ||
| 844 | int count; | ||
| 845 | AEP_RV rv = AEP_R_OK; | ||
| 846 | |||
| 847 | /*Get the current process id*/ | ||
| 848 | pid_t curr_pid; | ||
| 849 | |||
| 850 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 851 | |||
| 852 | curr_pid = getpid(); | ||
| 853 | |||
| 854 | /*Check if this is the first time this is being called from the current | ||
| 855 | process*/ | ||
| 856 | if (recorded_pid != curr_pid) | ||
| 857 | { | ||
| 858 | /*Remember our pid so we can check if we're in a new process*/ | ||
| 859 | recorded_pid = curr_pid; | ||
| 860 | |||
| 861 | /*Call Finalize to make sure we have not inherited some data | ||
| 862 | from a parent process*/ | ||
| 863 | p_AEP_Finalize(); | ||
| 864 | |||
| 865 | /*Initialise the AEP API*/ | ||
| 866 | rv = p_AEP_Initialize(NULL); | ||
| 867 | |||
| 868 | if (rv != AEP_R_OK) | ||
| 869 | { | ||
| 870 | AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_INIT_FAILURE); | ||
| 871 | recorded_pid = 0; | ||
| 872 | goto end; | ||
| 873 | } | ||
| 874 | |||
| 875 | /*Set the AEP big num call back functions*/ | ||
| 876 | rv = p_AEP_SetBNCallBacks(&GetBigNumSize, &MakeAEPBigNum, | ||
| 877 | &ConvertAEPBigNum); | ||
| 878 | |||
| 879 | if (rv != AEP_R_OK) | ||
| 880 | { | ||
| 881 | AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_SETBNCALLBACK_FAILURE); | ||
| 882 | recorded_pid = 0; | ||
| 883 | goto end; | ||
| 884 | } | ||
| 885 | |||
| 886 | #ifdef AEPRAND | ||
| 887 | /*Reset the rand byte count*/ | ||
| 888 | rand_block_bytes = 0; | ||
| 889 | #endif | ||
| 890 | |||
| 891 | /*Init the structures*/ | ||
| 892 | for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
| 893 | { | ||
| 894 | aep_app_conn_table[count].conn_state = NotConnected; | ||
| 895 | aep_app_conn_table[count].conn_hndl = 0; | ||
| 896 | } | ||
| 897 | |||
| 898 | /*Open a connection*/ | ||
| 899 | rv = p_AEP_OpenConnection(phConnection); | ||
| 900 | |||
| 901 | if (rv != AEP_R_OK) | ||
| 902 | { | ||
| 903 | AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_UNIT_FAILURE); | ||
| 904 | recorded_pid = 0; | ||
| 905 | goto end; | ||
| 906 | } | ||
| 907 | |||
| 908 | aep_app_conn_table[0].conn_state = InUse; | ||
| 909 | aep_app_conn_table[0].conn_hndl = *phConnection; | ||
| 910 | goto end; | ||
| 911 | } | ||
| 912 | /*Check the existing connections to see if we can find a free one*/ | ||
| 913 | for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
| 914 | { | ||
| 915 | if (aep_app_conn_table[count].conn_state == Connected) | ||
| 916 | { | ||
| 917 | aep_app_conn_table[count].conn_state = InUse; | ||
| 918 | *phConnection = aep_app_conn_table[count].conn_hndl; | ||
| 919 | goto end; | ||
| 920 | } | ||
| 921 | } | ||
| 922 | /*If no connections available, we're going to have to try | ||
| 923 | to open a new one*/ | ||
| 924 | for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
| 925 | { | ||
| 926 | if (aep_app_conn_table[count].conn_state == NotConnected) | ||
| 927 | { | ||
| 928 | /*Open a connection*/ | ||
| 929 | rv = p_AEP_OpenConnection(phConnection); | ||
| 930 | |||
| 931 | if (rv != AEP_R_OK) | ||
| 932 | { | ||
| 933 | AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_UNIT_FAILURE); | ||
| 934 | goto end; | ||
| 935 | } | ||
| 936 | |||
| 937 | aep_app_conn_table[count].conn_state = InUse; | ||
| 938 | aep_app_conn_table[count].conn_hndl = *phConnection; | ||
| 939 | goto end; | ||
| 940 | } | ||
| 941 | } | ||
| 942 | rv = AEP_R_GENERAL_ERROR; | ||
| 943 | end: | ||
| 944 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 945 | return rv; | ||
| 946 | } | ||
| 947 | |||
| 948 | |||
| 949 | static AEP_RV aep_return_connection(AEP_CONNECTION_HNDL hConnection) | ||
| 950 | { | ||
| 951 | int count; | ||
| 952 | |||
| 953 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 954 | |||
| 955 | /*Find the connection item that matches this connection handle*/ | ||
| 956 | for(count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
| 957 | { | ||
| 958 | if (aep_app_conn_table[count].conn_hndl == hConnection) | ||
| 959 | { | ||
| 960 | aep_app_conn_table[count].conn_state = Connected; | ||
| 961 | break; | ||
| 962 | } | ||
| 963 | } | ||
| 964 | |||
| 965 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 966 | |||
| 967 | return AEP_R_OK; | ||
| 968 | } | ||
| 969 | |||
| 970 | static AEP_RV aep_close_connection(AEP_CONNECTION_HNDL hConnection) | ||
| 971 | { | ||
| 972 | int count; | ||
| 973 | AEP_RV rv = AEP_R_OK; | ||
| 974 | |||
| 975 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 976 | |||
| 977 | /*Find the connection item that matches this connection handle*/ | ||
| 978 | for(count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
| 979 | { | ||
| 980 | if (aep_app_conn_table[count].conn_hndl == hConnection) | ||
| 981 | { | ||
| 982 | rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl); | ||
| 983 | if (rv != AEP_R_OK) | ||
| 984 | goto end; | ||
| 985 | aep_app_conn_table[count].conn_state = NotConnected; | ||
| 986 | aep_app_conn_table[count].conn_hndl = 0; | ||
| 987 | break; | ||
| 988 | } | ||
| 989 | } | ||
| 990 | |||
| 991 | end: | ||
| 992 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 993 | return rv; | ||
| 994 | } | ||
| 995 | |||
| 996 | static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use) | ||
| 997 | { | ||
| 998 | int count; | ||
| 999 | AEP_RV rv = AEP_R_OK; | ||
| 1000 | |||
| 1001 | *in_use = 0; | ||
| 1002 | if (use_engine_lock) CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 1003 | for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
| 1004 | { | ||
| 1005 | switch (aep_app_conn_table[count].conn_state) | ||
| 1006 | { | ||
| 1007 | case Connected: | ||
| 1008 | rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl); | ||
| 1009 | if (rv != AEP_R_OK) | ||
| 1010 | goto end; | ||
| 1011 | aep_app_conn_table[count].conn_state = NotConnected; | ||
| 1012 | aep_app_conn_table[count].conn_hndl = 0; | ||
| 1013 | break; | ||
| 1014 | case InUse: | ||
| 1015 | (*in_use)++; | ||
| 1016 | break; | ||
| 1017 | case NotConnected: | ||
| 1018 | break; | ||
| 1019 | } | ||
| 1020 | } | ||
| 1021 | end: | ||
| 1022 | if (use_engine_lock) CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 1023 | return rv; | ||
| 1024 | } | ||
| 1025 | |||
| 1026 | /*BigNum call back functions, used to convert OpenSSL bignums into AEP bignums. | ||
| 1027 | Note only 32bit Openssl build support*/ | ||
| 1028 | |||
| 1029 | static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize) | ||
| 1030 | { | ||
| 1031 | BIGNUM* bn; | ||
| 1032 | |||
| 1033 | /*Cast the ArbBigNum pointer to our BIGNUM struct*/ | ||
| 1034 | bn = (BIGNUM*) ArbBigNum; | ||
| 1035 | |||
| 1036 | #ifdef SIXTY_FOUR_BIT_LONG | ||
| 1037 | *BigNumSize = bn->top << 3; | ||
| 1038 | #else | ||
| 1039 | /*Size of the bignum in bytes is equal to the bn->top (no of 32 bit | ||
| 1040 | words) multiplies by 4*/ | ||
| 1041 | *BigNumSize = bn->top << 2; | ||
| 1042 | #endif | ||
| 1043 | |||
| 1044 | return AEP_R_OK; | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize, | ||
| 1048 | unsigned char* AEP_BigNum) | ||
| 1049 | { | ||
| 1050 | BIGNUM* bn; | ||
| 1051 | |||
| 1052 | #ifndef SIXTY_FOUR_BIT_LONG | ||
| 1053 | unsigned char* buf; | ||
| 1054 | int i; | ||
| 1055 | #endif | ||
| 1056 | |||
| 1057 | /*Cast the ArbBigNum pointer to our BIGNUM struct*/ | ||
| 1058 | bn = (BIGNUM*) ArbBigNum; | ||
| 1059 | |||
| 1060 | #ifdef SIXTY_FOUR_BIT_LONG | ||
| 1061 | memcpy(AEP_BigNum, bn->d, BigNumSize); | ||
| 1062 | #else | ||
| 1063 | /*Must copy data into a (monotone) least significant byte first format | ||
| 1064 | performing endian conversion if necessary*/ | ||
| 1065 | for(i=0;i<bn->top;i++) | ||
| 1066 | { | ||
| 1067 | buf = (unsigned char*)&bn->d[i]; | ||
| 1068 | |||
| 1069 | *((AEP_U32*)AEP_BigNum) = (AEP_U32) | ||
| 1070 | ((unsigned) buf[1] << 8 | buf[0]) | | ||
| 1071 | ((unsigned) buf[3] << 8 | buf[2]) << 16; | ||
| 1072 | |||
| 1073 | AEP_BigNum += 4; | ||
| 1074 | } | ||
| 1075 | #endif | ||
| 1076 | |||
| 1077 | return AEP_R_OK; | ||
| 1078 | } | ||
| 1079 | |||
| 1080 | /*Turn an AEP Big Num back to a user big num*/ | ||
| 1081 | static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize, | ||
| 1082 | unsigned char* AEP_BigNum) | ||
| 1083 | { | ||
| 1084 | BIGNUM* bn; | ||
| 1085 | #ifndef SIXTY_FOUR_BIT_LONG | ||
| 1086 | int i; | ||
| 1087 | #endif | ||
| 1088 | |||
| 1089 | bn = (BIGNUM*)ArbBigNum; | ||
| 1090 | |||
| 1091 | /*Expand the result bn so that it can hold our big num. | ||
| 1092 | Size is in bits*/ | ||
| 1093 | bn_expand(bn, (int)(BigNumSize << 3)); | ||
| 1094 | |||
| 1095 | #ifdef SIXTY_FOUR_BIT_LONG | ||
| 1096 | bn->top = BigNumSize >> 3; | ||
| 1097 | |||
| 1098 | if((BigNumSize & 7) != 0) | ||
| 1099 | bn->top++; | ||
| 1100 | |||
| 1101 | memset(bn->d, 0, bn->top << 3); | ||
| 1102 | |||
| 1103 | memcpy(bn->d, AEP_BigNum, BigNumSize); | ||
| 1104 | #else | ||
| 1105 | bn->top = BigNumSize >> 2; | ||
| 1106 | |||
| 1107 | for(i=0;i<bn->top;i++) | ||
| 1108 | { | ||
| 1109 | bn->d[i] = (AEP_U32) | ||
| 1110 | ((unsigned) AEP_BigNum[3] << 8 | AEP_BigNum[2]) << 16 | | ||
| 1111 | ((unsigned) AEP_BigNum[1] << 8 | AEP_BigNum[0]); | ||
| 1112 | AEP_BigNum += 4; | ||
| 1113 | } | ||
| 1114 | #endif | ||
| 1115 | |||
| 1116 | return AEP_R_OK; | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | #endif /* !OPENSSL_NO_HW_AEP */ | ||
| 1120 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_aep_err.c b/src/lib/libcrypto/engine/hw_aep_err.c deleted file mode 100644 index 092f532946..0000000000 --- a/src/lib/libcrypto/engine/hw_aep_err.c +++ /dev/null | |||
| @@ -1,157 +0,0 @@ | |||
| 1 | /* hw_aep_err.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include "hw_aep_err.h" | ||
| 64 | |||
| 65 | /* BEGIN ERROR CODES */ | ||
| 66 | #ifndef OPENSSL_NO_ERR | ||
| 67 | static ERR_STRING_DATA AEPHK_str_functs[]= | ||
| 68 | { | ||
| 69 | {ERR_PACK(0,AEPHK_F_AEP_CTRL,0), "AEP_CTRL"}, | ||
| 70 | {ERR_PACK(0,AEPHK_F_AEP_FINISH,0), "AEP_FINISH"}, | ||
| 71 | {ERR_PACK(0,AEPHK_F_AEP_GET_CONNECTION,0), "AEP_GET_CONNECTION"}, | ||
| 72 | {ERR_PACK(0,AEPHK_F_AEP_INIT,0), "AEP_INIT"}, | ||
| 73 | {ERR_PACK(0,AEPHK_F_AEP_MOD_EXP,0), "AEP_MOD_EXP"}, | ||
| 74 | {ERR_PACK(0,AEPHK_F_AEP_MOD_EXP_CRT,0), "AEP_MOD_EXP_CRT"}, | ||
| 75 | {ERR_PACK(0,AEPHK_F_AEP_RAND,0), "AEP_RAND"}, | ||
| 76 | {ERR_PACK(0,AEPHK_F_AEP_RSA_MOD_EXP,0), "AEP_RSA_MOD_EXP"}, | ||
| 77 | {0,NULL} | ||
| 78 | }; | ||
| 79 | |||
| 80 | static ERR_STRING_DATA AEPHK_str_reasons[]= | ||
| 81 | { | ||
| 82 | {AEPHK_R_ALREADY_LOADED ,"already loaded"}, | ||
| 83 | {AEPHK_R_CLOSE_HANDLES_FAILED ,"close handles failed"}, | ||
| 84 | {AEPHK_R_CONNECTIONS_IN_USE ,"connections in use"}, | ||
| 85 | {AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | ||
| 86 | {AEPHK_R_FINALIZE_FAILED ,"finalize failed"}, | ||
| 87 | {AEPHK_R_GET_HANDLE_FAILED ,"get handle failed"}, | ||
| 88 | {AEPHK_R_GET_RANDOM_FAILED ,"get random failed"}, | ||
| 89 | {AEPHK_R_INIT_FAILURE ,"init failure"}, | ||
| 90 | {AEPHK_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | ||
| 91 | {AEPHK_R_MOD_EXP_CRT_FAILED ,"mod exp crt failed"}, | ||
| 92 | {AEPHK_R_MOD_EXP_FAILED ,"mod exp failed"}, | ||
| 93 | {AEPHK_R_NOT_LOADED ,"not loaded"}, | ||
| 94 | {AEPHK_R_OK ,"ok"}, | ||
| 95 | {AEPHK_R_RETURN_CONNECTION_FAILED ,"return connection failed"}, | ||
| 96 | {AEPHK_R_SETBNCALLBACK_FAILURE ,"setbncallback failure"}, | ||
| 97 | {AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"}, | ||
| 98 | {AEPHK_R_UNIT_FAILURE ,"unit failure"}, | ||
| 99 | {0,NULL} | ||
| 100 | }; | ||
| 101 | |||
| 102 | #endif | ||
| 103 | |||
| 104 | #ifdef AEPHK_LIB_NAME | ||
| 105 | static ERR_STRING_DATA AEPHK_lib_name[]= | ||
| 106 | { | ||
| 107 | {0 ,AEPHK_LIB_NAME}, | ||
| 108 | {0,NULL} | ||
| 109 | }; | ||
| 110 | #endif | ||
| 111 | |||
| 112 | |||
| 113 | static int AEPHK_lib_error_code=0; | ||
| 114 | static int AEPHK_error_init=1; | ||
| 115 | |||
| 116 | static void ERR_load_AEPHK_strings(void) | ||
| 117 | { | ||
| 118 | if (AEPHK_lib_error_code == 0) | ||
| 119 | AEPHK_lib_error_code=ERR_get_next_error_library(); | ||
| 120 | |||
| 121 | if (AEPHK_error_init) | ||
| 122 | { | ||
| 123 | AEPHK_error_init=0; | ||
| 124 | #ifndef OPENSSL_NO_ERR | ||
| 125 | ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_functs); | ||
| 126 | ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_reasons); | ||
| 127 | #endif | ||
| 128 | |||
| 129 | #ifdef AEPHK_LIB_NAME | ||
| 130 | AEPHK_lib_name->error = ERR_PACK(AEPHK_lib_error_code,0,0); | ||
| 131 | ERR_load_strings(0,AEPHK_lib_name); | ||
| 132 | #endif | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | static void ERR_unload_AEPHK_strings(void) | ||
| 137 | { | ||
| 138 | if (AEPHK_error_init == 0) | ||
| 139 | { | ||
| 140 | #ifndef OPENSSL_NO_ERR | ||
| 141 | ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_functs); | ||
| 142 | ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_reasons); | ||
| 143 | #endif | ||
| 144 | |||
| 145 | #ifdef AEPHK_LIB_NAME | ||
| 146 | ERR_unload_strings(0,AEPHK_lib_name); | ||
| 147 | #endif | ||
| 148 | AEPHK_error_init=1; | ||
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | static void ERR_AEPHK_error(int function, int reason, char *file, int line) | ||
| 153 | { | ||
| 154 | if (AEPHK_lib_error_code == 0) | ||
| 155 | AEPHK_lib_error_code=ERR_get_next_error_library(); | ||
| 156 | ERR_PUT_error(AEPHK_lib_error_code,function,reason,file,line); | ||
| 157 | } | ||
diff --git a/src/lib/libcrypto/engine/hw_atalla_err.c b/src/lib/libcrypto/engine/hw_atalla_err.c deleted file mode 100644 index 1df9c4570c..0000000000 --- a/src/lib/libcrypto/engine/hw_atalla_err.c +++ /dev/null | |||
| @@ -1,145 +0,0 @@ | |||
| 1 | /* hw_atalla_err.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include "hw_atalla_err.h" | ||
| 64 | |||
| 65 | /* BEGIN ERROR CODES */ | ||
| 66 | #ifndef OPENSSL_NO_ERR | ||
| 67 | static ERR_STRING_DATA ATALLA_str_functs[]= | ||
| 68 | { | ||
| 69 | {ERR_PACK(0,ATALLA_F_ATALLA_CTRL,0), "ATALLA_CTRL"}, | ||
| 70 | {ERR_PACK(0,ATALLA_F_ATALLA_FINISH,0), "ATALLA_FINISH"}, | ||
| 71 | {ERR_PACK(0,ATALLA_F_ATALLA_INIT,0), "ATALLA_INIT"}, | ||
| 72 | {ERR_PACK(0,ATALLA_F_ATALLA_MOD_EXP,0), "ATALLA_MOD_EXP"}, | ||
| 73 | {ERR_PACK(0,ATALLA_F_ATALLA_RSA_MOD_EXP,0), "ATALLA_RSA_MOD_EXP"}, | ||
| 74 | {0,NULL} | ||
| 75 | }; | ||
| 76 | |||
| 77 | static ERR_STRING_DATA ATALLA_str_reasons[]= | ||
| 78 | { | ||
| 79 | {ATALLA_R_ALREADY_LOADED ,"already loaded"}, | ||
| 80 | {ATALLA_R_BN_CTX_FULL ,"bn ctx full"}, | ||
| 81 | {ATALLA_R_BN_EXPAND_FAIL ,"bn expand fail"}, | ||
| 82 | {ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | ||
| 83 | {ATALLA_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | ||
| 84 | {ATALLA_R_NOT_LOADED ,"not loaded"}, | ||
| 85 | {ATALLA_R_REQUEST_FAILED ,"request failed"}, | ||
| 86 | {ATALLA_R_UNIT_FAILURE ,"unit failure"}, | ||
| 87 | {0,NULL} | ||
| 88 | }; | ||
| 89 | |||
| 90 | #endif | ||
| 91 | |||
| 92 | #ifdef ATALLA_LIB_NAME | ||
| 93 | static ERR_STRING_DATA ATALLA_lib_name[]= | ||
| 94 | { | ||
| 95 | {0 ,ATALLA_LIB_NAME}, | ||
| 96 | {0,NULL} | ||
| 97 | }; | ||
| 98 | #endif | ||
| 99 | |||
| 100 | |||
| 101 | static int ATALLA_lib_error_code=0; | ||
| 102 | static int ATALLA_error_init=1; | ||
| 103 | |||
| 104 | static void ERR_load_ATALLA_strings(void) | ||
| 105 | { | ||
| 106 | if (ATALLA_lib_error_code == 0) | ||
| 107 | ATALLA_lib_error_code=ERR_get_next_error_library(); | ||
| 108 | |||
| 109 | if (ATALLA_error_init) | ||
| 110 | { | ||
| 111 | ATALLA_error_init=0; | ||
| 112 | #ifndef OPENSSL_NO_ERR | ||
| 113 | ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_functs); | ||
| 114 | ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_reasons); | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #ifdef ATALLA_LIB_NAME | ||
| 118 | ATALLA_lib_name->error = ERR_PACK(ATALLA_lib_error_code,0,0); | ||
| 119 | ERR_load_strings(0,ATALLA_lib_name); | ||
| 120 | #endif | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | static void ERR_unload_ATALLA_strings(void) | ||
| 125 | { | ||
| 126 | if (ATALLA_error_init == 0) | ||
| 127 | { | ||
| 128 | #ifndef OPENSSL_NO_ERR | ||
| 129 | ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_functs); | ||
| 130 | ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_reasons); | ||
| 131 | #endif | ||
| 132 | |||
| 133 | #ifdef ATALLA_LIB_NAME | ||
| 134 | ERR_unload_strings(0,ATALLA_lib_name); | ||
| 135 | #endif | ||
| 136 | ATALLA_error_init=1; | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | static void ERR_ATALLA_error(int function, int reason, char *file, int line) | ||
| 141 | { | ||
| 142 | if (ATALLA_lib_error_code == 0) | ||
| 143 | ATALLA_lib_error_code=ERR_get_next_error_library(); | ||
| 144 | ERR_PUT_error(ATALLA_lib_error_code,function,reason,file,line); | ||
| 145 | } | ||
diff --git a/src/lib/libcrypto/engine/hw_cryptodev.c b/src/lib/libcrypto/engine/hw_cryptodev.c deleted file mode 100644 index 3e7fff1c1e..0000000000 --- a/src/lib/libcrypto/engine/hw_cryptodev.c +++ /dev/null | |||
| @@ -1,1135 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2002 Bob Beck <beck@openbsd.org> | ||
| 3 | * Copyright (c) 2002 Theo de Raadt | ||
| 4 | * Copyright (c) 2002 Markus Friedl | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * 1. Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in the | ||
| 14 | * documentation and/or other materials provided with the distribution. | ||
| 15 | * | ||
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY | ||
| 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| 19 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY | ||
| 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
| 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | * | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include <openssl/objects.h> | ||
| 30 | #include <openssl/engine.h> | ||
| 31 | #include <openssl/evp.h> | ||
| 32 | |||
| 33 | #if (defined(__unix__) || defined(unix)) && !defined(USG) | ||
| 34 | #include <sys/param.h> | ||
| 35 | # if (OpenBSD >= 200112) || ((__FreeBSD_version >= 470101 && __FreeBSD_version < 500000) || __FreeBSD_version >= 500041) | ||
| 36 | # define HAVE_CRYPTODEV | ||
| 37 | # endif | ||
| 38 | # if (OpenBSD >= 200110) | ||
| 39 | # define HAVE_SYSLOG_R | ||
| 40 | # endif | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #ifndef HAVE_CRYPTODEV | ||
| 44 | |||
| 45 | void | ||
| 46 | ENGINE_load_cryptodev(void) | ||
| 47 | { | ||
| 48 | /* This is a NOP on platforms without /dev/crypto */ | ||
| 49 | return; | ||
| 50 | } | ||
| 51 | |||
| 52 | #else | ||
| 53 | |||
| 54 | #include <sys/types.h> | ||
| 55 | #include <crypto/cryptodev.h> | ||
| 56 | #include <sys/ioctl.h> | ||
| 57 | #include <errno.h> | ||
| 58 | #include <stdio.h> | ||
| 59 | #include <unistd.h> | ||
| 60 | #include <fcntl.h> | ||
| 61 | #include <stdarg.h> | ||
| 62 | #include <syslog.h> | ||
| 63 | #include <errno.h> | ||
| 64 | #include <string.h> | ||
| 65 | |||
| 66 | struct dev_crypto_state { | ||
| 67 | struct session_op d_sess; | ||
| 68 | int d_fd; | ||
| 69 | }; | ||
| 70 | |||
| 71 | static u_int32_t cryptodev_asymfeat = 0; | ||
| 72 | |||
| 73 | static int get_asym_dev_crypto(void); | ||
| 74 | static int open_dev_crypto(void); | ||
| 75 | static int get_dev_crypto(void); | ||
| 76 | static int cryptodev_max_iv(int cipher); | ||
| 77 | static int cryptodev_key_length_valid(int cipher, int len); | ||
| 78 | static int cipher_nid_to_cryptodev(int nid); | ||
| 79 | static int get_cryptodev_ciphers(const int **cnids); | ||
| 80 | /*static int get_cryptodev_digests(const int **cnids);*/ | ||
| 81 | static int cryptodev_usable_ciphers(const int **nids); | ||
| 82 | static int cryptodev_usable_digests(const int **nids); | ||
| 83 | static int cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 84 | const unsigned char *in, unsigned int inl); | ||
| 85 | static int cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 86 | const unsigned char *iv, int enc); | ||
| 87 | static int cryptodev_cleanup(EVP_CIPHER_CTX *ctx); | ||
| 88 | static int cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 89 | const int **nids, int nid); | ||
| 90 | static int cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest, | ||
| 91 | const int **nids, int nid); | ||
| 92 | static int bn2crparam(const BIGNUM *a, struct crparam *crp); | ||
| 93 | static int crparam2bn(struct crparam *crp, BIGNUM *a); | ||
| 94 | static void zapparams(struct crypt_kop *kop); | ||
| 95 | static int cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, | ||
| 96 | int slen, BIGNUM *s); | ||
| 97 | |||
| 98 | static int cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, | ||
| 99 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 100 | static int cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, | ||
| 101 | RSA *rsa); | ||
| 102 | static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa); | ||
| 103 | static int cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
| 104 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 105 | static int cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g, | ||
| 106 | BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p, | ||
| 107 | BN_CTX *ctx, BN_MONT_CTX *mont); | ||
| 108 | static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst, | ||
| 109 | int dlen, DSA *dsa); | ||
| 110 | static int cryptodev_dsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 111 | DSA_SIG *sig, DSA *dsa); | ||
| 112 | static int cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 113 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 114 | BN_MONT_CTX *m_ctx); | ||
| 115 | static int cryptodev_dh_compute_key(unsigned char *key, | ||
| 116 | const BIGNUM *pub_key, DH *dh); | ||
| 117 | static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, | ||
| 118 | void (*f)()); | ||
| 119 | void ENGINE_load_cryptodev(void); | ||
| 120 | |||
| 121 | static const ENGINE_CMD_DEFN cryptodev_defns[] = { | ||
| 122 | { 0, NULL, NULL, 0 } | ||
| 123 | }; | ||
| 124 | |||
| 125 | static struct { | ||
| 126 | int id; | ||
| 127 | int nid; | ||
| 128 | int ivmax; | ||
| 129 | int keylen; | ||
| 130 | } ciphers[] = { | ||
| 131 | { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, }, | ||
| 132 | { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, }, | ||
| 133 | { CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, }, | ||
| 134 | { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, }, | ||
| 135 | { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, }, | ||
| 136 | { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, }, | ||
| 137 | { 0, NID_undef, 0, 0, }, | ||
| 138 | }; | ||
| 139 | |||
| 140 | #if 0 /* UNUSED */ | ||
| 141 | static struct { | ||
| 142 | int id; | ||
| 143 | int nid; | ||
| 144 | } digests[] = { | ||
| 145 | { CRYPTO_SHA1_HMAC, NID_hmacWithSHA1, }, | ||
| 146 | { CRYPTO_RIPEMD160_HMAC, NID_ripemd160, }, | ||
| 147 | { CRYPTO_MD5_KPDK, NID_undef, }, | ||
| 148 | { CRYPTO_SHA1_KPDK, NID_undef, }, | ||
| 149 | { CRYPTO_MD5, NID_md5, }, | ||
| 150 | { CRYPTO_SHA1, NID_undef, }, | ||
| 151 | { 0, NID_undef, }, | ||
| 152 | }; | ||
| 153 | #endif | ||
| 154 | |||
| 155 | /* | ||
| 156 | * Return a fd if /dev/crypto seems usable, 0 otherwise. | ||
| 157 | */ | ||
| 158 | static int | ||
| 159 | open_dev_crypto(void) | ||
| 160 | { | ||
| 161 | static int fd = -1; | ||
| 162 | |||
| 163 | if (fd == -1) { | ||
| 164 | if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1) | ||
| 165 | return (-1); | ||
| 166 | /* close on exec */ | ||
| 167 | if (fcntl(fd, F_SETFD, 1) == -1) { | ||
| 168 | close(fd); | ||
| 169 | fd = -1; | ||
| 170 | return (-1); | ||
| 171 | } | ||
| 172 | } | ||
| 173 | return (fd); | ||
| 174 | } | ||
| 175 | |||
| 176 | static int | ||
| 177 | get_dev_crypto(void) | ||
| 178 | { | ||
| 179 | int fd, retfd; | ||
| 180 | |||
| 181 | if ((fd = open_dev_crypto()) == -1) | ||
| 182 | return (-1); | ||
| 183 | if (ioctl(fd, CRIOGET, &retfd) == -1) | ||
| 184 | return (-1); | ||
| 185 | |||
| 186 | /* close on exec */ | ||
| 187 | if (fcntl(retfd, F_SETFD, 1) == -1) { | ||
| 188 | close(retfd); | ||
| 189 | return (-1); | ||
| 190 | } | ||
| 191 | return (retfd); | ||
| 192 | } | ||
| 193 | |||
| 194 | /* Caching version for asym operations */ | ||
| 195 | static int | ||
| 196 | get_asym_dev_crypto(void) | ||
| 197 | { | ||
| 198 | static int fd = -1; | ||
| 199 | |||
| 200 | if (fd == -1) | ||
| 201 | fd = get_dev_crypto(); | ||
| 202 | return fd; | ||
| 203 | } | ||
| 204 | |||
| 205 | /* | ||
| 206 | * XXXX this needs to be set for each alg - and determined from | ||
| 207 | * a running card. | ||
| 208 | */ | ||
| 209 | static int | ||
| 210 | cryptodev_max_iv(int cipher) | ||
| 211 | { | ||
| 212 | int i; | ||
| 213 | |||
| 214 | for (i = 0; ciphers[i].id; i++) | ||
| 215 | if (ciphers[i].id == cipher) | ||
| 216 | return (ciphers[i].ivmax); | ||
| 217 | return (0); | ||
| 218 | } | ||
| 219 | |||
| 220 | /* | ||
| 221 | * XXXX this needs to be set for each alg - and determined from | ||
| 222 | * a running card. For now, fake it out - but most of these | ||
| 223 | * for real devices should return 1 for the supported key | ||
| 224 | * sizes the device can handle. | ||
| 225 | */ | ||
| 226 | static int | ||
| 227 | cryptodev_key_length_valid(int cipher, int len) | ||
| 228 | { | ||
| 229 | int i; | ||
| 230 | |||
| 231 | for (i = 0; ciphers[i].id; i++) | ||
| 232 | if (ciphers[i].id == cipher) | ||
| 233 | return (ciphers[i].keylen == len); | ||
| 234 | return (0); | ||
| 235 | } | ||
| 236 | |||
| 237 | /* convert libcrypto nids to cryptodev */ | ||
| 238 | static int | ||
| 239 | cipher_nid_to_cryptodev(int nid) | ||
| 240 | { | ||
| 241 | int i; | ||
| 242 | |||
| 243 | for (i = 0; ciphers[i].id; i++) | ||
| 244 | if (ciphers[i].nid == nid) | ||
| 245 | return (ciphers[i].id); | ||
| 246 | return (0); | ||
| 247 | } | ||
| 248 | |||
| 249 | /* | ||
| 250 | * Find out what ciphers /dev/crypto will let us have a session for. | ||
| 251 | * XXX note, that some of these openssl doesn't deal with yet! | ||
| 252 | * returning them here is harmless, as long as we return NULL | ||
| 253 | * when asked for a handler in the cryptodev_engine_ciphers routine | ||
| 254 | */ | ||
| 255 | static int | ||
| 256 | get_cryptodev_ciphers(const int **cnids) | ||
| 257 | { | ||
| 258 | static int nids[CRYPTO_ALGORITHM_MAX]; | ||
| 259 | struct session_op sess; | ||
| 260 | int fd, i, count = 0; | ||
| 261 | |||
| 262 | if ((fd = get_dev_crypto()) < 0) { | ||
| 263 | *cnids = NULL; | ||
| 264 | return (0); | ||
| 265 | } | ||
| 266 | memset(&sess, 0, sizeof(sess)); | ||
| 267 | sess.key = (caddr_t)"123456781234567812345678"; | ||
| 268 | |||
| 269 | for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) { | ||
| 270 | if (ciphers[i].nid == NID_undef) | ||
| 271 | continue; | ||
| 272 | sess.cipher = ciphers[i].id; | ||
| 273 | sess.keylen = ciphers[i].keylen; | ||
| 274 | sess.mac = 0; | ||
| 275 | if (ioctl(fd, CIOCGSESSION, &sess) != -1 && | ||
| 276 | ioctl(fd, CIOCFSESSION, &sess.ses) != -1) | ||
| 277 | nids[count++] = ciphers[i].nid; | ||
| 278 | } | ||
| 279 | close(fd); | ||
| 280 | |||
| 281 | if (count > 0) | ||
| 282 | *cnids = nids; | ||
| 283 | else | ||
| 284 | *cnids = NULL; | ||
| 285 | return (count); | ||
| 286 | } | ||
| 287 | |||
| 288 | /* | ||
| 289 | * Find out what digests /dev/crypto will let us have a session for. | ||
| 290 | * XXX note, that some of these openssl doesn't deal with yet! | ||
| 291 | * returning them here is harmless, as long as we return NULL | ||
| 292 | * when asked for a handler in the cryptodev_engine_digests routine | ||
| 293 | */ | ||
| 294 | #if 0 /* UNUSED */ | ||
| 295 | static int | ||
| 296 | get_cryptodev_digests(const int **cnids) | ||
| 297 | { | ||
| 298 | static int nids[CRYPTO_ALGORITHM_MAX]; | ||
| 299 | struct session_op sess; | ||
| 300 | int fd, i, count = 0; | ||
| 301 | |||
| 302 | if ((fd = get_dev_crypto()) < 0) { | ||
| 303 | *cnids = NULL; | ||
| 304 | return (0); | ||
| 305 | } | ||
| 306 | memset(&sess, 0, sizeof(sess)); | ||
| 307 | for (i = 0; digests[i].id && count < CRYPTO_ALGORITHM_MAX; i++) { | ||
| 308 | if (digests[i].nid == NID_undef) | ||
| 309 | continue; | ||
| 310 | sess.mac = digests[i].id; | ||
| 311 | sess.cipher = 0; | ||
| 312 | if (ioctl(fd, CIOCGSESSION, &sess) != -1 && | ||
| 313 | ioctl(fd, CIOCFSESSION, &sess.ses) != -1) | ||
| 314 | nids[count++] = digests[i].nid; | ||
| 315 | } | ||
| 316 | close(fd); | ||
| 317 | |||
| 318 | if (count > 0) | ||
| 319 | *cnids = nids; | ||
| 320 | else | ||
| 321 | *cnids = NULL; | ||
| 322 | return (count); | ||
| 323 | } | ||
| 324 | #endif | ||
| 325 | |||
| 326 | /* | ||
| 327 | * Find the useable ciphers|digests from dev/crypto - this is the first | ||
| 328 | * thing called by the engine init crud which determines what it | ||
| 329 | * can use for ciphers from this engine. We want to return | ||
| 330 | * only what we can do, anythine else is handled by software. | ||
| 331 | * | ||
| 332 | * If we can't initialize the device to do anything useful for | ||
| 333 | * any reason, we want to return a NULL array, and 0 length, | ||
| 334 | * which forces everything to be done is software. By putting | ||
| 335 | * the initalization of the device in here, we ensure we can | ||
| 336 | * use this engine as the default, and if for whatever reason | ||
| 337 | * /dev/crypto won't do what we want it will just be done in | ||
| 338 | * software | ||
| 339 | * | ||
| 340 | * This can (should) be greatly expanded to perhaps take into | ||
| 341 | * account speed of the device, and what we want to do. | ||
| 342 | * (although the disabling of particular alg's could be controlled | ||
| 343 | * by the device driver with sysctl's.) - this is where we | ||
| 344 | * want most of the decisions made about what we actually want | ||
| 345 | * to use from /dev/crypto. | ||
| 346 | */ | ||
| 347 | static int | ||
| 348 | cryptodev_usable_ciphers(const int **nids) | ||
| 349 | { | ||
| 350 | return (get_cryptodev_ciphers(nids)); | ||
| 351 | } | ||
| 352 | |||
| 353 | static int | ||
| 354 | cryptodev_usable_digests(const int **nids) | ||
| 355 | { | ||
| 356 | /* | ||
| 357 | * XXXX just disable all digests for now, because it sucks. | ||
| 358 | * we need a better way to decide this - i.e. I may not | ||
| 359 | * want digests on slow cards like hifn on fast machines, | ||
| 360 | * but might want them on slow or loaded machines, etc. | ||
| 361 | * will also want them when using crypto cards that don't | ||
| 362 | * suck moose gonads - would be nice to be able to decide something | ||
| 363 | * as reasonable default without having hackery that's card dependent. | ||
| 364 | * of course, the default should probably be just do everything, | ||
| 365 | * with perhaps a sysctl to turn algoritms off (or have them off | ||
| 366 | * by default) on cards that generally suck like the hifn. | ||
| 367 | */ | ||
| 368 | *nids = NULL; | ||
| 369 | return (0); | ||
| 370 | } | ||
| 371 | |||
| 372 | static int | ||
| 373 | cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 374 | const unsigned char *in, unsigned int inl) | ||
| 375 | { | ||
| 376 | struct crypt_op cryp; | ||
| 377 | struct dev_crypto_state *state = ctx->cipher_data; | ||
| 378 | struct session_op *sess = &state->d_sess; | ||
| 379 | void *iiv; | ||
| 380 | unsigned char save_iv[EVP_MAX_IV_LENGTH]; | ||
| 381 | |||
| 382 | if (state->d_fd < 0) | ||
| 383 | return (0); | ||
| 384 | if (!inl) | ||
| 385 | return (1); | ||
| 386 | if ((inl % ctx->cipher->block_size) != 0) | ||
| 387 | return (0); | ||
| 388 | |||
| 389 | memset(&cryp, 0, sizeof(cryp)); | ||
| 390 | |||
| 391 | cryp.ses = sess->ses; | ||
| 392 | cryp.flags = 0; | ||
| 393 | cryp.len = inl; | ||
| 394 | cryp.src = (caddr_t) in; | ||
| 395 | cryp.dst = (caddr_t) out; | ||
| 396 | cryp.mac = 0; | ||
| 397 | |||
| 398 | cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; | ||
| 399 | |||
| 400 | if (ctx->cipher->iv_len) { | ||
| 401 | cryp.iv = (caddr_t) ctx->iv; | ||
| 402 | if (!ctx->encrypt) { | ||
| 403 | iiv = (void *) in + inl - ctx->cipher->iv_len; | ||
| 404 | memcpy(save_iv, iiv, ctx->cipher->iv_len); | ||
| 405 | } | ||
| 406 | } else | ||
| 407 | cryp.iv = NULL; | ||
| 408 | |||
| 409 | if (ioctl(state->d_fd, CIOCCRYPT, &cryp) == -1) { | ||
| 410 | /* XXX need better errror handling | ||
| 411 | * this can fail for a number of different reasons. | ||
| 412 | */ | ||
| 413 | return (0); | ||
| 414 | } | ||
| 415 | |||
| 416 | if (ctx->cipher->iv_len) { | ||
| 417 | if (ctx->encrypt) | ||
| 418 | iiv = (void *) out + inl - ctx->cipher->iv_len; | ||
| 419 | else | ||
| 420 | iiv = save_iv; | ||
| 421 | memcpy(ctx->iv, iiv, ctx->cipher->iv_len); | ||
| 422 | } | ||
| 423 | return (1); | ||
| 424 | } | ||
| 425 | |||
| 426 | static int | ||
| 427 | cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 428 | const unsigned char *iv, int enc) | ||
| 429 | { | ||
| 430 | struct dev_crypto_state *state = ctx->cipher_data; | ||
| 431 | struct session_op *sess = &state->d_sess; | ||
| 432 | int cipher; | ||
| 433 | |||
| 434 | if ((cipher = cipher_nid_to_cryptodev(ctx->cipher->nid)) == NID_undef) | ||
| 435 | return (0); | ||
| 436 | |||
| 437 | if (ctx->cipher->iv_len > cryptodev_max_iv(cipher)) | ||
| 438 | return (0); | ||
| 439 | |||
| 440 | if (!cryptodev_key_length_valid(cipher, ctx->key_len)) | ||
| 441 | return (0); | ||
| 442 | |||
| 443 | memset(sess, 0, sizeof(struct session_op)); | ||
| 444 | |||
| 445 | if ((state->d_fd = get_dev_crypto()) < 0) | ||
| 446 | return (0); | ||
| 447 | |||
| 448 | sess->key = (unsigned char *)key; | ||
| 449 | sess->keylen = ctx->key_len; | ||
| 450 | sess->cipher = cipher; | ||
| 451 | |||
| 452 | if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) { | ||
| 453 | close(state->d_fd); | ||
| 454 | state->d_fd = -1; | ||
| 455 | return (0); | ||
| 456 | } | ||
| 457 | return (1); | ||
| 458 | } | ||
| 459 | |||
| 460 | /* | ||
| 461 | * free anything we allocated earlier when initting a | ||
| 462 | * session, and close the session. | ||
| 463 | */ | ||
| 464 | static int | ||
| 465 | cryptodev_cleanup(EVP_CIPHER_CTX *ctx) | ||
| 466 | { | ||
| 467 | int ret = 0; | ||
| 468 | struct dev_crypto_state *state = ctx->cipher_data; | ||
| 469 | struct session_op *sess = &state->d_sess; | ||
| 470 | |||
| 471 | if (state->d_fd < 0) | ||
| 472 | return (0); | ||
| 473 | |||
| 474 | /* XXX if this ioctl fails, someting's wrong. the invoker | ||
| 475 | * may have called us with a bogus ctx, or we could | ||
| 476 | * have a device that for whatever reason just doesn't | ||
| 477 | * want to play ball - it's not clear what's right | ||
| 478 | * here - should this be an error? should it just | ||
| 479 | * increase a counter, hmm. For right now, we return | ||
| 480 | * 0 - I don't believe that to be "right". we could | ||
| 481 | * call the gorpy openssl lib error handlers that | ||
| 482 | * print messages to users of the library. hmm.. | ||
| 483 | */ | ||
| 484 | |||
| 485 | if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) == -1) { | ||
| 486 | ret = 0; | ||
| 487 | } else { | ||
| 488 | ret = 1; | ||
| 489 | } | ||
| 490 | close(state->d_fd); | ||
| 491 | state->d_fd = -1; | ||
| 492 | |||
| 493 | return (ret); | ||
| 494 | } | ||
| 495 | |||
| 496 | /* | ||
| 497 | * libcrypto EVP stuff - this is how we get wired to EVP so the engine | ||
| 498 | * gets called when libcrypto requests a cipher NID. | ||
| 499 | */ | ||
| 500 | |||
| 501 | /* DES CBC EVP */ | ||
| 502 | const EVP_CIPHER cryptodev_des_cbc = { | ||
| 503 | NID_des_cbc, | ||
| 504 | 8, 8, 8, | ||
| 505 | EVP_CIPH_CBC_MODE, | ||
| 506 | cryptodev_init_key, | ||
| 507 | cryptodev_cipher, | ||
| 508 | cryptodev_cleanup, | ||
| 509 | sizeof(struct dev_crypto_state), | ||
| 510 | EVP_CIPHER_set_asn1_iv, | ||
| 511 | EVP_CIPHER_get_asn1_iv, | ||
| 512 | NULL | ||
| 513 | }; | ||
| 514 | |||
| 515 | /* 3DES CBC EVP */ | ||
| 516 | const EVP_CIPHER cryptodev_3des_cbc = { | ||
| 517 | NID_des_ede3_cbc, | ||
| 518 | 8, 24, 8, | ||
| 519 | EVP_CIPH_CBC_MODE, | ||
| 520 | cryptodev_init_key, | ||
| 521 | cryptodev_cipher, | ||
| 522 | cryptodev_cleanup, | ||
| 523 | sizeof(struct dev_crypto_state), | ||
| 524 | EVP_CIPHER_set_asn1_iv, | ||
| 525 | EVP_CIPHER_get_asn1_iv, | ||
| 526 | NULL | ||
| 527 | }; | ||
| 528 | |||
| 529 | const EVP_CIPHER cryptodev_bf_cbc = { | ||
| 530 | NID_bf_cbc, | ||
| 531 | 8, 16, 8, | ||
| 532 | EVP_CIPH_CBC_MODE, | ||
| 533 | cryptodev_init_key, | ||
| 534 | cryptodev_cipher, | ||
| 535 | cryptodev_cleanup, | ||
| 536 | sizeof(struct dev_crypto_state), | ||
| 537 | EVP_CIPHER_set_asn1_iv, | ||
| 538 | EVP_CIPHER_get_asn1_iv, | ||
| 539 | NULL | ||
| 540 | }; | ||
| 541 | |||
| 542 | const EVP_CIPHER cryptodev_cast_cbc = { | ||
| 543 | NID_cast5_cbc, | ||
| 544 | 8, 16, 8, | ||
| 545 | EVP_CIPH_CBC_MODE, | ||
| 546 | cryptodev_init_key, | ||
| 547 | cryptodev_cipher, | ||
| 548 | cryptodev_cleanup, | ||
| 549 | sizeof(struct dev_crypto_state), | ||
| 550 | EVP_CIPHER_set_asn1_iv, | ||
| 551 | EVP_CIPHER_get_asn1_iv, | ||
| 552 | NULL | ||
| 553 | }; | ||
| 554 | |||
| 555 | const EVP_CIPHER cryptodev_aes_cbc = { | ||
| 556 | NID_aes_128_cbc, | ||
| 557 | 16, 16, 16, | ||
| 558 | EVP_CIPH_CBC_MODE, | ||
| 559 | cryptodev_init_key, | ||
| 560 | cryptodev_cipher, | ||
| 561 | cryptodev_cleanup, | ||
| 562 | sizeof(struct dev_crypto_state), | ||
| 563 | EVP_CIPHER_set_asn1_iv, | ||
| 564 | EVP_CIPHER_get_asn1_iv, | ||
| 565 | NULL | ||
| 566 | }; | ||
| 567 | |||
| 568 | /* | ||
| 569 | * Registered by the ENGINE when used to find out how to deal with | ||
| 570 | * a particular NID in the ENGINE. this says what we'll do at the | ||
| 571 | * top level - note, that list is restricted by what we answer with | ||
| 572 | */ | ||
| 573 | static int | ||
| 574 | cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
| 575 | const int **nids, int nid) | ||
| 576 | { | ||
| 577 | if (!cipher) | ||
| 578 | return (cryptodev_usable_ciphers(nids)); | ||
| 579 | |||
| 580 | switch (nid) { | ||
| 581 | case NID_des_ede3_cbc: | ||
| 582 | *cipher = &cryptodev_3des_cbc; | ||
| 583 | break; | ||
| 584 | case NID_des_cbc: | ||
| 585 | *cipher = &cryptodev_des_cbc; | ||
| 586 | break; | ||
| 587 | case NID_bf_cbc: | ||
| 588 | *cipher = &cryptodev_bf_cbc; | ||
| 589 | break; | ||
| 590 | case NID_cast5_cbc: | ||
| 591 | *cipher = &cryptodev_cast_cbc; | ||
| 592 | break; | ||
| 593 | case NID_aes_128_cbc: | ||
| 594 | *cipher = &cryptodev_aes_cbc; | ||
| 595 | break; | ||
| 596 | default: | ||
| 597 | *cipher = NULL; | ||
| 598 | break; | ||
| 599 | } | ||
| 600 | return (*cipher != NULL); | ||
| 601 | } | ||
| 602 | |||
| 603 | static int | ||
| 604 | cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest, | ||
| 605 | const int **nids, int nid) | ||
| 606 | { | ||
| 607 | if (!digest) | ||
| 608 | return (cryptodev_usable_digests(nids)); | ||
| 609 | |||
| 610 | switch (nid) { | ||
| 611 | case NID_md5: | ||
| 612 | *digest = NULL; /* need to make a clean md5 critter */ | ||
| 613 | break; | ||
| 614 | default: | ||
| 615 | *digest = NULL; | ||
| 616 | break; | ||
| 617 | } | ||
| 618 | return (*digest != NULL); | ||
| 619 | } | ||
| 620 | |||
| 621 | /* | ||
| 622 | * Convert a BIGNUM to the representation that /dev/crypto needs. | ||
| 623 | * Upon completion of use, the caller is responsible for freeing | ||
| 624 | * crp->crp_p. | ||
| 625 | */ | ||
| 626 | static int | ||
| 627 | bn2crparam(const BIGNUM *a, struct crparam *crp) | ||
| 628 | { | ||
| 629 | int i, j, k; | ||
| 630 | ssize_t bytes, bits; | ||
| 631 | u_char *b; | ||
| 632 | |||
| 633 | crp->crp_p = NULL; | ||
| 634 | crp->crp_nbits = 0; | ||
| 635 | |||
| 636 | bits = BN_num_bits(a); | ||
| 637 | bytes = (bits + 7) / 8; | ||
| 638 | |||
| 639 | b = malloc(bytes); | ||
| 640 | if (b == NULL) | ||
| 641 | return (1); | ||
| 642 | |||
| 643 | crp->crp_p = b; | ||
| 644 | crp->crp_nbits = bits; | ||
| 645 | |||
| 646 | for (i = 0, j = 0; i < a->top; i++) { | ||
| 647 | for (k = 0; k < BN_BITS2 / 8; k++) { | ||
| 648 | if ((j + k) >= bytes) | ||
| 649 | return (0); | ||
| 650 | b[j + k] = a->d[i] >> (k * 8); | ||
| 651 | } | ||
| 652 | j += BN_BITS2 / 8; | ||
| 653 | } | ||
| 654 | return (0); | ||
| 655 | } | ||
| 656 | |||
| 657 | /* Convert a /dev/crypto parameter to a BIGNUM */ | ||
| 658 | static int | ||
| 659 | crparam2bn(struct crparam *crp, BIGNUM *a) | ||
| 660 | { | ||
| 661 | u_int8_t *pd; | ||
| 662 | int i, bytes; | ||
| 663 | |||
| 664 | bytes = (crp->crp_nbits + 7) / 8; | ||
| 665 | |||
| 666 | if (bytes == 0) | ||
| 667 | return (-1); | ||
| 668 | |||
| 669 | if ((pd = (u_int8_t *) malloc(bytes)) == NULL) | ||
| 670 | return (-1); | ||
| 671 | |||
| 672 | for (i = 0; i < bytes; i++) | ||
| 673 | pd[i] = crp->crp_p[bytes - i - 1]; | ||
| 674 | |||
| 675 | BN_bin2bn(pd, bytes, a); | ||
| 676 | free(pd); | ||
| 677 | |||
| 678 | return (0); | ||
| 679 | } | ||
| 680 | |||
| 681 | static void | ||
| 682 | zapparams(struct crypt_kop *kop) | ||
| 683 | { | ||
| 684 | int i; | ||
| 685 | |||
| 686 | for (i = 0; i <= kop->crk_iparams + kop->crk_oparams; i++) { | ||
| 687 | if (kop->crk_param[i].crp_p) | ||
| 688 | free(kop->crk_param[i].crp_p); | ||
| 689 | kop->crk_param[i].crp_p = NULL; | ||
| 690 | kop->crk_param[i].crp_nbits = 0; | ||
| 691 | } | ||
| 692 | } | ||
| 693 | |||
| 694 | static int | ||
| 695 | cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, BIGNUM *s) | ||
| 696 | { | ||
| 697 | int fd, ret = -1; | ||
| 698 | |||
| 699 | if ((fd = get_asym_dev_crypto()) < 0) | ||
| 700 | return (ret); | ||
| 701 | |||
| 702 | if (r) { | ||
| 703 | kop->crk_param[kop->crk_iparams].crp_p = calloc(rlen, sizeof(char)); | ||
| 704 | kop->crk_param[kop->crk_iparams].crp_nbits = rlen * 8; | ||
| 705 | kop->crk_oparams++; | ||
| 706 | } | ||
| 707 | if (s) { | ||
| 708 | kop->crk_param[kop->crk_iparams+1].crp_p = calloc(slen, sizeof(char)); | ||
| 709 | kop->crk_param[kop->crk_iparams+1].crp_nbits = slen * 8; | ||
| 710 | kop->crk_oparams++; | ||
| 711 | } | ||
| 712 | |||
| 713 | if (ioctl(fd, CIOCKEY, kop) == 0) { | ||
| 714 | if (r) | ||
| 715 | crparam2bn(&kop->crk_param[kop->crk_iparams], r); | ||
| 716 | if (s) | ||
| 717 | crparam2bn(&kop->crk_param[kop->crk_iparams+1], s); | ||
| 718 | ret = 0; | ||
| 719 | } | ||
| 720 | |||
| 721 | return (ret); | ||
| 722 | } | ||
| 723 | |||
| 724 | static int | ||
| 725 | cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 726 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
| 727 | { | ||
| 728 | struct crypt_kop kop; | ||
| 729 | int ret = 1; | ||
| 730 | |||
| 731 | /* Currently, we know we can do mod exp iff we can do any | ||
| 732 | * asymmetric operations at all. | ||
| 733 | */ | ||
| 734 | if (cryptodev_asymfeat == 0) { | ||
| 735 | ret = BN_mod_exp(r, a, p, m, ctx); | ||
| 736 | return (ret); | ||
| 737 | } | ||
| 738 | |||
| 739 | memset(&kop, 0, sizeof kop); | ||
| 740 | kop.crk_op = CRK_MOD_EXP; | ||
| 741 | |||
| 742 | /* inputs: a^p % m */ | ||
| 743 | if (bn2crparam(a, &kop.crk_param[0])) | ||
| 744 | goto err; | ||
| 745 | if (bn2crparam(p, &kop.crk_param[1])) | ||
| 746 | goto err; | ||
| 747 | if (bn2crparam(m, &kop.crk_param[2])) | ||
| 748 | goto err; | ||
| 749 | kop.crk_iparams = 3; | ||
| 750 | |||
| 751 | if (cryptodev_asym(&kop, BN_num_bytes(m), r, 0, NULL) == -1) { | ||
| 752 | const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 753 | ret = meth->bn_mod_exp(r, a, p, m, ctx, in_mont); | ||
| 754 | } | ||
| 755 | err: | ||
| 756 | zapparams(&kop); | ||
| 757 | return (ret); | ||
| 758 | } | ||
| 759 | |||
| 760 | static int | ||
| 761 | cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | ||
| 762 | { | ||
| 763 | int r; | ||
| 764 | BN_CTX *ctx; | ||
| 765 | |||
| 766 | ctx = BN_CTX_new(); | ||
| 767 | r = cryptodev_bn_mod_exp(r0, I, rsa->d, rsa->n, ctx, NULL); | ||
| 768 | BN_CTX_free(ctx); | ||
| 769 | return (r); | ||
| 770 | } | ||
| 771 | |||
| 772 | static int | ||
| 773 | cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | ||
| 774 | { | ||
| 775 | struct crypt_kop kop; | ||
| 776 | int ret = 1; | ||
| 777 | |||
| 778 | if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) { | ||
| 779 | /* XXX 0 means failure?? */ | ||
| 780 | return (0); | ||
| 781 | } | ||
| 782 | |||
| 783 | memset(&kop, 0, sizeof kop); | ||
| 784 | kop.crk_op = CRK_MOD_EXP_CRT; | ||
| 785 | /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */ | ||
| 786 | if (bn2crparam(rsa->p, &kop.crk_param[0])) | ||
| 787 | goto err; | ||
| 788 | if (bn2crparam(rsa->q, &kop.crk_param[1])) | ||
| 789 | goto err; | ||
| 790 | if (bn2crparam(I, &kop.crk_param[2])) | ||
| 791 | goto err; | ||
| 792 | if (bn2crparam(rsa->dmp1, &kop.crk_param[3])) | ||
| 793 | goto err; | ||
| 794 | if (bn2crparam(rsa->dmq1, &kop.crk_param[4])) | ||
| 795 | goto err; | ||
| 796 | if (bn2crparam(rsa->iqmp, &kop.crk_param[5])) | ||
| 797 | goto err; | ||
| 798 | kop.crk_iparams = 6; | ||
| 799 | |||
| 800 | if (cryptodev_asym(&kop, BN_num_bytes(rsa->n), r0, 0, NULL) == -1) { | ||
| 801 | const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 802 | ret = (*meth->rsa_mod_exp)(r0, I, rsa); | ||
| 803 | } | ||
| 804 | err: | ||
| 805 | zapparams(&kop); | ||
| 806 | return (ret); | ||
| 807 | } | ||
| 808 | |||
| 809 | static RSA_METHOD cryptodev_rsa = { | ||
| 810 | "cryptodev RSA method", | ||
| 811 | NULL, /* rsa_pub_enc */ | ||
| 812 | NULL, /* rsa_pub_dec */ | ||
| 813 | NULL, /* rsa_priv_enc */ | ||
| 814 | NULL, /* rsa_priv_dec */ | ||
| 815 | NULL, | ||
| 816 | NULL, | ||
| 817 | NULL, /* init */ | ||
| 818 | NULL, /* finish */ | ||
| 819 | 0, /* flags */ | ||
| 820 | NULL, /* app_data */ | ||
| 821 | NULL, /* rsa_sign */ | ||
| 822 | NULL /* rsa_verify */ | ||
| 823 | }; | ||
| 824 | |||
| 825 | static int | ||
| 826 | cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 827 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
| 828 | { | ||
| 829 | return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx)); | ||
| 830 | } | ||
| 831 | |||
| 832 | static int | ||
| 833 | cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g, | ||
| 834 | BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p, | ||
| 835 | BN_CTX *ctx, BN_MONT_CTX *mont) | ||
| 836 | { | ||
| 837 | BIGNUM t2; | ||
| 838 | int ret = 0; | ||
| 839 | |||
| 840 | BN_init(&t2); | ||
| 841 | |||
| 842 | /* v = ( g^u1 * y^u2 mod p ) mod q */ | ||
| 843 | /* let t1 = g ^ u1 mod p */ | ||
| 844 | ret = 0; | ||
| 845 | |||
| 846 | if (!dsa->meth->bn_mod_exp(dsa,t1,dsa->g,u1,dsa->p,ctx,mont)) | ||
| 847 | goto err; | ||
| 848 | |||
| 849 | /* let t2 = y ^ u2 mod p */ | ||
| 850 | if (!dsa->meth->bn_mod_exp(dsa,&t2,dsa->pub_key,u2,dsa->p,ctx,mont)) | ||
| 851 | goto err; | ||
| 852 | /* let u1 = t1 * t2 mod p */ | ||
| 853 | if (!BN_mod_mul(u1,t1,&t2,dsa->p,ctx)) | ||
| 854 | goto err; | ||
| 855 | |||
| 856 | BN_copy(t1,u1); | ||
| 857 | |||
| 858 | ret = 1; | ||
| 859 | err: | ||
| 860 | BN_free(&t2); | ||
| 861 | return(ret); | ||
| 862 | } | ||
| 863 | |||
| 864 | static DSA_SIG * | ||
| 865 | cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
| 866 | { | ||
| 867 | struct crypt_kop kop; | ||
| 868 | BIGNUM *r = NULL, *s = NULL; | ||
| 869 | DSA_SIG *dsaret = NULL; | ||
| 870 | |||
| 871 | if ((r = BN_new()) == NULL) | ||
| 872 | goto err; | ||
| 873 | if ((s = BN_new()) == NULL) { | ||
| 874 | BN_free(r); | ||
| 875 | goto err; | ||
| 876 | } | ||
| 877 | |||
| 878 | memset(&kop, 0, sizeof kop); | ||
| 879 | kop.crk_op = CRK_DSA_SIGN; | ||
| 880 | |||
| 881 | /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
| 882 | kop.crk_param[0].crp_p = (caddr_t)dgst; | ||
| 883 | kop.crk_param[0].crp_nbits = dlen * 8; | ||
| 884 | if (bn2crparam(dsa->p, &kop.crk_param[1])) | ||
| 885 | goto err; | ||
| 886 | if (bn2crparam(dsa->q, &kop.crk_param[2])) | ||
| 887 | goto err; | ||
| 888 | if (bn2crparam(dsa->g, &kop.crk_param[3])) | ||
| 889 | goto err; | ||
| 890 | if (bn2crparam(dsa->priv_key, &kop.crk_param[4])) | ||
| 891 | goto err; | ||
| 892 | kop.crk_iparams = 5; | ||
| 893 | |||
| 894 | if (cryptodev_asym(&kop, BN_num_bytes(dsa->q), r, | ||
| 895 | BN_num_bytes(dsa->q), s) == 0) { | ||
| 896 | dsaret = DSA_SIG_new(); | ||
| 897 | dsaret->r = r; | ||
| 898 | dsaret->s = s; | ||
| 899 | } else { | ||
| 900 | const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 901 | BN_free(r); | ||
| 902 | BN_free(s); | ||
| 903 | dsaret = (meth->dsa_do_sign)(dgst, dlen, dsa); | ||
| 904 | } | ||
| 905 | err: | ||
| 906 | kop.crk_param[0].crp_p = NULL; | ||
| 907 | zapparams(&kop); | ||
| 908 | return (dsaret); | ||
| 909 | } | ||
| 910 | |||
| 911 | static int | ||
| 912 | cryptodev_dsa_verify(const unsigned char *dgst, int dlen, | ||
| 913 | DSA_SIG *sig, DSA *dsa) | ||
| 914 | { | ||
| 915 | struct crypt_kop kop; | ||
| 916 | int dsaret = 1; | ||
| 917 | |||
| 918 | memset(&kop, 0, sizeof kop); | ||
| 919 | kop.crk_op = CRK_DSA_VERIFY; | ||
| 920 | |||
| 921 | /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */ | ||
| 922 | kop.crk_param[0].crp_p = (caddr_t)dgst; | ||
| 923 | kop.crk_param[0].crp_nbits = dlen * 8; | ||
| 924 | if (bn2crparam(dsa->p, &kop.crk_param[1])) | ||
| 925 | goto err; | ||
| 926 | if (bn2crparam(dsa->q, &kop.crk_param[2])) | ||
| 927 | goto err; | ||
| 928 | if (bn2crparam(dsa->g, &kop.crk_param[3])) | ||
| 929 | goto err; | ||
| 930 | if (bn2crparam(dsa->pub_key, &kop.crk_param[4])) | ||
| 931 | goto err; | ||
| 932 | if (bn2crparam(sig->r, &kop.crk_param[5])) | ||
| 933 | goto err; | ||
| 934 | if (bn2crparam(sig->s, &kop.crk_param[6])) | ||
| 935 | goto err; | ||
| 936 | kop.crk_iparams = 7; | ||
| 937 | |||
| 938 | if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
| 939 | dsaret = kop.crk_status; | ||
| 940 | } else { | ||
| 941 | const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 942 | |||
| 943 | dsaret = (meth->dsa_do_verify)(dgst, dlen, sig, dsa); | ||
| 944 | } | ||
| 945 | err: | ||
| 946 | kop.crk_param[0].crp_p = NULL; | ||
| 947 | zapparams(&kop); | ||
| 948 | return (dsaret); | ||
| 949 | } | ||
| 950 | |||
| 951 | static DSA_METHOD cryptodev_dsa = { | ||
| 952 | "cryptodev DSA method", | ||
| 953 | NULL, | ||
| 954 | NULL, /* dsa_sign_setup */ | ||
| 955 | NULL, | ||
| 956 | NULL, /* dsa_mod_exp */ | ||
| 957 | NULL, | ||
| 958 | NULL, /* init */ | ||
| 959 | NULL, /* finish */ | ||
| 960 | 0, /* flags */ | ||
| 961 | NULL /* app_data */ | ||
| 962 | }; | ||
| 963 | |||
| 964 | static int | ||
| 965 | cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 966 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 967 | BN_MONT_CTX *m_ctx) | ||
| 968 | { | ||
| 969 | return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx)); | ||
| 970 | } | ||
| 971 | |||
| 972 | static int | ||
| 973 | cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | ||
| 974 | { | ||
| 975 | struct crypt_kop kop; | ||
| 976 | int dhret = 1; | ||
| 977 | int fd, keylen; | ||
| 978 | |||
| 979 | if ((fd = get_asym_dev_crypto()) < 0) { | ||
| 980 | const DH_METHOD *meth = DH_OpenSSL(); | ||
| 981 | |||
| 982 | return ((meth->compute_key)(key, pub_key, dh)); | ||
| 983 | } | ||
| 984 | |||
| 985 | keylen = BN_num_bits(dh->p); | ||
| 986 | |||
| 987 | memset(&kop, 0, sizeof kop); | ||
| 988 | kop.crk_op = CRK_DH_COMPUTE_KEY; | ||
| 989 | |||
| 990 | /* inputs: dh->priv_key pub_key dh->p key */ | ||
| 991 | if (bn2crparam(dh->priv_key, &kop.crk_param[0])) | ||
| 992 | goto err; | ||
| 993 | if (bn2crparam(pub_key, &kop.crk_param[1])) | ||
| 994 | goto err; | ||
| 995 | if (bn2crparam(dh->p, &kop.crk_param[2])) | ||
| 996 | goto err; | ||
| 997 | kop.crk_iparams = 3; | ||
| 998 | |||
| 999 | kop.crk_param[3].crp_p = key; | ||
| 1000 | kop.crk_param[3].crp_nbits = keylen * 8; | ||
| 1001 | kop.crk_oparams = 1; | ||
| 1002 | |||
| 1003 | if (ioctl(fd, CIOCKEY, &kop) == -1) { | ||
| 1004 | const DH_METHOD *meth = DH_OpenSSL(); | ||
| 1005 | |||
| 1006 | dhret = (meth->compute_key)(key, pub_key, dh); | ||
| 1007 | } | ||
| 1008 | err: | ||
| 1009 | kop.crk_param[3].crp_p = NULL; | ||
| 1010 | zapparams(&kop); | ||
| 1011 | return (dhret); | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | static DH_METHOD cryptodev_dh = { | ||
| 1015 | "cryptodev DH method", | ||
| 1016 | NULL, /* cryptodev_dh_generate_key */ | ||
| 1017 | NULL, | ||
| 1018 | NULL, | ||
| 1019 | NULL, | ||
| 1020 | NULL, | ||
| 1021 | 0, /* flags */ | ||
| 1022 | NULL /* app_data */ | ||
| 1023 | }; | ||
| 1024 | |||
| 1025 | /* | ||
| 1026 | * ctrl right now is just a wrapper that doesn't do much | ||
| 1027 | * but I expect we'll want some options soon. | ||
| 1028 | */ | ||
| 1029 | static int | ||
| 1030 | cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
| 1031 | { | ||
| 1032 | #ifdef HAVE_SYSLOG_R | ||
| 1033 | struct syslog_data sd = SYSLOG_DATA_INIT; | ||
| 1034 | #endif | ||
| 1035 | |||
| 1036 | switch (cmd) { | ||
| 1037 | default: | ||
| 1038 | #ifdef HAVE_SYSLOG_R | ||
| 1039 | syslog_r(LOG_ERR, &sd, | ||
| 1040 | "cryptodev_ctrl: unknown command %d", cmd); | ||
| 1041 | #else | ||
| 1042 | syslog(LOG_ERR, "cryptodev_ctrl: unknown command %d", cmd); | ||
| 1043 | #endif | ||
| 1044 | break; | ||
| 1045 | } | ||
| 1046 | return (1); | ||
| 1047 | } | ||
| 1048 | |||
| 1049 | void | ||
| 1050 | ENGINE_load_cryptodev(void) | ||
| 1051 | { | ||
| 1052 | ENGINE *engine = ENGINE_new(); | ||
| 1053 | int fd; | ||
| 1054 | |||
| 1055 | if (engine == NULL) | ||
| 1056 | return; | ||
| 1057 | if ((fd = get_dev_crypto()) < 0) { | ||
| 1058 | ENGINE_free(engine); | ||
| 1059 | return; | ||
| 1060 | } | ||
| 1061 | |||
| 1062 | /* | ||
| 1063 | * find out what asymmetric crypto algorithms we support | ||
| 1064 | */ | ||
| 1065 | if (ioctl(fd, CIOCASYMFEAT, &cryptodev_asymfeat) == -1) { | ||
| 1066 | close(fd); | ||
| 1067 | ENGINE_free(engine); | ||
| 1068 | return; | ||
| 1069 | } | ||
| 1070 | close(fd); | ||
| 1071 | |||
| 1072 | if (!ENGINE_set_id(engine, "cryptodev") || | ||
| 1073 | !ENGINE_set_name(engine, "BSD cryptodev engine") || | ||
| 1074 | !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) || | ||
| 1075 | !ENGINE_set_digests(engine, cryptodev_engine_digests) || | ||
| 1076 | !ENGINE_set_ctrl_function(engine, cryptodev_ctrl) || | ||
| 1077 | !ENGINE_set_cmd_defns(engine, cryptodev_defns)) { | ||
| 1078 | ENGINE_free(engine); | ||
| 1079 | return; | ||
| 1080 | } | ||
| 1081 | |||
| 1082 | if (ENGINE_set_RSA(engine, &cryptodev_rsa)) { | ||
| 1083 | const RSA_METHOD *rsa_meth = RSA_PKCS1_SSLeay(); | ||
| 1084 | |||
| 1085 | cryptodev_rsa.bn_mod_exp = rsa_meth->bn_mod_exp; | ||
| 1086 | cryptodev_rsa.rsa_mod_exp = rsa_meth->rsa_mod_exp; | ||
| 1087 | cryptodev_rsa.rsa_pub_enc = rsa_meth->rsa_pub_enc; | ||
| 1088 | cryptodev_rsa.rsa_pub_dec = rsa_meth->rsa_pub_dec; | ||
| 1089 | cryptodev_rsa.rsa_priv_enc = rsa_meth->rsa_priv_enc; | ||
| 1090 | cryptodev_rsa.rsa_priv_dec = rsa_meth->rsa_priv_dec; | ||
| 1091 | if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
| 1092 | cryptodev_rsa.bn_mod_exp = cryptodev_bn_mod_exp; | ||
| 1093 | if (cryptodev_asymfeat & CRF_MOD_EXP_CRT) | ||
| 1094 | cryptodev_rsa.rsa_mod_exp = | ||
| 1095 | cryptodev_rsa_mod_exp; | ||
| 1096 | else | ||
| 1097 | cryptodev_rsa.rsa_mod_exp = | ||
| 1098 | cryptodev_rsa_nocrt_mod_exp; | ||
| 1099 | } | ||
| 1100 | } | ||
| 1101 | |||
| 1102 | if (ENGINE_set_DSA(engine, &cryptodev_dsa)) { | ||
| 1103 | const DSA_METHOD *meth = DSA_OpenSSL(); | ||
| 1104 | |||
| 1105 | memcpy(&cryptodev_dsa, meth, sizeof(DSA_METHOD)); | ||
| 1106 | if (cryptodev_asymfeat & CRF_DSA_SIGN) | ||
| 1107 | cryptodev_dsa.dsa_do_sign = cryptodev_dsa_do_sign; | ||
| 1108 | if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
| 1109 | cryptodev_dsa.bn_mod_exp = cryptodev_dsa_bn_mod_exp; | ||
| 1110 | cryptodev_dsa.dsa_mod_exp = cryptodev_dsa_dsa_mod_exp; | ||
| 1111 | } | ||
| 1112 | if (cryptodev_asymfeat & CRF_DSA_VERIFY) | ||
| 1113 | cryptodev_dsa.dsa_do_verify = cryptodev_dsa_verify; | ||
| 1114 | } | ||
| 1115 | |||
| 1116 | if (ENGINE_set_DH(engine, &cryptodev_dh)){ | ||
| 1117 | const DH_METHOD *dh_meth = DH_OpenSSL(); | ||
| 1118 | |||
| 1119 | cryptodev_dh.generate_key = dh_meth->generate_key; | ||
| 1120 | cryptodev_dh.compute_key = dh_meth->compute_key; | ||
| 1121 | cryptodev_dh.bn_mod_exp = dh_meth->bn_mod_exp; | ||
| 1122 | if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
| 1123 | cryptodev_dh.bn_mod_exp = cryptodev_mod_exp_dh; | ||
| 1124 | if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) | ||
| 1125 | cryptodev_dh.compute_key = | ||
| 1126 | cryptodev_dh_compute_key; | ||
| 1127 | } | ||
| 1128 | } | ||
| 1129 | |||
| 1130 | ENGINE_add(engine); | ||
| 1131 | ENGINE_free(engine); | ||
| 1132 | ERR_clear_error(); | ||
| 1133 | } | ||
| 1134 | |||
| 1135 | #endif /* HAVE_CRYPTODEV */ | ||
diff --git a/src/lib/libcrypto/engine/hw_cswift_err.c b/src/lib/libcrypto/engine/hw_cswift_err.c deleted file mode 100644 index 684f53bf27..0000000000 --- a/src/lib/libcrypto/engine/hw_cswift_err.c +++ /dev/null | |||
| @@ -1,149 +0,0 @@ | |||
| 1 | /* hw_cswift_err.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include "hw_cswift_err.h" | ||
| 64 | |||
| 65 | /* BEGIN ERROR CODES */ | ||
| 66 | #ifndef OPENSSL_NO_ERR | ||
| 67 | static ERR_STRING_DATA CSWIFT_str_functs[]= | ||
| 68 | { | ||
| 69 | {ERR_PACK(0,CSWIFT_F_CSWIFT_CTRL,0), "CSWIFT_CTRL"}, | ||
| 70 | {ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_SIGN,0), "CSWIFT_DSA_SIGN"}, | ||
| 71 | {ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_VERIFY,0), "CSWIFT_DSA_VERIFY"}, | ||
| 72 | {ERR_PACK(0,CSWIFT_F_CSWIFT_FINISH,0), "CSWIFT_FINISH"}, | ||
| 73 | {ERR_PACK(0,CSWIFT_F_CSWIFT_INIT,0), "CSWIFT_INIT"}, | ||
| 74 | {ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP,0), "CSWIFT_MOD_EXP"}, | ||
| 75 | {ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP_CRT,0), "CSWIFT_MOD_EXP_CRT"}, | ||
| 76 | {ERR_PACK(0,CSWIFT_F_CSWIFT_RSA_MOD_EXP,0), "CSWIFT_RSA_MOD_EXP"}, | ||
| 77 | {0,NULL} | ||
| 78 | }; | ||
| 79 | |||
| 80 | static ERR_STRING_DATA CSWIFT_str_reasons[]= | ||
| 81 | { | ||
| 82 | {CSWIFT_R_ALREADY_LOADED ,"already loaded"}, | ||
| 83 | {CSWIFT_R_BAD_KEY_SIZE ,"bad key size"}, | ||
| 84 | {CSWIFT_R_BN_CTX_FULL ,"bn ctx full"}, | ||
| 85 | {CSWIFT_R_BN_EXPAND_FAIL ,"bn expand fail"}, | ||
| 86 | {CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | ||
| 87 | {CSWIFT_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | ||
| 88 | {CSWIFT_R_NOT_LOADED ,"not loaded"}, | ||
| 89 | {CSWIFT_R_REQUEST_FAILED ,"request failed"}, | ||
| 90 | {CSWIFT_R_UNIT_FAILURE ,"unit failure"}, | ||
| 91 | {0,NULL} | ||
| 92 | }; | ||
| 93 | |||
| 94 | #endif | ||
| 95 | |||
| 96 | #ifdef CSWIFT_LIB_NAME | ||
| 97 | static ERR_STRING_DATA CSWIFT_lib_name[]= | ||
| 98 | { | ||
| 99 | {0 ,CSWIFT_LIB_NAME}, | ||
| 100 | {0,NULL} | ||
| 101 | }; | ||
| 102 | #endif | ||
| 103 | |||
| 104 | |||
| 105 | static int CSWIFT_lib_error_code=0; | ||
| 106 | static int CSWIFT_error_init=1; | ||
| 107 | |||
| 108 | static void ERR_load_CSWIFT_strings(void) | ||
| 109 | { | ||
| 110 | if (CSWIFT_lib_error_code == 0) | ||
| 111 | CSWIFT_lib_error_code=ERR_get_next_error_library(); | ||
| 112 | |||
| 113 | if (CSWIFT_error_init) | ||
| 114 | { | ||
| 115 | CSWIFT_error_init=0; | ||
| 116 | #ifndef OPENSSL_NO_ERR | ||
| 117 | ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_functs); | ||
| 118 | ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons); | ||
| 119 | #endif | ||
| 120 | |||
| 121 | #ifdef CSWIFT_LIB_NAME | ||
| 122 | CSWIFT_lib_name->error = ERR_PACK(CSWIFT_lib_error_code,0,0); | ||
| 123 | ERR_load_strings(0,CSWIFT_lib_name); | ||
| 124 | #endif | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | static void ERR_unload_CSWIFT_strings(void) | ||
| 129 | { | ||
| 130 | if (CSWIFT_error_init == 0) | ||
| 131 | { | ||
| 132 | #ifndef OPENSSL_NO_ERR | ||
| 133 | ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_functs); | ||
| 134 | ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons); | ||
| 135 | #endif | ||
| 136 | |||
| 137 | #ifdef CSWIFT_LIB_NAME | ||
| 138 | ERR_unload_strings(0,CSWIFT_lib_name); | ||
| 139 | #endif | ||
| 140 | CSWIFT_error_init=1; | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | static void ERR_CSWIFT_error(int function, int reason, char *file, int line) | ||
| 145 | { | ||
| 146 | if (CSWIFT_lib_error_code == 0) | ||
| 147 | CSWIFT_lib_error_code=ERR_get_next_error_library(); | ||
| 148 | ERR_PUT_error(CSWIFT_lib_error_code,function,reason,file,line); | ||
| 149 | } | ||
diff --git a/src/lib/libcrypto/engine/hw_ncipher.c b/src/lib/libcrypto/engine/hw_ncipher.c deleted file mode 100644 index 0d1c6b8df0..0000000000 --- a/src/lib/libcrypto/engine/hw_ncipher.c +++ /dev/null | |||
| @@ -1,1388 +0,0 @@ | |||
| 1 | /* crypto/engine/hw_ncipher.c -*- mode: C; c-file-style: "eay" -*- */ | ||
| 2 | /* Written by Richard Levitte (richard@levitte.org), Geoff Thorpe | ||
| 3 | * (geoff@geoffthorpe.net) and Dr Stephen N Henson (shenson@bigfoot.com) | ||
| 4 | * for the OpenSSL project 2000. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * licensing@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | |||
| 60 | #include <stdio.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include <openssl/crypto.h> | ||
| 64 | #include <openssl/pem.h> | ||
| 65 | #include <openssl/dso.h> | ||
| 66 | #include <openssl/engine.h> | ||
| 67 | #include <openssl/ui.h> | ||
| 68 | |||
| 69 | #ifndef OPENSSL_NO_HW | ||
| 70 | #ifndef OPENSSL_NO_HW_NCIPHER | ||
| 71 | |||
| 72 | /* Attribution notice: nCipher have said several times that it's OK for | ||
| 73 | * us to implement a general interface to their boxes, and recently declared | ||
| 74 | * their HWCryptoHook to be public, and therefore available for us to use. | ||
| 75 | * Thanks, nCipher. | ||
| 76 | * | ||
| 77 | * The hwcryptohook.h included here is from May 2000. | ||
| 78 | * [Richard Levitte] | ||
| 79 | */ | ||
| 80 | #ifdef FLAT_INC | ||
| 81 | #include "hwcryptohook.h" | ||
| 82 | #else | ||
| 83 | #include "vendor_defns/hwcryptohook.h" | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #define HWCRHK_LIB_NAME "hwcrhk engine" | ||
| 87 | #include "hw_ncipher_err.c" | ||
| 88 | |||
| 89 | static int hwcrhk_destroy(ENGINE *e); | ||
| 90 | static int hwcrhk_init(ENGINE *e); | ||
| 91 | static int hwcrhk_finish(ENGINE *e); | ||
| 92 | static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
| 93 | |||
| 94 | /* Functions to handle mutexes if have dynamic locks */ | ||
| 95 | static int hwcrhk_mutex_init(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext*); | ||
| 96 | static int hwcrhk_mutex_lock(HWCryptoHook_Mutex*); | ||
| 97 | static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex*); | ||
| 98 | static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex*); | ||
| 99 | #if 1 /* This is a HACK which will disappear in 0.9.8 */ | ||
| 100 | /* Functions to handle mutexes if only have static locks */ | ||
| 101 | static int hwcrhk_static_mutex_init(HWCryptoHook_Mutex *m, | ||
| 102 | HWCryptoHook_CallerContext *c); | ||
| 103 | static int hwcrhk_static_mutex_lock(HWCryptoHook_Mutex *m); | ||
| 104 | static void hwcrhk_static_mutex_unlock(HWCryptoHook_Mutex *m); | ||
| 105 | static void hwcrhk_static_mutex_destroy(HWCryptoHook_Mutex *m); | ||
| 106 | #endif | ||
| 107 | |||
| 108 | /* BIGNUM stuff */ | ||
| 109 | static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 110 | const BIGNUM *m, BN_CTX *ctx); | ||
| 111 | |||
| 112 | #ifndef OPENSSL_NO_RSA | ||
| 113 | /* RSA stuff */ | ||
| 114 | static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa); | ||
| 115 | #endif | ||
| 116 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
| 117 | static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 118 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 119 | |||
| 120 | #ifndef OPENSSL_NO_DH | ||
| 121 | /* DH stuff */ | ||
| 122 | /* This function is alised to mod_exp (with the DH and mont dropped). */ | ||
| 123 | static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r, | ||
| 124 | const BIGNUM *a, const BIGNUM *p, | ||
| 125 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 126 | #endif | ||
| 127 | |||
| 128 | /* RAND stuff */ | ||
| 129 | static int hwcrhk_rand_bytes(unsigned char *buf, int num); | ||
| 130 | static int hwcrhk_rand_status(void); | ||
| 131 | |||
| 132 | /* KM stuff */ | ||
| 133 | static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id, | ||
| 134 | UI_METHOD *ui_method, void *callback_data); | ||
| 135 | static EVP_PKEY *hwcrhk_load_pubkey(ENGINE *eng, const char *key_id, | ||
| 136 | UI_METHOD *ui_method, void *callback_data); | ||
| 137 | static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
| 138 | int ind,long argl, void *argp); | ||
| 139 | |||
| 140 | /* Interaction stuff */ | ||
| 141 | static int hwcrhk_insert_card(const char *prompt_info, | ||
| 142 | const char *wrong_info, | ||
| 143 | HWCryptoHook_PassphraseContext *ppctx, | ||
| 144 | HWCryptoHook_CallerContext *cactx); | ||
| 145 | static int hwcrhk_get_pass(const char *prompt_info, | ||
| 146 | int *len_io, char *buf, | ||
| 147 | HWCryptoHook_PassphraseContext *ppctx, | ||
| 148 | HWCryptoHook_CallerContext *cactx); | ||
| 149 | static void hwcrhk_log_message(void *logstr, const char *message); | ||
| 150 | |||
| 151 | /* The definitions for control commands specific to this engine */ | ||
| 152 | #define HWCRHK_CMD_SO_PATH ENGINE_CMD_BASE | ||
| 153 | #define HWCRHK_CMD_FORK_CHECK (ENGINE_CMD_BASE + 1) | ||
| 154 | #define HWCRHK_CMD_THREAD_LOCKING (ENGINE_CMD_BASE + 2) | ||
| 155 | #define HWCRHK_CMD_SET_USER_INTERFACE (ENGINE_CMD_BASE + 3) | ||
| 156 | #define HWCRHK_CMD_SET_CALLBACK_DATA (ENGINE_CMD_BASE + 4) | ||
| 157 | static const ENGINE_CMD_DEFN hwcrhk_cmd_defns[] = { | ||
| 158 | {HWCRHK_CMD_SO_PATH, | ||
| 159 | "SO_PATH", | ||
| 160 | "Specifies the path to the 'hwcrhk' shared library", | ||
| 161 | ENGINE_CMD_FLAG_STRING}, | ||
| 162 | {HWCRHK_CMD_FORK_CHECK, | ||
| 163 | "FORK_CHECK", | ||
| 164 | "Turns fork() checking on or off (boolean)", | ||
| 165 | ENGINE_CMD_FLAG_NUMERIC}, | ||
| 166 | {HWCRHK_CMD_THREAD_LOCKING, | ||
| 167 | "THREAD_LOCKING", | ||
| 168 | "Turns thread-safe locking on or off (boolean)", | ||
| 169 | ENGINE_CMD_FLAG_NUMERIC}, | ||
| 170 | {HWCRHK_CMD_SET_USER_INTERFACE, | ||
| 171 | "SET_USER_INTERFACE", | ||
| 172 | "Set the global user interface (internal)", | ||
| 173 | ENGINE_CMD_FLAG_INTERNAL}, | ||
| 174 | {HWCRHK_CMD_SET_CALLBACK_DATA, | ||
| 175 | "SET_CALLBACK_DATA", | ||
| 176 | "Set the global user interface extra data (internal)", | ||
| 177 | ENGINE_CMD_FLAG_INTERNAL}, | ||
| 178 | {0, NULL, NULL, 0} | ||
| 179 | }; | ||
| 180 | |||
| 181 | #ifndef OPENSSL_NO_RSA | ||
| 182 | /* Our internal RSA_METHOD that we provide pointers to */ | ||
| 183 | static RSA_METHOD hwcrhk_rsa = | ||
| 184 | { | ||
| 185 | "nCipher RSA method", | ||
| 186 | NULL, | ||
| 187 | NULL, | ||
| 188 | NULL, | ||
| 189 | NULL, | ||
| 190 | hwcrhk_rsa_mod_exp, | ||
| 191 | hwcrhk_mod_exp_mont, | ||
| 192 | NULL, | ||
| 193 | NULL, | ||
| 194 | 0, | ||
| 195 | NULL, | ||
| 196 | NULL, | ||
| 197 | NULL | ||
| 198 | }; | ||
| 199 | #endif | ||
| 200 | |||
| 201 | #ifndef OPENSSL_NO_DH | ||
| 202 | /* Our internal DH_METHOD that we provide pointers to */ | ||
| 203 | static DH_METHOD hwcrhk_dh = | ||
| 204 | { | ||
| 205 | "nCipher DH method", | ||
| 206 | NULL, | ||
| 207 | NULL, | ||
| 208 | hwcrhk_mod_exp_dh, | ||
| 209 | NULL, | ||
| 210 | NULL, | ||
| 211 | 0, | ||
| 212 | NULL | ||
| 213 | }; | ||
| 214 | #endif | ||
| 215 | |||
| 216 | static RAND_METHOD hwcrhk_rand = | ||
| 217 | { | ||
| 218 | /* "nCipher RAND method", */ | ||
| 219 | NULL, | ||
| 220 | hwcrhk_rand_bytes, | ||
| 221 | NULL, | ||
| 222 | NULL, | ||
| 223 | hwcrhk_rand_bytes, | ||
| 224 | hwcrhk_rand_status, | ||
| 225 | }; | ||
| 226 | |||
| 227 | /* Constants used when creating the ENGINE */ | ||
| 228 | static const char *engine_hwcrhk_id = "chil"; | ||
| 229 | static const char *engine_hwcrhk_name = "nCipher hardware engine support"; | ||
| 230 | |||
| 231 | /* Internal stuff for HWCryptoHook */ | ||
| 232 | |||
| 233 | /* Some structures needed for proper use of thread locks */ | ||
| 234 | /* hwcryptohook.h has some typedefs that turn struct HWCryptoHook_MutexValue | ||
| 235 | into HWCryptoHook_Mutex */ | ||
| 236 | struct HWCryptoHook_MutexValue | ||
| 237 | { | ||
| 238 | int lockid; | ||
| 239 | }; | ||
| 240 | |||
| 241 | /* hwcryptohook.h has some typedefs that turn | ||
| 242 | struct HWCryptoHook_PassphraseContextValue | ||
| 243 | into HWCryptoHook_PassphraseContext */ | ||
| 244 | struct HWCryptoHook_PassphraseContextValue | ||
| 245 | { | ||
| 246 | UI_METHOD *ui_method; | ||
| 247 | void *callback_data; | ||
| 248 | }; | ||
| 249 | |||
| 250 | /* hwcryptohook.h has some typedefs that turn | ||
| 251 | struct HWCryptoHook_CallerContextValue | ||
| 252 | into HWCryptoHook_CallerContext */ | ||
| 253 | struct HWCryptoHook_CallerContextValue | ||
| 254 | { | ||
| 255 | pem_password_cb *password_callback; /* Deprecated! Only present for | ||
| 256 | backward compatibility! */ | ||
| 257 | UI_METHOD *ui_method; | ||
| 258 | void *callback_data; | ||
| 259 | }; | ||
| 260 | |||
| 261 | /* The MPI structure in HWCryptoHook is pretty compatible with OpenSSL | ||
| 262 | BIGNUM's, so lets define a couple of conversion macros */ | ||
| 263 | #define BN2MPI(mp, bn) \ | ||
| 264 | {mp.size = bn->top * sizeof(BN_ULONG); mp.buf = (unsigned char *)bn->d;} | ||
| 265 | #define MPI2BN(bn, mp) \ | ||
| 266 | {mp.size = bn->dmax * sizeof(BN_ULONG); mp.buf = (unsigned char *)bn->d;} | ||
| 267 | |||
| 268 | static BIO *logstream = NULL; | ||
| 269 | static int disable_mutex_callbacks = 0; | ||
| 270 | |||
| 271 | /* One might wonder why these are needed, since one can pass down at least | ||
| 272 | a UI_METHOD and a pointer to callback data to the key-loading functions. | ||
| 273 | The thing is that the ModExp and RSAImmed functions can load keys as well, | ||
| 274 | if the data they get is in a special, nCipher-defined format (hint: if you | ||
| 275 | look at the private exponent of the RSA data as a string, you'll see this | ||
| 276 | string: "nCipher KM tool key id", followed by some bytes, followed a key | ||
| 277 | identity string, followed by more bytes. This happens when you use "embed" | ||
| 278 | keys instead of "hwcrhk" keys). Unfortunately, those functions do not take | ||
| 279 | any passphrase or caller context, and our functions can't really take any | ||
| 280 | callback data either. Still, the "insert_card" and "get_passphrase" | ||
| 281 | callbacks may be called down the line, and will need to know what user | ||
| 282 | interface callbacks to call, and having callback data from the application | ||
| 283 | may be a nice thing as well, so we need to keep track of that globally. */ | ||
| 284 | static HWCryptoHook_CallerContext password_context = { NULL, NULL, NULL }; | ||
| 285 | |||
| 286 | /* Stuff to pass to the HWCryptoHook library */ | ||
| 287 | static HWCryptoHook_InitInfo hwcrhk_globals = { | ||
| 288 | HWCryptoHook_InitFlags_SimpleForkCheck, /* Flags */ | ||
| 289 | &logstream, /* logstream */ | ||
| 290 | sizeof(BN_ULONG), /* limbsize */ | ||
| 291 | 0, /* mslimb first: false for BNs */ | ||
| 292 | -1, /* msbyte first: use native */ | ||
| 293 | 0, /* Max mutexes, 0 = no small limit */ | ||
| 294 | 0, /* Max simultaneous, 0 = default */ | ||
| 295 | |||
| 296 | /* The next few are mutex stuff: we write wrapper functions | ||
| 297 | around the OS mutex functions. We initialise them to 0 | ||
| 298 | here, and change that to actual function pointers in hwcrhk_init() | ||
| 299 | if dynamic locks are supported (that is, if the application | ||
| 300 | programmer has made sure of setting up callbacks bafore starting | ||
| 301 | this engine) *and* if disable_mutex_callbacks hasn't been set by | ||
| 302 | a call to ENGINE_ctrl(ENGINE_CTRL_CHIL_NO_LOCKING). */ | ||
| 303 | sizeof(HWCryptoHook_Mutex), | ||
| 304 | 0, | ||
| 305 | 0, | ||
| 306 | 0, | ||
| 307 | 0, | ||
| 308 | |||
| 309 | /* The next few are condvar stuff: we write wrapper functions | ||
| 310 | round the OS functions. Currently not implemented and not | ||
| 311 | and absolute necessity even in threaded programs, therefore | ||
| 312 | 0'ed. Will hopefully be implemented some day, since it | ||
| 313 | enhances the efficiency of HWCryptoHook. */ | ||
| 314 | 0, /* sizeof(HWCryptoHook_CondVar), */ | ||
| 315 | 0, /* hwcrhk_cv_init, */ | ||
| 316 | 0, /* hwcrhk_cv_wait, */ | ||
| 317 | 0, /* hwcrhk_cv_signal, */ | ||
| 318 | 0, /* hwcrhk_cv_broadcast, */ | ||
| 319 | 0, /* hwcrhk_cv_destroy, */ | ||
| 320 | |||
| 321 | hwcrhk_get_pass, /* pass phrase */ | ||
| 322 | hwcrhk_insert_card, /* insert a card */ | ||
| 323 | hwcrhk_log_message /* Log message */ | ||
| 324 | }; | ||
| 325 | |||
| 326 | |||
| 327 | /* Now, to our own code */ | ||
| 328 | |||
| 329 | /* This internal function is used by ENGINE_ncipher() and possibly by the | ||
| 330 | * "dynamic" ENGINE support too */ | ||
| 331 | static int bind_helper(ENGINE *e) | ||
| 332 | { | ||
| 333 | #ifndef OPENSSL_NO_RSA | ||
| 334 | const RSA_METHOD *meth1; | ||
| 335 | #endif | ||
| 336 | #ifndef OPENSSL_NO_DH | ||
| 337 | const DH_METHOD *meth2; | ||
| 338 | #endif | ||
| 339 | if(!ENGINE_set_id(e, engine_hwcrhk_id) || | ||
| 340 | !ENGINE_set_name(e, engine_hwcrhk_name) || | ||
| 341 | #ifndef OPENSSL_NO_RSA | ||
| 342 | !ENGINE_set_RSA(e, &hwcrhk_rsa) || | ||
| 343 | #endif | ||
| 344 | #ifndef OPENSSL_NO_DH | ||
| 345 | !ENGINE_set_DH(e, &hwcrhk_dh) || | ||
| 346 | #endif | ||
| 347 | !ENGINE_set_RAND(e, &hwcrhk_rand) || | ||
| 348 | !ENGINE_set_destroy_function(e, hwcrhk_destroy) || | ||
| 349 | !ENGINE_set_init_function(e, hwcrhk_init) || | ||
| 350 | !ENGINE_set_finish_function(e, hwcrhk_finish) || | ||
| 351 | !ENGINE_set_ctrl_function(e, hwcrhk_ctrl) || | ||
| 352 | !ENGINE_set_load_privkey_function(e, hwcrhk_load_privkey) || | ||
| 353 | !ENGINE_set_load_pubkey_function(e, hwcrhk_load_pubkey) || | ||
| 354 | !ENGINE_set_cmd_defns(e, hwcrhk_cmd_defns)) | ||
| 355 | return 0; | ||
| 356 | |||
| 357 | #ifndef OPENSSL_NO_RSA | ||
| 358 | /* We know that the "PKCS1_SSLeay()" functions hook properly | ||
| 359 | * to the cswift-specific mod_exp and mod_exp_crt so we use | ||
| 360 | * those functions. NB: We don't use ENGINE_openssl() or | ||
| 361 | * anything "more generic" because something like the RSAref | ||
| 362 | * code may not hook properly, and if you own one of these | ||
| 363 | * cards then you have the right to do RSA operations on it | ||
| 364 | * anyway! */ | ||
| 365 | meth1 = RSA_PKCS1_SSLeay(); | ||
| 366 | hwcrhk_rsa.rsa_pub_enc = meth1->rsa_pub_enc; | ||
| 367 | hwcrhk_rsa.rsa_pub_dec = meth1->rsa_pub_dec; | ||
| 368 | hwcrhk_rsa.rsa_priv_enc = meth1->rsa_priv_enc; | ||
| 369 | hwcrhk_rsa.rsa_priv_dec = meth1->rsa_priv_dec; | ||
| 370 | #endif | ||
| 371 | |||
| 372 | #ifndef OPENSSL_NO_DH | ||
| 373 | /* Much the same for Diffie-Hellman */ | ||
| 374 | meth2 = DH_OpenSSL(); | ||
| 375 | hwcrhk_dh.generate_key = meth2->generate_key; | ||
| 376 | hwcrhk_dh.compute_key = meth2->compute_key; | ||
| 377 | #endif | ||
| 378 | |||
| 379 | /* Ensure the hwcrhk error handling is set up */ | ||
| 380 | ERR_load_HWCRHK_strings(); | ||
| 381 | return 1; | ||
| 382 | } | ||
| 383 | |||
| 384 | #ifndef ENGINE_DYNAMIC_SUPPORT | ||
| 385 | static ENGINE *engine_ncipher(void) | ||
| 386 | { | ||
| 387 | ENGINE *ret = ENGINE_new(); | ||
| 388 | if(!ret) | ||
| 389 | return NULL; | ||
| 390 | if(!bind_helper(ret)) | ||
| 391 | { | ||
| 392 | ENGINE_free(ret); | ||
| 393 | return NULL; | ||
| 394 | } | ||
| 395 | return ret; | ||
| 396 | } | ||
| 397 | |||
| 398 | void ENGINE_load_chil(void) | ||
| 399 | { | ||
| 400 | /* Copied from eng_[openssl|dyn].c */ | ||
| 401 | ENGINE *toadd = engine_ncipher(); | ||
| 402 | if(!toadd) return; | ||
| 403 | ENGINE_add(toadd); | ||
| 404 | ENGINE_free(toadd); | ||
| 405 | ERR_clear_error(); | ||
| 406 | } | ||
| 407 | #endif | ||
| 408 | |||
| 409 | /* This is a process-global DSO handle used for loading and unloading | ||
| 410 | * the HWCryptoHook library. NB: This is only set (or unset) during an | ||
| 411 | * init() or finish() call (reference counts permitting) and they're | ||
| 412 | * operating with global locks, so this should be thread-safe | ||
| 413 | * implicitly. */ | ||
| 414 | static DSO *hwcrhk_dso = NULL; | ||
| 415 | static HWCryptoHook_ContextHandle hwcrhk_context = 0; | ||
| 416 | #ifndef OPENSSL_NO_RSA | ||
| 417 | static int hndidx_rsa = -1; /* Index for KM handle. Not really used yet. */ | ||
| 418 | #endif | ||
| 419 | |||
| 420 | /* These are the function pointers that are (un)set when the library has | ||
| 421 | * successfully (un)loaded. */ | ||
| 422 | static HWCryptoHook_Init_t *p_hwcrhk_Init = NULL; | ||
| 423 | static HWCryptoHook_Finish_t *p_hwcrhk_Finish = NULL; | ||
| 424 | static HWCryptoHook_ModExp_t *p_hwcrhk_ModExp = NULL; | ||
| 425 | #ifndef OPENSSL_NO_RSA | ||
| 426 | static HWCryptoHook_RSA_t *p_hwcrhk_RSA = NULL; | ||
| 427 | #endif | ||
| 428 | static HWCryptoHook_RandomBytes_t *p_hwcrhk_RandomBytes = NULL; | ||
| 429 | #ifndef OPENSSL_NO_RSA | ||
| 430 | static HWCryptoHook_RSALoadKey_t *p_hwcrhk_RSALoadKey = NULL; | ||
| 431 | static HWCryptoHook_RSAGetPublicKey_t *p_hwcrhk_RSAGetPublicKey = NULL; | ||
| 432 | static HWCryptoHook_RSAUnloadKey_t *p_hwcrhk_RSAUnloadKey = NULL; | ||
| 433 | #endif | ||
| 434 | static HWCryptoHook_ModExpCRT_t *p_hwcrhk_ModExpCRT = NULL; | ||
| 435 | |||
| 436 | /* Used in the DSO operations. */ | ||
| 437 | static const char *HWCRHK_LIBNAME = NULL; | ||
| 438 | static void free_HWCRHK_LIBNAME(void) | ||
| 439 | { | ||
| 440 | if(HWCRHK_LIBNAME) | ||
| 441 | OPENSSL_free((void*)HWCRHK_LIBNAME); | ||
| 442 | HWCRHK_LIBNAME = NULL; | ||
| 443 | } | ||
| 444 | static const char *get_HWCRHK_LIBNAME(void) | ||
| 445 | { | ||
| 446 | if(HWCRHK_LIBNAME) | ||
| 447 | return HWCRHK_LIBNAME; | ||
| 448 | return "nfhwcrhk"; | ||
| 449 | } | ||
| 450 | static long set_HWCRHK_LIBNAME(const char *name) | ||
| 451 | { | ||
| 452 | free_HWCRHK_LIBNAME(); | ||
| 453 | return (((HWCRHK_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0); | ||
| 454 | } | ||
| 455 | static const char *n_hwcrhk_Init = "HWCryptoHook_Init"; | ||
| 456 | static const char *n_hwcrhk_Finish = "HWCryptoHook_Finish"; | ||
| 457 | static const char *n_hwcrhk_ModExp = "HWCryptoHook_ModExp"; | ||
| 458 | #ifndef OPENSSL_NO_RSA | ||
| 459 | static const char *n_hwcrhk_RSA = "HWCryptoHook_RSA"; | ||
| 460 | #endif | ||
| 461 | static const char *n_hwcrhk_RandomBytes = "HWCryptoHook_RandomBytes"; | ||
| 462 | #ifndef OPENSSL_NO_RSA | ||
| 463 | static const char *n_hwcrhk_RSALoadKey = "HWCryptoHook_RSALoadKey"; | ||
| 464 | static const char *n_hwcrhk_RSAGetPublicKey = "HWCryptoHook_RSAGetPublicKey"; | ||
| 465 | static const char *n_hwcrhk_RSAUnloadKey = "HWCryptoHook_RSAUnloadKey"; | ||
| 466 | #endif | ||
| 467 | static const char *n_hwcrhk_ModExpCRT = "HWCryptoHook_ModExpCRT"; | ||
| 468 | |||
| 469 | /* HWCryptoHook library functions and mechanics - these are used by the | ||
| 470 | * higher-level functions further down. NB: As and where there's no | ||
| 471 | * error checking, take a look lower down where these functions are | ||
| 472 | * called, the checking and error handling is probably down there. */ | ||
| 473 | |||
| 474 | /* utility function to obtain a context */ | ||
| 475 | static int get_context(HWCryptoHook_ContextHandle *hac, | ||
| 476 | HWCryptoHook_CallerContext *cac) | ||
| 477 | { | ||
| 478 | char tempbuf[1024]; | ||
| 479 | HWCryptoHook_ErrMsgBuf rmsg; | ||
| 480 | |||
| 481 | rmsg.buf = tempbuf; | ||
| 482 | rmsg.size = sizeof(tempbuf); | ||
| 483 | |||
| 484 | *hac = p_hwcrhk_Init(&hwcrhk_globals, sizeof(hwcrhk_globals), &rmsg, | ||
| 485 | cac); | ||
| 486 | if (!*hac) | ||
| 487 | return 0; | ||
| 488 | return 1; | ||
| 489 | } | ||
| 490 | |||
| 491 | /* similarly to release one. */ | ||
| 492 | static void release_context(HWCryptoHook_ContextHandle hac) | ||
| 493 | { | ||
| 494 | p_hwcrhk_Finish(hac); | ||
| 495 | } | ||
| 496 | |||
| 497 | /* Destructor (complements the "ENGINE_ncipher()" constructor) */ | ||
| 498 | static int hwcrhk_destroy(ENGINE *e) | ||
| 499 | { | ||
| 500 | free_HWCRHK_LIBNAME(); | ||
| 501 | ERR_unload_HWCRHK_strings(); | ||
| 502 | return 1; | ||
| 503 | } | ||
| 504 | |||
| 505 | /* (de)initialisation functions. */ | ||
| 506 | static int hwcrhk_init(ENGINE *e) | ||
| 507 | { | ||
| 508 | HWCryptoHook_Init_t *p1; | ||
| 509 | HWCryptoHook_Finish_t *p2; | ||
| 510 | HWCryptoHook_ModExp_t *p3; | ||
| 511 | #ifndef OPENSSL_NO_RSA | ||
| 512 | HWCryptoHook_RSA_t *p4; | ||
| 513 | HWCryptoHook_RSALoadKey_t *p5; | ||
| 514 | HWCryptoHook_RSAGetPublicKey_t *p6; | ||
| 515 | HWCryptoHook_RSAUnloadKey_t *p7; | ||
| 516 | #endif | ||
| 517 | HWCryptoHook_RandomBytes_t *p8; | ||
| 518 | HWCryptoHook_ModExpCRT_t *p9; | ||
| 519 | |||
| 520 | if(hwcrhk_dso != NULL) | ||
| 521 | { | ||
| 522 | HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_ALREADY_LOADED); | ||
| 523 | goto err; | ||
| 524 | } | ||
| 525 | /* Attempt to load libnfhwcrhk.so/nfhwcrhk.dll/whatever. */ | ||
| 526 | hwcrhk_dso = DSO_load(NULL, get_HWCRHK_LIBNAME(), NULL, 0); | ||
| 527 | if(hwcrhk_dso == NULL) | ||
| 528 | { | ||
| 529 | HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DSO_FAILURE); | ||
| 530 | goto err; | ||
| 531 | } | ||
| 532 | if(!(p1 = (HWCryptoHook_Init_t *) | ||
| 533 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_Init)) || | ||
| 534 | !(p2 = (HWCryptoHook_Finish_t *) | ||
| 535 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_Finish)) || | ||
| 536 | !(p3 = (HWCryptoHook_ModExp_t *) | ||
| 537 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExp)) || | ||
| 538 | #ifndef OPENSSL_NO_RSA | ||
| 539 | !(p4 = (HWCryptoHook_RSA_t *) | ||
| 540 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSA)) || | ||
| 541 | !(p5 = (HWCryptoHook_RSALoadKey_t *) | ||
| 542 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSALoadKey)) || | ||
| 543 | !(p6 = (HWCryptoHook_RSAGetPublicKey_t *) | ||
| 544 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAGetPublicKey)) || | ||
| 545 | !(p7 = (HWCryptoHook_RSAUnloadKey_t *) | ||
| 546 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAUnloadKey)) || | ||
| 547 | #endif | ||
| 548 | !(p8 = (HWCryptoHook_RandomBytes_t *) | ||
| 549 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_RandomBytes)) || | ||
| 550 | !(p9 = (HWCryptoHook_ModExpCRT_t *) | ||
| 551 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExpCRT))) | ||
| 552 | { | ||
| 553 | HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DSO_FAILURE); | ||
| 554 | goto err; | ||
| 555 | } | ||
| 556 | /* Copy the pointers */ | ||
| 557 | p_hwcrhk_Init = p1; | ||
| 558 | p_hwcrhk_Finish = p2; | ||
| 559 | p_hwcrhk_ModExp = p3; | ||
| 560 | #ifndef OPENSSL_NO_RSA | ||
| 561 | p_hwcrhk_RSA = p4; | ||
| 562 | p_hwcrhk_RSALoadKey = p5; | ||
| 563 | p_hwcrhk_RSAGetPublicKey = p6; | ||
| 564 | p_hwcrhk_RSAUnloadKey = p7; | ||
| 565 | #endif | ||
| 566 | p_hwcrhk_RandomBytes = p8; | ||
| 567 | p_hwcrhk_ModExpCRT = p9; | ||
| 568 | |||
| 569 | /* Check if the application decided to support dynamic locks, | ||
| 570 | and if it does, use them. */ | ||
| 571 | if (disable_mutex_callbacks == 0) | ||
| 572 | { | ||
| 573 | if (CRYPTO_get_dynlock_create_callback() != NULL && | ||
| 574 | CRYPTO_get_dynlock_lock_callback() != NULL && | ||
| 575 | CRYPTO_get_dynlock_destroy_callback() != NULL) | ||
| 576 | { | ||
| 577 | hwcrhk_globals.mutex_init = hwcrhk_mutex_init; | ||
| 578 | hwcrhk_globals.mutex_acquire = hwcrhk_mutex_lock; | ||
| 579 | hwcrhk_globals.mutex_release = hwcrhk_mutex_unlock; | ||
| 580 | hwcrhk_globals.mutex_destroy = hwcrhk_mutex_destroy; | ||
| 581 | } | ||
| 582 | else if (CRYPTO_get_locking_callback() != NULL) | ||
| 583 | { | ||
| 584 | HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DYNAMIC_LOCKING_MISSING); | ||
| 585 | ERR_add_error_data(1,"You HAVE to add dynamic locking callbacks via CRYPTO_set_dynlock_{create,lock,destroy}_callback()"); | ||
| 586 | #if 1 /* This is a HACK which will disappear in 0.9.8 */ | ||
| 587 | hwcrhk_globals.maxmutexes = 1; /* Only have one lock */ | ||
| 588 | hwcrhk_globals.mutex_init = hwcrhk_static_mutex_init; | ||
| 589 | hwcrhk_globals.mutex_acquire = hwcrhk_static_mutex_lock; | ||
| 590 | hwcrhk_globals.mutex_release = hwcrhk_static_mutex_unlock; | ||
| 591 | hwcrhk_globals.mutex_destroy = hwcrhk_static_mutex_destroy; | ||
| 592 | #else | ||
| 593 | goto err; | ||
| 594 | #endif | ||
| 595 | } | ||
| 596 | } | ||
| 597 | |||
| 598 | /* Try and get a context - if not, we may have a DSO but no | ||
| 599 | * accelerator! */ | ||
| 600 | if(!get_context(&hwcrhk_context, &password_context)) | ||
| 601 | { | ||
| 602 | HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_UNIT_FAILURE); | ||
| 603 | goto err; | ||
| 604 | } | ||
| 605 | /* Everything's fine. */ | ||
| 606 | #ifndef OPENSSL_NO_RSA | ||
| 607 | if (hndidx_rsa == -1) | ||
| 608 | hndidx_rsa = RSA_get_ex_new_index(0, | ||
| 609 | "nFast HWCryptoHook RSA key handle", | ||
| 610 | NULL, NULL, hwcrhk_ex_free); | ||
| 611 | #endif | ||
| 612 | return 1; | ||
| 613 | err: | ||
| 614 | if(hwcrhk_dso) | ||
| 615 | DSO_free(hwcrhk_dso); | ||
| 616 | hwcrhk_dso = NULL; | ||
| 617 | p_hwcrhk_Init = NULL; | ||
| 618 | p_hwcrhk_Finish = NULL; | ||
| 619 | p_hwcrhk_ModExp = NULL; | ||
| 620 | #ifndef OPENSSL_NO_RSA | ||
| 621 | p_hwcrhk_RSA = NULL; | ||
| 622 | p_hwcrhk_RSALoadKey = NULL; | ||
| 623 | p_hwcrhk_RSAGetPublicKey = NULL; | ||
| 624 | p_hwcrhk_RSAUnloadKey = NULL; | ||
| 625 | #endif | ||
| 626 | p_hwcrhk_ModExpCRT = NULL; | ||
| 627 | p_hwcrhk_RandomBytes = NULL; | ||
| 628 | return 0; | ||
| 629 | } | ||
| 630 | |||
| 631 | static int hwcrhk_finish(ENGINE *e) | ||
| 632 | { | ||
| 633 | int to_return = 1; | ||
| 634 | free_HWCRHK_LIBNAME(); | ||
| 635 | if(hwcrhk_dso == NULL) | ||
| 636 | { | ||
| 637 | HWCRHKerr(HWCRHK_F_HWCRHK_FINISH,HWCRHK_R_NOT_LOADED); | ||
| 638 | to_return = 0; | ||
| 639 | goto err; | ||
| 640 | } | ||
| 641 | release_context(hwcrhk_context); | ||
| 642 | if(!DSO_free(hwcrhk_dso)) | ||
| 643 | { | ||
| 644 | HWCRHKerr(HWCRHK_F_HWCRHK_FINISH,HWCRHK_R_DSO_FAILURE); | ||
| 645 | to_return = 0; | ||
| 646 | goto err; | ||
| 647 | } | ||
| 648 | err: | ||
| 649 | if (logstream) | ||
| 650 | BIO_free(logstream); | ||
| 651 | hwcrhk_dso = NULL; | ||
| 652 | p_hwcrhk_Init = NULL; | ||
| 653 | p_hwcrhk_Finish = NULL; | ||
| 654 | p_hwcrhk_ModExp = NULL; | ||
| 655 | #ifndef OPENSSL_NO_RSA | ||
| 656 | p_hwcrhk_RSA = NULL; | ||
| 657 | p_hwcrhk_RSALoadKey = NULL; | ||
| 658 | p_hwcrhk_RSAGetPublicKey = NULL; | ||
| 659 | p_hwcrhk_RSAUnloadKey = NULL; | ||
| 660 | #endif | ||
| 661 | p_hwcrhk_ModExpCRT = NULL; | ||
| 662 | p_hwcrhk_RandomBytes = NULL; | ||
| 663 | return to_return; | ||
| 664 | } | ||
| 665 | |||
| 666 | static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
| 667 | { | ||
| 668 | int to_return = 1; | ||
| 669 | |||
| 670 | switch(cmd) | ||
| 671 | { | ||
| 672 | case HWCRHK_CMD_SO_PATH: | ||
| 673 | if(hwcrhk_dso) | ||
| 674 | { | ||
| 675 | HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,HWCRHK_R_ALREADY_LOADED); | ||
| 676 | return 0; | ||
| 677 | } | ||
| 678 | if(p == NULL) | ||
| 679 | { | ||
| 680 | HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
| 681 | return 0; | ||
| 682 | } | ||
| 683 | return set_HWCRHK_LIBNAME((const char *)p); | ||
| 684 | case ENGINE_CTRL_SET_LOGSTREAM: | ||
| 685 | { | ||
| 686 | BIO *bio = (BIO *)p; | ||
| 687 | |||
| 688 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 689 | if (logstream) | ||
| 690 | { | ||
| 691 | BIO_free(logstream); | ||
| 692 | logstream = NULL; | ||
| 693 | } | ||
| 694 | if (CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO) > 1) | ||
| 695 | logstream = bio; | ||
| 696 | else | ||
| 697 | HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,HWCRHK_R_BIO_WAS_FREED); | ||
| 698 | } | ||
| 699 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 700 | break; | ||
| 701 | case ENGINE_CTRL_SET_PASSWORD_CALLBACK: | ||
| 702 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 703 | password_context.password_callback = (pem_password_cb *)f; | ||
| 704 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 705 | break; | ||
| 706 | case ENGINE_CTRL_SET_USER_INTERFACE: | ||
| 707 | case HWCRHK_CMD_SET_USER_INTERFACE: | ||
| 708 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 709 | password_context.ui_method = (UI_METHOD *)p; | ||
| 710 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 711 | break; | ||
| 712 | case ENGINE_CTRL_SET_CALLBACK_DATA: | ||
| 713 | case HWCRHK_CMD_SET_CALLBACK_DATA: | ||
| 714 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 715 | password_context.callback_data = p; | ||
| 716 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 717 | break; | ||
| 718 | /* this enables or disables the "SimpleForkCheck" flag used in the | ||
| 719 | * initialisation structure. */ | ||
| 720 | case ENGINE_CTRL_CHIL_SET_FORKCHECK: | ||
| 721 | case HWCRHK_CMD_FORK_CHECK: | ||
| 722 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 723 | if(i) | ||
| 724 | hwcrhk_globals.flags |= | ||
| 725 | HWCryptoHook_InitFlags_SimpleForkCheck; | ||
| 726 | else | ||
| 727 | hwcrhk_globals.flags &= | ||
| 728 | ~HWCryptoHook_InitFlags_SimpleForkCheck; | ||
| 729 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 730 | break; | ||
| 731 | /* This will prevent the initialisation function from "installing" | ||
| 732 | * the mutex-handling callbacks, even if they are available from | ||
| 733 | * within the library (or were provided to the library from the | ||
| 734 | * calling application). This is to remove any baggage for | ||
| 735 | * applications not using multithreading. */ | ||
| 736 | case ENGINE_CTRL_CHIL_NO_LOCKING: | ||
| 737 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 738 | disable_mutex_callbacks = 1; | ||
| 739 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 740 | break; | ||
| 741 | case HWCRHK_CMD_THREAD_LOCKING: | ||
| 742 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 743 | disable_mutex_callbacks = ((i == 0) ? 0 : 1); | ||
| 744 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 745 | break; | ||
| 746 | |||
| 747 | /* The command isn't understood by this engine */ | ||
| 748 | default: | ||
| 749 | HWCRHKerr(HWCRHK_F_HWCRHK_CTRL, | ||
| 750 | HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
| 751 | to_return = 0; | ||
| 752 | break; | ||
| 753 | } | ||
| 754 | |||
| 755 | return to_return; | ||
| 756 | } | ||
| 757 | |||
| 758 | static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id, | ||
| 759 | UI_METHOD *ui_method, void *callback_data) | ||
| 760 | { | ||
| 761 | #ifndef OPENSSL_NO_RSA | ||
| 762 | RSA *rtmp = NULL; | ||
| 763 | #endif | ||
| 764 | EVP_PKEY *res = NULL; | ||
| 765 | #ifndef OPENSSL_NO_RSA | ||
| 766 | HWCryptoHook_MPI e, n; | ||
| 767 | HWCryptoHook_RSAKeyHandle *hptr; | ||
| 768 | #endif | ||
| 769 | #if !defined(OPENSSL_NO_RSA) | ||
| 770 | char tempbuf[1024]; | ||
| 771 | HWCryptoHook_ErrMsgBuf rmsg; | ||
| 772 | #endif | ||
| 773 | HWCryptoHook_PassphraseContext ppctx; | ||
| 774 | |||
| 775 | #if !defined(OPENSSL_NO_RSA) | ||
| 776 | rmsg.buf = tempbuf; | ||
| 777 | rmsg.size = sizeof(tempbuf); | ||
| 778 | #endif | ||
| 779 | |||
| 780 | if(!hwcrhk_context) | ||
| 781 | { | ||
| 782 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY, | ||
| 783 | HWCRHK_R_NOT_INITIALISED); | ||
| 784 | goto err; | ||
| 785 | } | ||
| 786 | #ifndef OPENSSL_NO_RSA | ||
| 787 | hptr = OPENSSL_malloc(sizeof(HWCryptoHook_RSAKeyHandle)); | ||
| 788 | if (!hptr) | ||
| 789 | { | ||
| 790 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY, | ||
| 791 | ERR_R_MALLOC_FAILURE); | ||
| 792 | goto err; | ||
| 793 | } | ||
| 794 | ppctx.ui_method = ui_method; | ||
| 795 | ppctx.callback_data = callback_data; | ||
| 796 | if (p_hwcrhk_RSALoadKey(hwcrhk_context, key_id, hptr, | ||
| 797 | &rmsg, &ppctx)) | ||
| 798 | { | ||
| 799 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY, | ||
| 800 | HWCRHK_R_CHIL_ERROR); | ||
| 801 | ERR_add_error_data(1,rmsg.buf); | ||
| 802 | goto err; | ||
| 803 | } | ||
| 804 | if (!*hptr) | ||
| 805 | { | ||
| 806 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY, | ||
| 807 | HWCRHK_R_NO_KEY); | ||
| 808 | goto err; | ||
| 809 | } | ||
| 810 | #endif | ||
| 811 | #ifndef OPENSSL_NO_RSA | ||
| 812 | rtmp = RSA_new_method(eng); | ||
| 813 | RSA_set_ex_data(rtmp, hndidx_rsa, (char *)hptr); | ||
| 814 | rtmp->e = BN_new(); | ||
| 815 | rtmp->n = BN_new(); | ||
| 816 | rtmp->flags |= RSA_FLAG_EXT_PKEY; | ||
| 817 | MPI2BN(rtmp->e, e); | ||
| 818 | MPI2BN(rtmp->n, n); | ||
| 819 | if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg) | ||
| 820 | != HWCRYPTOHOOK_ERROR_MPISIZE) | ||
| 821 | { | ||
| 822 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,HWCRHK_R_CHIL_ERROR); | ||
| 823 | ERR_add_error_data(1,rmsg.buf); | ||
| 824 | goto err; | ||
| 825 | } | ||
| 826 | |||
| 827 | bn_expand2(rtmp->e, e.size/sizeof(BN_ULONG)); | ||
| 828 | bn_expand2(rtmp->n, n.size/sizeof(BN_ULONG)); | ||
| 829 | MPI2BN(rtmp->e, e); | ||
| 830 | MPI2BN(rtmp->n, n); | ||
| 831 | |||
| 832 | if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg)) | ||
| 833 | { | ||
| 834 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY, | ||
| 835 | HWCRHK_R_CHIL_ERROR); | ||
| 836 | ERR_add_error_data(1,rmsg.buf); | ||
| 837 | goto err; | ||
| 838 | } | ||
| 839 | rtmp->e->top = e.size / sizeof(BN_ULONG); | ||
| 840 | bn_fix_top(rtmp->e); | ||
| 841 | rtmp->n->top = n.size / sizeof(BN_ULONG); | ||
| 842 | bn_fix_top(rtmp->n); | ||
| 843 | |||
| 844 | res = EVP_PKEY_new(); | ||
| 845 | EVP_PKEY_assign_RSA(res, rtmp); | ||
| 846 | #endif | ||
| 847 | |||
| 848 | if (!res) | ||
| 849 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY, | ||
| 850 | HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED); | ||
| 851 | |||
| 852 | return res; | ||
| 853 | err: | ||
| 854 | if (res) | ||
| 855 | EVP_PKEY_free(res); | ||
| 856 | #ifndef OPENSSL_NO_RSA | ||
| 857 | if (rtmp) | ||
| 858 | RSA_free(rtmp); | ||
| 859 | #endif | ||
| 860 | return NULL; | ||
| 861 | } | ||
| 862 | |||
| 863 | static EVP_PKEY *hwcrhk_load_pubkey(ENGINE *eng, const char *key_id, | ||
| 864 | UI_METHOD *ui_method, void *callback_data) | ||
| 865 | { | ||
| 866 | EVP_PKEY *res = NULL; | ||
| 867 | |||
| 868 | #ifndef OPENSSL_NO_RSA | ||
| 869 | res = hwcrhk_load_privkey(eng, key_id, | ||
| 870 | ui_method, callback_data); | ||
| 871 | #endif | ||
| 872 | |||
| 873 | if (res) | ||
| 874 | switch(res->type) | ||
| 875 | { | ||
| 876 | #ifndef OPENSSL_NO_RSA | ||
| 877 | case EVP_PKEY_RSA: | ||
| 878 | { | ||
| 879 | RSA *rsa = NULL; | ||
| 880 | |||
| 881 | CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY); | ||
| 882 | rsa = res->pkey.rsa; | ||
| 883 | res->pkey.rsa = RSA_new(); | ||
| 884 | res->pkey.rsa->n = rsa->n; | ||
| 885 | res->pkey.rsa->e = rsa->e; | ||
| 886 | rsa->n = NULL; | ||
| 887 | rsa->e = NULL; | ||
| 888 | CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); | ||
| 889 | RSA_free(rsa); | ||
| 890 | } | ||
| 891 | break; | ||
| 892 | #endif | ||
| 893 | default: | ||
| 894 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY, | ||
| 895 | HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
| 896 | goto err; | ||
| 897 | } | ||
| 898 | |||
| 899 | return res; | ||
| 900 | err: | ||
| 901 | if (res) | ||
| 902 | EVP_PKEY_free(res); | ||
| 903 | return NULL; | ||
| 904 | } | ||
| 905 | |||
| 906 | /* A little mod_exp */ | ||
| 907 | static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 908 | const BIGNUM *m, BN_CTX *ctx) | ||
| 909 | { | ||
| 910 | char tempbuf[1024]; | ||
| 911 | HWCryptoHook_ErrMsgBuf rmsg; | ||
| 912 | /* Since HWCryptoHook_MPI is pretty compatible with BIGNUM's, | ||
| 913 | we use them directly, plus a little macro magic. We only | ||
| 914 | thing we need to make sure of is that enough space is allocated. */ | ||
| 915 | HWCryptoHook_MPI m_a, m_p, m_n, m_r; | ||
| 916 | int to_return, ret; | ||
| 917 | |||
| 918 | to_return = 0; /* expect failure */ | ||
| 919 | rmsg.buf = tempbuf; | ||
| 920 | rmsg.size = sizeof(tempbuf); | ||
| 921 | |||
| 922 | if(!hwcrhk_context) | ||
| 923 | { | ||
| 924 | HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_NOT_INITIALISED); | ||
| 925 | goto err; | ||
| 926 | } | ||
| 927 | /* Prepare the params */ | ||
| 928 | bn_expand2(r, m->top); /* Check for error !! */ | ||
| 929 | BN2MPI(m_a, a); | ||
| 930 | BN2MPI(m_p, p); | ||
| 931 | BN2MPI(m_n, m); | ||
| 932 | MPI2BN(r, m_r); | ||
| 933 | |||
| 934 | /* Perform the operation */ | ||
| 935 | ret = p_hwcrhk_ModExp(hwcrhk_context, m_a, m_p, m_n, &m_r, &rmsg); | ||
| 936 | |||
| 937 | /* Convert the response */ | ||
| 938 | r->top = m_r.size / sizeof(BN_ULONG); | ||
| 939 | bn_fix_top(r); | ||
| 940 | |||
| 941 | if (ret < 0) | ||
| 942 | { | ||
| 943 | /* FIXME: When this error is returned, HWCryptoHook is | ||
| 944 | telling us that falling back to software computation | ||
| 945 | might be a good thing. */ | ||
| 946 | if(ret == HWCRYPTOHOOK_ERROR_FALLBACK) | ||
| 947 | { | ||
| 948 | HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_REQUEST_FALLBACK); | ||
| 949 | } | ||
| 950 | else | ||
| 951 | { | ||
| 952 | HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_REQUEST_FAILED); | ||
| 953 | } | ||
| 954 | ERR_add_error_data(1,rmsg.buf); | ||
| 955 | goto err; | ||
| 956 | } | ||
| 957 | |||
| 958 | to_return = 1; | ||
| 959 | err: | ||
| 960 | return to_return; | ||
| 961 | } | ||
| 962 | |||
| 963 | #ifndef OPENSSL_NO_RSA | ||
| 964 | static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa) | ||
| 965 | { | ||
| 966 | char tempbuf[1024]; | ||
| 967 | HWCryptoHook_ErrMsgBuf rmsg; | ||
| 968 | HWCryptoHook_RSAKeyHandle *hptr; | ||
| 969 | int to_return = 0, ret; | ||
| 970 | |||
| 971 | rmsg.buf = tempbuf; | ||
| 972 | rmsg.size = sizeof(tempbuf); | ||
| 973 | |||
| 974 | if(!hwcrhk_context) | ||
| 975 | { | ||
| 976 | HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_NOT_INITIALISED); | ||
| 977 | goto err; | ||
| 978 | } | ||
| 979 | |||
| 980 | /* This provides support for nForce keys. Since that's opaque data | ||
| 981 | all we do is provide a handle to the proper key and let HWCryptoHook | ||
| 982 | take care of the rest. */ | ||
| 983 | if ((hptr = (HWCryptoHook_RSAKeyHandle *) RSA_get_ex_data(rsa, hndidx_rsa)) | ||
| 984 | != NULL) | ||
| 985 | { | ||
| 986 | HWCryptoHook_MPI m_a, m_r; | ||
| 987 | |||
| 988 | if(!rsa->n) | ||
| 989 | { | ||
| 990 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
| 991 | HWCRHK_R_MISSING_KEY_COMPONENTS); | ||
| 992 | goto err; | ||
| 993 | } | ||
| 994 | |||
| 995 | /* Prepare the params */ | ||
| 996 | bn_expand2(r, rsa->n->top); /* Check for error !! */ | ||
| 997 | BN2MPI(m_a, I); | ||
| 998 | MPI2BN(r, m_r); | ||
| 999 | |||
| 1000 | /* Perform the operation */ | ||
| 1001 | ret = p_hwcrhk_RSA(m_a, *hptr, &m_r, &rmsg); | ||
| 1002 | |||
| 1003 | /* Convert the response */ | ||
| 1004 | r->top = m_r.size / sizeof(BN_ULONG); | ||
| 1005 | bn_fix_top(r); | ||
| 1006 | |||
| 1007 | if (ret < 0) | ||
| 1008 | { | ||
| 1009 | /* FIXME: When this error is returned, HWCryptoHook is | ||
| 1010 | telling us that falling back to software computation | ||
| 1011 | might be a good thing. */ | ||
| 1012 | if(ret == HWCRYPTOHOOK_ERROR_FALLBACK) | ||
| 1013 | { | ||
| 1014 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
| 1015 | HWCRHK_R_REQUEST_FALLBACK); | ||
| 1016 | } | ||
| 1017 | else | ||
| 1018 | { | ||
| 1019 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
| 1020 | HWCRHK_R_REQUEST_FAILED); | ||
| 1021 | } | ||
| 1022 | ERR_add_error_data(1,rmsg.buf); | ||
| 1023 | goto err; | ||
| 1024 | } | ||
| 1025 | } | ||
| 1026 | else | ||
| 1027 | { | ||
| 1028 | HWCryptoHook_MPI m_a, m_p, m_q, m_dmp1, m_dmq1, m_iqmp, m_r; | ||
| 1029 | |||
| 1030 | if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) | ||
| 1031 | { | ||
| 1032 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
| 1033 | HWCRHK_R_MISSING_KEY_COMPONENTS); | ||
| 1034 | goto err; | ||
| 1035 | } | ||
| 1036 | |||
| 1037 | /* Prepare the params */ | ||
| 1038 | bn_expand2(r, rsa->n->top); /* Check for error !! */ | ||
| 1039 | BN2MPI(m_a, I); | ||
| 1040 | BN2MPI(m_p, rsa->p); | ||
| 1041 | BN2MPI(m_q, rsa->q); | ||
| 1042 | BN2MPI(m_dmp1, rsa->dmp1); | ||
| 1043 | BN2MPI(m_dmq1, rsa->dmq1); | ||
| 1044 | BN2MPI(m_iqmp, rsa->iqmp); | ||
| 1045 | MPI2BN(r, m_r); | ||
| 1046 | |||
| 1047 | /* Perform the operation */ | ||
| 1048 | ret = p_hwcrhk_ModExpCRT(hwcrhk_context, m_a, m_p, m_q, | ||
| 1049 | m_dmp1, m_dmq1, m_iqmp, &m_r, &rmsg); | ||
| 1050 | |||
| 1051 | /* Convert the response */ | ||
| 1052 | r->top = m_r.size / sizeof(BN_ULONG); | ||
| 1053 | bn_fix_top(r); | ||
| 1054 | |||
| 1055 | if (ret < 0) | ||
| 1056 | { | ||
| 1057 | /* FIXME: When this error is returned, HWCryptoHook is | ||
| 1058 | telling us that falling back to software computation | ||
| 1059 | might be a good thing. */ | ||
| 1060 | if(ret == HWCRYPTOHOOK_ERROR_FALLBACK) | ||
| 1061 | { | ||
| 1062 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
| 1063 | HWCRHK_R_REQUEST_FALLBACK); | ||
| 1064 | } | ||
| 1065 | else | ||
| 1066 | { | ||
| 1067 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
| 1068 | HWCRHK_R_REQUEST_FAILED); | ||
| 1069 | } | ||
| 1070 | ERR_add_error_data(1,rmsg.buf); | ||
| 1071 | goto err; | ||
| 1072 | } | ||
| 1073 | } | ||
| 1074 | /* If we're here, we must be here with some semblance of success :-) */ | ||
| 1075 | to_return = 1; | ||
| 1076 | err: | ||
| 1077 | return to_return; | ||
| 1078 | } | ||
| 1079 | #endif | ||
| 1080 | |||
| 1081 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
| 1082 | static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 1083 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
| 1084 | { | ||
| 1085 | return hwcrhk_mod_exp(r, a, p, m, ctx); | ||
| 1086 | } | ||
| 1087 | |||
| 1088 | #ifndef OPENSSL_NO_DH | ||
| 1089 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | ||
| 1090 | static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r, | ||
| 1091 | const BIGNUM *a, const BIGNUM *p, | ||
| 1092 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
| 1093 | { | ||
| 1094 | return hwcrhk_mod_exp(r, a, p, m, ctx); | ||
| 1095 | } | ||
| 1096 | #endif | ||
| 1097 | |||
| 1098 | /* Random bytes are good */ | ||
| 1099 | static int hwcrhk_rand_bytes(unsigned char *buf, int num) | ||
| 1100 | { | ||
| 1101 | char tempbuf[1024]; | ||
| 1102 | HWCryptoHook_ErrMsgBuf rmsg; | ||
| 1103 | int to_return = 0; /* assume failure */ | ||
| 1104 | int ret; | ||
| 1105 | |||
| 1106 | rmsg.buf = tempbuf; | ||
| 1107 | rmsg.size = sizeof(tempbuf); | ||
| 1108 | |||
| 1109 | if(!hwcrhk_context) | ||
| 1110 | { | ||
| 1111 | HWCRHKerr(HWCRHK_F_HWCRHK_RAND_BYTES,HWCRHK_R_NOT_INITIALISED); | ||
| 1112 | goto err; | ||
| 1113 | } | ||
| 1114 | |||
| 1115 | ret = p_hwcrhk_RandomBytes(hwcrhk_context, buf, num, &rmsg); | ||
| 1116 | if (ret < 0) | ||
| 1117 | { | ||
| 1118 | /* FIXME: When this error is returned, HWCryptoHook is | ||
| 1119 | telling us that falling back to software computation | ||
| 1120 | might be a good thing. */ | ||
| 1121 | if(ret == HWCRYPTOHOOK_ERROR_FALLBACK) | ||
| 1122 | { | ||
| 1123 | HWCRHKerr(HWCRHK_F_HWCRHK_RAND_BYTES, | ||
| 1124 | HWCRHK_R_REQUEST_FALLBACK); | ||
| 1125 | } | ||
| 1126 | else | ||
| 1127 | { | ||
| 1128 | HWCRHKerr(HWCRHK_F_HWCRHK_RAND_BYTES, | ||
| 1129 | HWCRHK_R_REQUEST_FAILED); | ||
| 1130 | } | ||
| 1131 | ERR_add_error_data(1,rmsg.buf); | ||
| 1132 | goto err; | ||
| 1133 | } | ||
| 1134 | to_return = 1; | ||
| 1135 | err: | ||
| 1136 | return to_return; | ||
| 1137 | } | ||
| 1138 | |||
| 1139 | static int hwcrhk_rand_status(void) | ||
| 1140 | { | ||
| 1141 | return 1; | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | /* This cleans up an RSA KM key, called when ex_data is freed */ | ||
| 1145 | |||
| 1146 | static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
| 1147 | int ind,long argl, void *argp) | ||
| 1148 | { | ||
| 1149 | char tempbuf[1024]; | ||
| 1150 | HWCryptoHook_ErrMsgBuf rmsg; | ||
| 1151 | #ifndef OPENSSL_NO_RSA | ||
| 1152 | HWCryptoHook_RSAKeyHandle *hptr; | ||
| 1153 | #endif | ||
| 1154 | #if !defined(OPENSSL_NO_RSA) | ||
| 1155 | int ret; | ||
| 1156 | #endif | ||
| 1157 | |||
| 1158 | rmsg.buf = tempbuf; | ||
| 1159 | rmsg.size = sizeof(tempbuf); | ||
| 1160 | |||
| 1161 | #ifndef OPENSSL_NO_RSA | ||
| 1162 | hptr = (HWCryptoHook_RSAKeyHandle *) item; | ||
| 1163 | if(hptr) | ||
| 1164 | { | ||
| 1165 | ret = p_hwcrhk_RSAUnloadKey(*hptr, NULL); | ||
| 1166 | OPENSSL_free(hptr); | ||
| 1167 | } | ||
| 1168 | #endif | ||
| 1169 | } | ||
| 1170 | |||
| 1171 | /* Mutex calls: since the HWCryptoHook model closely follows the POSIX model | ||
| 1172 | * these just wrap the POSIX functions and add some logging. | ||
| 1173 | */ | ||
| 1174 | |||
| 1175 | static int hwcrhk_mutex_init(HWCryptoHook_Mutex* mt, | ||
| 1176 | HWCryptoHook_CallerContext *cactx) | ||
| 1177 | { | ||
| 1178 | mt->lockid = CRYPTO_get_new_dynlockid(); | ||
| 1179 | if (mt->lockid == 0) | ||
| 1180 | return 1; /* failure */ | ||
| 1181 | return 0; /* success */ | ||
| 1182 | } | ||
| 1183 | |||
| 1184 | static int hwcrhk_mutex_lock(HWCryptoHook_Mutex *mt) | ||
| 1185 | { | ||
| 1186 | CRYPTO_w_lock(mt->lockid); | ||
| 1187 | return 0; | ||
| 1188 | } | ||
| 1189 | |||
| 1190 | static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex * mt) | ||
| 1191 | { | ||
| 1192 | CRYPTO_w_unlock(mt->lockid); | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex *mt) | ||
| 1196 | { | ||
| 1197 | CRYPTO_destroy_dynlockid(mt->lockid); | ||
| 1198 | } | ||
| 1199 | |||
| 1200 | /* Mutex upcalls to use if the application does not support dynamic locks */ | ||
| 1201 | |||
| 1202 | static int hwcrhk_static_mutex_init(HWCryptoHook_Mutex *m, | ||
| 1203 | HWCryptoHook_CallerContext *c) | ||
| 1204 | { | ||
| 1205 | return 0; | ||
| 1206 | } | ||
| 1207 | static int hwcrhk_static_mutex_lock(HWCryptoHook_Mutex *m) | ||
| 1208 | { | ||
| 1209 | CRYPTO_w_lock(CRYPTO_LOCK_HWCRHK); | ||
| 1210 | return 0; | ||
| 1211 | } | ||
| 1212 | static void hwcrhk_static_mutex_unlock(HWCryptoHook_Mutex *m) | ||
| 1213 | { | ||
| 1214 | CRYPTO_w_unlock(CRYPTO_LOCK_HWCRHK); | ||
| 1215 | } | ||
| 1216 | static void hwcrhk_static_mutex_destroy(HWCryptoHook_Mutex *m) | ||
| 1217 | { | ||
| 1218 | } | ||
| 1219 | |||
| 1220 | static int hwcrhk_get_pass(const char *prompt_info, | ||
| 1221 | int *len_io, char *buf, | ||
| 1222 | HWCryptoHook_PassphraseContext *ppctx, | ||
| 1223 | HWCryptoHook_CallerContext *cactx) | ||
| 1224 | { | ||
| 1225 | pem_password_cb *callback = NULL; | ||
| 1226 | void *callback_data = NULL; | ||
| 1227 | UI_METHOD *ui_method = NULL; | ||
| 1228 | |||
| 1229 | if (cactx) | ||
| 1230 | { | ||
| 1231 | if (cactx->ui_method) | ||
| 1232 | ui_method = cactx->ui_method; | ||
| 1233 | if (cactx->password_callback) | ||
| 1234 | callback = cactx->password_callback; | ||
| 1235 | if (cactx->callback_data) | ||
| 1236 | callback_data = cactx->callback_data; | ||
| 1237 | } | ||
| 1238 | if (ppctx) | ||
| 1239 | { | ||
| 1240 | if (ppctx->ui_method) | ||
| 1241 | { | ||
| 1242 | ui_method = ppctx->ui_method; | ||
| 1243 | callback = NULL; | ||
| 1244 | } | ||
| 1245 | if (ppctx->callback_data) | ||
| 1246 | callback_data = ppctx->callback_data; | ||
| 1247 | } | ||
| 1248 | if (callback == NULL && ui_method == NULL) | ||
| 1249 | { | ||
| 1250 | HWCRHKerr(HWCRHK_F_HWCRHK_GET_PASS,HWCRHK_R_NO_CALLBACK); | ||
| 1251 | return -1; | ||
| 1252 | } | ||
| 1253 | |||
| 1254 | if (ui_method) | ||
| 1255 | { | ||
| 1256 | UI *ui = UI_new_method(ui_method); | ||
| 1257 | if (ui) | ||
| 1258 | { | ||
| 1259 | int ok; | ||
| 1260 | char *prompt = UI_construct_prompt(ui, | ||
| 1261 | "pass phrase", prompt_info); | ||
| 1262 | |||
| 1263 | ok = UI_add_input_string(ui,prompt, | ||
| 1264 | UI_INPUT_FLAG_DEFAULT_PWD, | ||
| 1265 | buf,0,(*len_io) - 1); | ||
| 1266 | UI_add_user_data(ui, callback_data); | ||
| 1267 | UI_ctrl(ui, UI_CTRL_PRINT_ERRORS, 1, 0, 0); | ||
| 1268 | |||
| 1269 | if (ok >= 0) | ||
| 1270 | do | ||
| 1271 | { | ||
| 1272 | ok=UI_process(ui); | ||
| 1273 | } | ||
| 1274 | while (ok < 0 && UI_ctrl(ui, UI_CTRL_IS_REDOABLE, 0, 0, 0)); | ||
| 1275 | |||
| 1276 | if (ok >= 0) | ||
| 1277 | *len_io = strlen(buf); | ||
| 1278 | |||
| 1279 | UI_free(ui); | ||
| 1280 | OPENSSL_free(prompt); | ||
| 1281 | } | ||
| 1282 | } | ||
| 1283 | else | ||
| 1284 | { | ||
| 1285 | *len_io = callback(buf, *len_io, 0, callback_data); | ||
| 1286 | } | ||
| 1287 | if(!*len_io) | ||
| 1288 | return -1; | ||
| 1289 | return 0; | ||
| 1290 | } | ||
| 1291 | |||
| 1292 | static int hwcrhk_insert_card(const char *prompt_info, | ||
| 1293 | const char *wrong_info, | ||
| 1294 | HWCryptoHook_PassphraseContext *ppctx, | ||
| 1295 | HWCryptoHook_CallerContext *cactx) | ||
| 1296 | { | ||
| 1297 | int ok = -1; | ||
| 1298 | UI *ui; | ||
| 1299 | void *callback_data = NULL; | ||
| 1300 | UI_METHOD *ui_method = NULL; | ||
| 1301 | |||
| 1302 | if (cactx) | ||
| 1303 | { | ||
| 1304 | if (cactx->ui_method) | ||
| 1305 | ui_method = cactx->ui_method; | ||
| 1306 | if (cactx->callback_data) | ||
| 1307 | callback_data = cactx->callback_data; | ||
| 1308 | } | ||
| 1309 | if (ppctx) | ||
| 1310 | { | ||
| 1311 | if (ppctx->ui_method) | ||
| 1312 | ui_method = ppctx->ui_method; | ||
| 1313 | if (ppctx->callback_data) | ||
| 1314 | callback_data = ppctx->callback_data; | ||
| 1315 | } | ||
| 1316 | if (ui_method == NULL) | ||
| 1317 | { | ||
| 1318 | HWCRHKerr(HWCRHK_F_HWCRHK_INSERT_CARD, | ||
| 1319 | HWCRHK_R_NO_CALLBACK); | ||
| 1320 | return -1; | ||
| 1321 | } | ||
| 1322 | |||
| 1323 | ui = UI_new_method(ui_method); | ||
| 1324 | |||
| 1325 | if (ui) | ||
| 1326 | { | ||
| 1327 | char answer; | ||
| 1328 | char buf[BUFSIZ]; | ||
| 1329 | |||
| 1330 | if (wrong_info) | ||
| 1331 | BIO_snprintf(buf, sizeof(buf)-1, | ||
| 1332 | "Current card: \"%s\"\n", wrong_info); | ||
| 1333 | ok = UI_dup_info_string(ui, buf); | ||
| 1334 | if (ok >= 0 && prompt_info) | ||
| 1335 | { | ||
| 1336 | BIO_snprintf(buf, sizeof(buf)-1, | ||
| 1337 | "Insert card \"%s\"", prompt_info); | ||
| 1338 | ok = UI_dup_input_boolean(ui, buf, | ||
| 1339 | "\n then hit <enter> or C<enter> to cancel\n", | ||
| 1340 | "\r\n", "Cc", UI_INPUT_FLAG_ECHO, &answer); | ||
| 1341 | } | ||
| 1342 | UI_add_user_data(ui, callback_data); | ||
| 1343 | |||
| 1344 | if (ok >= 0) | ||
| 1345 | ok = UI_process(ui); | ||
| 1346 | UI_free(ui); | ||
| 1347 | |||
| 1348 | if (ok == -2 || (ok >= 0 && answer == 'C')) | ||
| 1349 | ok = 1; | ||
| 1350 | else if (ok < 0) | ||
| 1351 | ok = -1; | ||
| 1352 | else | ||
| 1353 | ok = 0; | ||
| 1354 | } | ||
| 1355 | return ok; | ||
| 1356 | } | ||
| 1357 | |||
| 1358 | static void hwcrhk_log_message(void *logstr, const char *message) | ||
| 1359 | { | ||
| 1360 | BIO *lstream = NULL; | ||
| 1361 | |||
| 1362 | CRYPTO_w_lock(CRYPTO_LOCK_BIO); | ||
| 1363 | if (logstr) | ||
| 1364 | lstream=*(BIO **)logstr; | ||
| 1365 | if (lstream) | ||
| 1366 | { | ||
| 1367 | BIO_printf(lstream, "%s\n", message); | ||
| 1368 | } | ||
| 1369 | CRYPTO_w_unlock(CRYPTO_LOCK_BIO); | ||
| 1370 | } | ||
| 1371 | |||
| 1372 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | ||
| 1373 | * shared-library. */ | ||
| 1374 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
| 1375 | static int bind_fn(ENGINE *e, const char *id) | ||
| 1376 | { | ||
| 1377 | if(id && (strcmp(id, engine_hwcrhk_id) != 0)) | ||
| 1378 | return 0; | ||
| 1379 | if(!bind_helper(e)) | ||
| 1380 | return 0; | ||
| 1381 | return 1; | ||
| 1382 | } | ||
| 1383 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
| 1384 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | ||
| 1385 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | ||
| 1386 | |||
| 1387 | #endif /* !OPENSSL_NO_HW_NCIPHER */ | ||
| 1388 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_ncipher_err.h b/src/lib/libcrypto/engine/hw_ncipher_err.h deleted file mode 100644 index d232d02319..0000000000 --- a/src/lib/libcrypto/engine/hw_ncipher_err.h +++ /dev/null | |||
| @@ -1,101 +0,0 @@ | |||
| 1 | /* ==================================================================== | ||
| 2 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | ||
| 3 | * | ||
| 4 | * Redistribution and use in source and binary forms, with or without | ||
| 5 | * modification, are permitted provided that the following conditions | ||
| 6 | * are met: | ||
| 7 | * | ||
| 8 | * 1. Redistributions of source code must retain the above copyright | ||
| 9 | * notice, this list of conditions and the following disclaimer. | ||
| 10 | * | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in | ||
| 13 | * the documentation and/or other materials provided with the | ||
| 14 | * distribution. | ||
| 15 | * | ||
| 16 | * 3. All advertising materials mentioning features or use of this | ||
| 17 | * software must display the following acknowledgment: | ||
| 18 | * "This product includes software developed by the OpenSSL Project | ||
| 19 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 20 | * | ||
| 21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 22 | * endorse or promote products derived from this software without | ||
| 23 | * prior written permission. For written permission, please contact | ||
| 24 | * openssl-core@openssl.org. | ||
| 25 | * | ||
| 26 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 27 | * nor may "OpenSSL" appear in their names without prior written | ||
| 28 | * permission of the OpenSSL Project. | ||
| 29 | * | ||
| 30 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 31 | * acknowledgment: | ||
| 32 | * "This product includes software developed by the OpenSSL Project | ||
| 33 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 34 | * | ||
| 35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 46 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 47 | * ==================================================================== | ||
| 48 | * | ||
| 49 | * This product includes cryptographic software written by Eric Young | ||
| 50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 51 | * Hudson (tjh@cryptsoft.com). | ||
| 52 | * | ||
| 53 | */ | ||
| 54 | |||
| 55 | #ifndef HEADER_HWCRHK_ERR_H | ||
| 56 | #define HEADER_HWCRHK_ERR_H | ||
| 57 | |||
| 58 | /* BEGIN ERROR CODES */ | ||
| 59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 60 | * made after this point may be overwritten when the script is next run. | ||
| 61 | */ | ||
| 62 | static void ERR_load_HWCRHK_strings(void); | ||
| 63 | static void ERR_unload_HWCRHK_strings(void); | ||
| 64 | static void ERR_HWCRHK_error(int function, int reason, char *file, int line); | ||
| 65 | #define HWCRHKerr(f,r) ERR_HWCRHK_error((f),(r),__FILE__,__LINE__) | ||
| 66 | |||
| 67 | /* Error codes for the HWCRHK functions. */ | ||
| 68 | |||
| 69 | /* Function codes. */ | ||
| 70 | #define HWCRHK_F_HWCRHK_CTRL 100 | ||
| 71 | #define HWCRHK_F_HWCRHK_FINISH 101 | ||
| 72 | #define HWCRHK_F_HWCRHK_GET_PASS 102 | ||
| 73 | #define HWCRHK_F_HWCRHK_INIT 103 | ||
| 74 | #define HWCRHK_F_HWCRHK_INSERT_CARD 104 | ||
| 75 | #define HWCRHK_F_HWCRHK_LOAD_PRIVKEY 105 | ||
| 76 | #define HWCRHK_F_HWCRHK_LOAD_PUBKEY 106 | ||
| 77 | #define HWCRHK_F_HWCRHK_MOD_EXP 107 | ||
| 78 | #define HWCRHK_F_HWCRHK_RAND_BYTES 108 | ||
| 79 | #define HWCRHK_F_HWCRHK_RSA_MOD_EXP 109 | ||
| 80 | |||
| 81 | /* Reason codes. */ | ||
| 82 | #define HWCRHK_R_ALREADY_LOADED 100 | ||
| 83 | #define HWCRHK_R_BIO_WAS_FREED 101 | ||
| 84 | #define HWCRHK_R_CHIL_ERROR 102 | ||
| 85 | #define HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103 | ||
| 86 | #define HWCRHK_R_DSO_FAILURE 104 | ||
| 87 | #define HWCRHK_R_DYNAMIC_LOCKING_MISSING 114 | ||
| 88 | #define HWCRHK_R_MISSING_KEY_COMPONENTS 105 | ||
| 89 | #define HWCRHK_R_NOT_INITIALISED 106 | ||
| 90 | #define HWCRHK_R_NOT_LOADED 107 | ||
| 91 | #define HWCRHK_R_NO_CALLBACK 108 | ||
| 92 | #define HWCRHK_R_NO_KEY 109 | ||
| 93 | #define HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED 110 | ||
| 94 | #define HWCRHK_R_REQUEST_FAILED 111 | ||
| 95 | #define HWCRHK_R_REQUEST_FALLBACK 112 | ||
| 96 | #define HWCRHK_R_UNIT_FAILURE 113 | ||
| 97 | |||
| 98 | #ifdef __cplusplus | ||
| 99 | } | ||
| 100 | #endif | ||
| 101 | #endif | ||
diff --git a/src/lib/libcrypto/engine/hw_sureware.c b/src/lib/libcrypto/engine/hw_sureware.c deleted file mode 100644 index fca467e690..0000000000 --- a/src/lib/libcrypto/engine/hw_sureware.c +++ /dev/null | |||
| @@ -1,1039 +0,0 @@ | |||
| 1 | /* Written by Corinne Dive-Reclus(cdive@baltimore.com) | ||
| 2 | * | ||
| 3 | * | ||
| 4 | * Redistribution and use in source and binary forms, with or without | ||
| 5 | * modification, are permitted provided that the following conditions | ||
| 6 | * are met: | ||
| 7 | * | ||
| 8 | * 1. Redistributions of source code must retain the above copyright | ||
| 9 | * notice, this list of conditions and the following disclaimer. | ||
| 10 | * | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in | ||
| 13 | * the documentation and/or other materials provided with the | ||
| 14 | * distribution. | ||
| 15 | * | ||
| 16 | * 3. All advertising materials mentioning features or use of this | ||
| 17 | * software must display the following acknowledgment: | ||
| 18 | * "This product includes software developed by the OpenSSL Project | ||
| 19 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 20 | * | ||
| 21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 22 | * endorse or promote products derived from this software without | ||
| 23 | * prior written permission. For written permission, please contact | ||
| 24 | * licensing@OpenSSL.org. | ||
| 25 | * | ||
| 26 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 27 | * nor may "OpenSSL" appear in their names without prior written | ||
| 28 | * permission of the OpenSSL Project. | ||
| 29 | * | ||
| 30 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 31 | * acknowledgment: | ||
| 32 | * "This product includes software developed by the OpenSSL Project | ||
| 33 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 34 | * | ||
| 35 | * Written by Corinne Dive-Reclus(cdive@baltimore.com) | ||
| 36 | * | ||
| 37 | * Copyright@2001 Baltimore Technologies Ltd. | ||
| 38 | * All right Reserved. | ||
| 39 | * * | ||
| 40 | * THIS FILE IS PROVIDED BY BALTIMORE TECHNOLOGIES ``AS IS'' AND * | ||
| 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * | ||
| 43 | * ARE DISCLAIMED. IN NO EVENT SHALL BALTIMORE TECHNOLOGIES BE LIABLE * | ||
| 44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * | ||
| 45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * | ||
| 46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * | ||
| 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * | ||
| 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * | ||
| 50 | * SUCH DAMAGE. * | ||
| 51 | ====================================================================*/ | ||
| 52 | |||
| 53 | #include <stdio.h> | ||
| 54 | #include "cryptlib.h" | ||
| 55 | #include <openssl/crypto.h> | ||
| 56 | #include <openssl/pem.h> | ||
| 57 | #include <openssl/dso.h> | ||
| 58 | #include "eng_int.h" | ||
| 59 | #include "engine.h" | ||
| 60 | #include <openssl/engine.h> | ||
| 61 | |||
| 62 | #ifndef OPENSSL_NO_HW | ||
| 63 | #ifndef OPENSSL_NO_HW_SUREWARE | ||
| 64 | |||
| 65 | #ifdef FLAT_INC | ||
| 66 | #include "sureware.h" | ||
| 67 | #else | ||
| 68 | #include "vendor_defns/sureware.h" | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #define SUREWARE_LIB_NAME "sureware engine" | ||
| 72 | #include "hw_sureware_err.c" | ||
| 73 | |||
| 74 | static int surewarehk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
| 75 | static int surewarehk_destroy(ENGINE *e); | ||
| 76 | static int surewarehk_init(ENGINE *e); | ||
| 77 | static int surewarehk_finish(ENGINE *e); | ||
| 78 | static int surewarehk_modexp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 79 | const BIGNUM *m, BN_CTX *ctx); | ||
| 80 | |||
| 81 | /* RSA stuff */ | ||
| 82 | static int surewarehk_rsa_priv_dec(int flen,const unsigned char *from,unsigned char *to, | ||
| 83 | RSA *rsa,int padding); | ||
| 84 | static int surewarehk_rsa_sign(int flen,const unsigned char *from,unsigned char *to, | ||
| 85 | RSA *rsa,int padding); | ||
| 86 | |||
| 87 | /* RAND stuff */ | ||
| 88 | static int surewarehk_rand_bytes(unsigned char *buf, int num); | ||
| 89 | static void surewarehk_rand_seed(const void *buf, int num); | ||
| 90 | static void surewarehk_rand_add(const void *buf, int num, double entropy); | ||
| 91 | |||
| 92 | /* KM stuff */ | ||
| 93 | static EVP_PKEY *surewarehk_load_privkey(ENGINE *e, const char *key_id, | ||
| 94 | UI_METHOD *ui_method, void *callback_data); | ||
| 95 | static EVP_PKEY *surewarehk_load_pubkey(ENGINE *e, const char *key_id, | ||
| 96 | UI_METHOD *ui_method, void *callback_data); | ||
| 97 | static void surewarehk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
| 98 | int idx,long argl, void *argp); | ||
| 99 | #if 0 | ||
| 100 | static void surewarehk_dh_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
| 101 | int idx,long argl, void *argp); | ||
| 102 | #endif | ||
| 103 | |||
| 104 | #ifndef OPENSSL_NO_RSA | ||
| 105 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
| 106 | static int surewarehk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 107 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
| 108 | { | ||
| 109 | return surewarehk_modexp(r, a, p, m, ctx); | ||
| 110 | } | ||
| 111 | |||
| 112 | /* Our internal RSA_METHOD that we provide pointers to */ | ||
| 113 | static RSA_METHOD surewarehk_rsa = | ||
| 114 | { | ||
| 115 | "SureWare RSA method", | ||
| 116 | NULL, /* pub_enc*/ | ||
| 117 | NULL, /* pub_dec*/ | ||
| 118 | surewarehk_rsa_sign, /* our rsa_sign is OpenSSL priv_enc*/ | ||
| 119 | surewarehk_rsa_priv_dec, /* priv_dec*/ | ||
| 120 | NULL, /*mod_exp*/ | ||
| 121 | surewarehk_mod_exp_mont, /*mod_exp_mongomery*/ | ||
| 122 | NULL, /* init*/ | ||
| 123 | NULL, /* finish*/ | ||
| 124 | 0, /* RSA flag*/ | ||
| 125 | NULL, | ||
| 126 | NULL, /* OpenSSL sign*/ | ||
| 127 | NULL /* OpenSSL verify*/ | ||
| 128 | }; | ||
| 129 | #endif | ||
| 130 | |||
| 131 | #ifndef OPENSSL_NO_DH | ||
| 132 | /* Our internal DH_METHOD that we provide pointers to */ | ||
| 133 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | ||
| 134 | static int surewarehk_modexp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 135 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
| 136 | { | ||
| 137 | return surewarehk_modexp(r, a, p, m, ctx); | ||
| 138 | } | ||
| 139 | |||
| 140 | static DH_METHOD surewarehk_dh = | ||
| 141 | { | ||
| 142 | "SureWare DH method", | ||
| 143 | NULL,/*gen_key*/ | ||
| 144 | NULL,/*agree,*/ | ||
| 145 | surewarehk_modexp_dh, /*dh mod exp*/ | ||
| 146 | NULL, /* init*/ | ||
| 147 | NULL, /* finish*/ | ||
| 148 | 0, /* flags*/ | ||
| 149 | NULL | ||
| 150 | }; | ||
| 151 | #endif | ||
| 152 | |||
| 153 | static RAND_METHOD surewarehk_rand = | ||
| 154 | { | ||
| 155 | /* "SureWare RAND method", */ | ||
| 156 | surewarehk_rand_seed, | ||
| 157 | surewarehk_rand_bytes, | ||
| 158 | NULL,/*cleanup*/ | ||
| 159 | surewarehk_rand_add, | ||
| 160 | surewarehk_rand_bytes, | ||
| 161 | NULL,/*rand_status*/ | ||
| 162 | }; | ||
| 163 | |||
| 164 | #ifndef OPENSSL_NO_DSA | ||
| 165 | /* DSA stuff */ | ||
| 166 | static DSA_SIG * surewarehk_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | ||
| 167 | static int surewarehk_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
| 168 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
| 169 | BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
| 170 | { | ||
| 171 | BIGNUM t; | ||
| 172 | int to_return = 0; | ||
| 173 | BN_init(&t); | ||
| 174 | /* let rr = a1 ^ p1 mod m */ | ||
| 175 | if (!surewarehk_modexp(rr,a1,p1,m,ctx)) goto end; | ||
| 176 | /* let t = a2 ^ p2 mod m */ | ||
| 177 | if (!surewarehk_modexp(&t,a2,p2,m,ctx)) goto end; | ||
| 178 | /* let rr = rr * t mod m */ | ||
| 179 | if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end; | ||
| 180 | to_return = 1; | ||
| 181 | end: | ||
| 182 | BN_free(&t); | ||
| 183 | return to_return; | ||
| 184 | } | ||
| 185 | |||
| 186 | static DSA_METHOD surewarehk_dsa = | ||
| 187 | { | ||
| 188 | "SureWare DSA method", | ||
| 189 | surewarehk_dsa_do_sign, | ||
| 190 | NULL,/*sign setup*/ | ||
| 191 | NULL,/*verify,*/ | ||
| 192 | surewarehk_dsa_mod_exp,/*mod exp*/ | ||
| 193 | NULL,/*bn mod exp*/ | ||
| 194 | NULL, /*init*/ | ||
| 195 | NULL,/*finish*/ | ||
| 196 | 0, | ||
| 197 | NULL, | ||
| 198 | }; | ||
| 199 | #endif | ||
| 200 | |||
| 201 | static const char *engine_sureware_id = "sureware"; | ||
| 202 | static const char *engine_sureware_name = "SureWare hardware engine support"; | ||
| 203 | |||
| 204 | /* Now, to our own code */ | ||
| 205 | |||
| 206 | /* As this is only ever called once, there's no need for locking | ||
| 207 | * (indeed - the lock will already be held by our caller!!!) */ | ||
| 208 | static int bind_sureware(ENGINE *e) | ||
| 209 | { | ||
| 210 | #ifndef OPENSSL_NO_RSA | ||
| 211 | const RSA_METHOD *meth1; | ||
| 212 | #endif | ||
| 213 | #ifndef OPENSSL_NO_DSA | ||
| 214 | const DSA_METHOD *meth2; | ||
| 215 | #endif | ||
| 216 | #ifndef OPENSSL_NO_DH | ||
| 217 | const DH_METHOD *meth3; | ||
| 218 | #endif | ||
| 219 | |||
| 220 | if(!ENGINE_set_id(e, engine_sureware_id) || | ||
| 221 | !ENGINE_set_name(e, engine_sureware_name) || | ||
| 222 | #ifndef OPENSSL_NO_RSA | ||
| 223 | !ENGINE_set_RSA(e, &surewarehk_rsa) || | ||
| 224 | #endif | ||
| 225 | #ifndef OPENSSL_NO_DSA | ||
| 226 | !ENGINE_set_DSA(e, &surewarehk_dsa) || | ||
| 227 | #endif | ||
| 228 | #ifndef OPENSSL_NO_DH | ||
| 229 | !ENGINE_set_DH(e, &surewarehk_dh) || | ||
| 230 | #endif | ||
| 231 | !ENGINE_set_RAND(e, &surewarehk_rand) || | ||
| 232 | !ENGINE_set_destroy_function(e, surewarehk_destroy) || | ||
| 233 | !ENGINE_set_init_function(e, surewarehk_init) || | ||
| 234 | !ENGINE_set_finish_function(e, surewarehk_finish) || | ||
| 235 | !ENGINE_set_ctrl_function(e, surewarehk_ctrl) || | ||
| 236 | !ENGINE_set_load_privkey_function(e, surewarehk_load_privkey) || | ||
| 237 | !ENGINE_set_load_pubkey_function(e, surewarehk_load_pubkey)) | ||
| 238 | return 0; | ||
| 239 | |||
| 240 | #ifndef OPENSSL_NO_RSA | ||
| 241 | /* We know that the "PKCS1_SSLeay()" functions hook properly | ||
| 242 | * to the cswift-specific mod_exp and mod_exp_crt so we use | ||
| 243 | * those functions. NB: We don't use ENGINE_openssl() or | ||
| 244 | * anything "more generic" because something like the RSAref | ||
| 245 | * code may not hook properly, and if you own one of these | ||
| 246 | * cards then you have the right to do RSA operations on it | ||
| 247 | * anyway! */ | ||
| 248 | meth1 = RSA_PKCS1_SSLeay(); | ||
| 249 | if (meth1) | ||
| 250 | { | ||
| 251 | surewarehk_rsa.rsa_pub_enc = meth1->rsa_pub_enc; | ||
| 252 | surewarehk_rsa.rsa_pub_dec = meth1->rsa_pub_dec; | ||
| 253 | } | ||
| 254 | #endif | ||
| 255 | |||
| 256 | #ifndef OPENSSL_NO_DSA | ||
| 257 | /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish | ||
| 258 | * bits. */ | ||
| 259 | meth2 = DSA_OpenSSL(); | ||
| 260 | if (meth2) | ||
| 261 | { | ||
| 262 | surewarehk_dsa.dsa_do_verify = meth2->dsa_do_verify; | ||
| 263 | } | ||
| 264 | #endif | ||
| 265 | |||
| 266 | #ifndef OPENSSL_NO_DH | ||
| 267 | /* Much the same for Diffie-Hellman */ | ||
| 268 | meth3 = DH_OpenSSL(); | ||
| 269 | if (meth3) | ||
| 270 | { | ||
| 271 | surewarehk_dh.generate_key = meth3->generate_key; | ||
| 272 | surewarehk_dh.compute_key = meth3->compute_key; | ||
| 273 | } | ||
| 274 | #endif | ||
| 275 | |||
| 276 | /* Ensure the sureware error handling is set up */ | ||
| 277 | ERR_load_SUREWARE_strings(); | ||
| 278 | return 1; | ||
| 279 | } | ||
| 280 | |||
| 281 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
| 282 | static int bind_helper(ENGINE *e, const char *id) | ||
| 283 | { | ||
| 284 | if(id && (strcmp(id, engine_sureware_id) != 0)) | ||
| 285 | return 0; | ||
| 286 | if(!bind_sureware(e)) | ||
| 287 | return 0; | ||
| 288 | return 1; | ||
| 289 | } | ||
| 290 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
| 291 | IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) | ||
| 292 | #else | ||
| 293 | static ENGINE *engine_sureware(void) | ||
| 294 | { | ||
| 295 | ENGINE *ret = ENGINE_new(); | ||
| 296 | if(!ret) | ||
| 297 | return NULL; | ||
| 298 | if(!bind_sureware(ret)) | ||
| 299 | { | ||
| 300 | ENGINE_free(ret); | ||
| 301 | return NULL; | ||
| 302 | } | ||
| 303 | return ret; | ||
| 304 | } | ||
| 305 | |||
| 306 | void ENGINE_load_sureware(void) | ||
| 307 | { | ||
| 308 | /* Copied from eng_[openssl|dyn].c */ | ||
| 309 | ENGINE *toadd = engine_sureware(); | ||
| 310 | if(!toadd) return; | ||
| 311 | ENGINE_add(toadd); | ||
| 312 | ENGINE_free(toadd); | ||
| 313 | ERR_clear_error(); | ||
| 314 | } | ||
| 315 | #endif | ||
| 316 | |||
| 317 | /* This is a process-global DSO handle used for loading and unloading | ||
| 318 | * the SureWareHook library. NB: This is only set (or unset) during an | ||
| 319 | * init() or finish() call (reference counts permitting) and they're | ||
| 320 | * operating with global locks, so this should be thread-safe | ||
| 321 | * implicitly. */ | ||
| 322 | static DSO *surewarehk_dso = NULL; | ||
| 323 | #ifndef OPENSSL_NO_RSA | ||
| 324 | static int rsaHndidx = -1; /* Index for KM handle. Not really used yet. */ | ||
| 325 | #endif | ||
| 326 | #ifndef OPENSSL_NO_DSA | ||
| 327 | static int dsaHndidx = -1; /* Index for KM handle. Not really used yet. */ | ||
| 328 | #endif | ||
| 329 | |||
| 330 | /* These are the function pointers that are (un)set when the library has | ||
| 331 | * successfully (un)loaded. */ | ||
| 332 | static SureWareHook_Init_t *p_surewarehk_Init = NULL; | ||
| 333 | static SureWareHook_Finish_t *p_surewarehk_Finish = NULL; | ||
| 334 | static SureWareHook_Rand_Bytes_t *p_surewarehk_Rand_Bytes = NULL; | ||
| 335 | static SureWareHook_Rand_Seed_t *p_surewarehk_Rand_Seed = NULL; | ||
| 336 | static SureWareHook_Load_Privkey_t *p_surewarehk_Load_Privkey = NULL; | ||
| 337 | static SureWareHook_Info_Pubkey_t *p_surewarehk_Info_Pubkey = NULL; | ||
| 338 | static SureWareHook_Load_Rsa_Pubkey_t *p_surewarehk_Load_Rsa_Pubkey = NULL; | ||
| 339 | static SureWareHook_Load_Dsa_Pubkey_t *p_surewarehk_Load_Dsa_Pubkey = NULL; | ||
| 340 | static SureWareHook_Free_t *p_surewarehk_Free=NULL; | ||
| 341 | static SureWareHook_Rsa_Priv_Dec_t *p_surewarehk_Rsa_Priv_Dec=NULL; | ||
| 342 | static SureWareHook_Rsa_Sign_t *p_surewarehk_Rsa_Sign=NULL; | ||
| 343 | static SureWareHook_Dsa_Sign_t *p_surewarehk_Dsa_Sign=NULL; | ||
| 344 | static SureWareHook_Mod_Exp_t *p_surewarehk_Mod_Exp=NULL; | ||
| 345 | |||
| 346 | /* Used in the DSO operations. */ | ||
| 347 | static const char *surewarehk_LIBNAME = "SureWareHook"; | ||
| 348 | static const char *n_surewarehk_Init = "SureWareHook_Init"; | ||
| 349 | static const char *n_surewarehk_Finish = "SureWareHook_Finish"; | ||
| 350 | static const char *n_surewarehk_Rand_Bytes="SureWareHook_Rand_Bytes"; | ||
| 351 | static const char *n_surewarehk_Rand_Seed="SureWareHook_Rand_Seed"; | ||
| 352 | static const char *n_surewarehk_Load_Privkey="SureWareHook_Load_Privkey"; | ||
| 353 | static const char *n_surewarehk_Info_Pubkey="SureWareHook_Info_Pubkey"; | ||
| 354 | static const char *n_surewarehk_Load_Rsa_Pubkey="SureWareHook_Load_Rsa_Pubkey"; | ||
| 355 | static const char *n_surewarehk_Load_Dsa_Pubkey="SureWareHook_Load_Dsa_Pubkey"; | ||
| 356 | static const char *n_surewarehk_Free="SureWareHook_Free"; | ||
| 357 | static const char *n_surewarehk_Rsa_Priv_Dec="SureWareHook_Rsa_Priv_Dec"; | ||
| 358 | static const char *n_surewarehk_Rsa_Sign="SureWareHook_Rsa_Sign"; | ||
| 359 | static const char *n_surewarehk_Dsa_Sign="SureWareHook_Dsa_Sign"; | ||
| 360 | static const char *n_surewarehk_Mod_Exp="SureWareHook_Mod_Exp"; | ||
| 361 | static BIO *logstream = NULL; | ||
| 362 | |||
| 363 | /* SureWareHook library functions and mechanics - these are used by the | ||
| 364 | * higher-level functions further down. NB: As and where there's no | ||
| 365 | * error checking, take a look lower down where these functions are | ||
| 366 | * called, the checking and error handling is probably down there. | ||
| 367 | */ | ||
| 368 | static int threadsafe=1; | ||
| 369 | static int surewarehk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
| 370 | { | ||
| 371 | int to_return = 1; | ||
| 372 | |||
| 373 | switch(cmd) | ||
| 374 | { | ||
| 375 | case ENGINE_CTRL_SET_LOGSTREAM: | ||
| 376 | { | ||
| 377 | BIO *bio = (BIO *)p; | ||
| 378 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 379 | if (logstream) | ||
| 380 | { | ||
| 381 | BIO_free(logstream); | ||
| 382 | logstream = NULL; | ||
| 383 | } | ||
| 384 | if (CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO) > 1) | ||
| 385 | logstream = bio; | ||
| 386 | else | ||
| 387 | SUREWAREerr(SUREWARE_F_SUREWAREHK_CTRL,SUREWARE_R_BIO_WAS_FREED); | ||
| 388 | } | ||
| 389 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 390 | break; | ||
| 391 | /* This will prevent the initialisation function from "installing" | ||
| 392 | * the mutex-handling callbacks, even if they are available from | ||
| 393 | * within the library (or were provided to the library from the | ||
| 394 | * calling application). This is to remove any baggage for | ||
| 395 | * applications not using multithreading. */ | ||
| 396 | case ENGINE_CTRL_CHIL_NO_LOCKING: | ||
| 397 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
| 398 | threadsafe = 0; | ||
| 399 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
| 400 | break; | ||
| 401 | |||
| 402 | /* The command isn't understood by this engine */ | ||
| 403 | default: | ||
| 404 | SUREWAREerr(SUREWARE_F_SUREWAREHK_CTRL, | ||
| 405 | ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
| 406 | to_return = 0; | ||
| 407 | break; | ||
| 408 | } | ||
| 409 | |||
| 410 | return to_return; | ||
| 411 | } | ||
| 412 | |||
| 413 | /* Destructor (complements the "ENGINE_surewarehk()" constructor) */ | ||
| 414 | static int surewarehk_destroy(ENGINE *e) | ||
| 415 | { | ||
| 416 | ERR_unload_SUREWARE_strings(); | ||
| 417 | return 1; | ||
| 418 | } | ||
| 419 | |||
| 420 | /* (de)initialisation functions. */ | ||
| 421 | static int surewarehk_init(ENGINE *e) | ||
| 422 | { | ||
| 423 | char msg[64]="ENGINE_init"; | ||
| 424 | SureWareHook_Init_t *p1=NULL; | ||
| 425 | SureWareHook_Finish_t *p2=NULL; | ||
| 426 | SureWareHook_Rand_Bytes_t *p3=NULL; | ||
| 427 | SureWareHook_Rand_Seed_t *p4=NULL; | ||
| 428 | SureWareHook_Load_Privkey_t *p5=NULL; | ||
| 429 | SureWareHook_Load_Rsa_Pubkey_t *p6=NULL; | ||
| 430 | SureWareHook_Free_t *p7=NULL; | ||
| 431 | SureWareHook_Rsa_Priv_Dec_t *p8=NULL; | ||
| 432 | SureWareHook_Rsa_Sign_t *p9=NULL; | ||
| 433 | SureWareHook_Dsa_Sign_t *p12=NULL; | ||
| 434 | SureWareHook_Info_Pubkey_t *p13=NULL; | ||
| 435 | SureWareHook_Load_Dsa_Pubkey_t *p14=NULL; | ||
| 436 | SureWareHook_Mod_Exp_t *p15=NULL; | ||
| 437 | |||
| 438 | if(surewarehk_dso != NULL) | ||
| 439 | { | ||
| 440 | SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,ENGINE_R_ALREADY_LOADED); | ||
| 441 | goto err; | ||
| 442 | } | ||
| 443 | /* Attempt to load libsurewarehk.so/surewarehk.dll/whatever. */ | ||
| 444 | surewarehk_dso = DSO_load(NULL, surewarehk_LIBNAME, NULL, 0); | ||
| 445 | if(surewarehk_dso == NULL) | ||
| 446 | { | ||
| 447 | SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,ENGINE_R_DSO_FAILURE); | ||
| 448 | goto err; | ||
| 449 | } | ||
| 450 | if(!(p1=(SureWareHook_Init_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Init)) || | ||
| 451 | !(p2=(SureWareHook_Finish_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Finish)) || | ||
| 452 | !(p3=(SureWareHook_Rand_Bytes_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rand_Bytes)) || | ||
| 453 | !(p4=(SureWareHook_Rand_Seed_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rand_Seed)) || | ||
| 454 | !(p5=(SureWareHook_Load_Privkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Load_Privkey)) || | ||
| 455 | !(p6=(SureWareHook_Load_Rsa_Pubkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Load_Rsa_Pubkey)) || | ||
| 456 | !(p7=(SureWareHook_Free_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Free)) || | ||
| 457 | !(p8=(SureWareHook_Rsa_Priv_Dec_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rsa_Priv_Dec)) || | ||
| 458 | !(p9=(SureWareHook_Rsa_Sign_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rsa_Sign)) || | ||
| 459 | !(p12=(SureWareHook_Dsa_Sign_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Dsa_Sign)) || | ||
| 460 | !(p13=(SureWareHook_Info_Pubkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Info_Pubkey)) || | ||
| 461 | !(p14=(SureWareHook_Load_Dsa_Pubkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Load_Dsa_Pubkey)) || | ||
| 462 | !(p15=(SureWareHook_Mod_Exp_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Mod_Exp))) | ||
| 463 | { | ||
| 464 | SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,ENGINE_R_DSO_FAILURE); | ||
| 465 | goto err; | ||
| 466 | } | ||
| 467 | /* Copy the pointers */ | ||
| 468 | p_surewarehk_Init = p1; | ||
| 469 | p_surewarehk_Finish = p2; | ||
| 470 | p_surewarehk_Rand_Bytes = p3; | ||
| 471 | p_surewarehk_Rand_Seed = p4; | ||
| 472 | p_surewarehk_Load_Privkey = p5; | ||
| 473 | p_surewarehk_Load_Rsa_Pubkey = p6; | ||
| 474 | p_surewarehk_Free = p7; | ||
| 475 | p_surewarehk_Rsa_Priv_Dec = p8; | ||
| 476 | p_surewarehk_Rsa_Sign = p9; | ||
| 477 | p_surewarehk_Dsa_Sign = p12; | ||
| 478 | p_surewarehk_Info_Pubkey = p13; | ||
| 479 | p_surewarehk_Load_Dsa_Pubkey = p14; | ||
| 480 | p_surewarehk_Mod_Exp = p15; | ||
| 481 | /* Contact the hardware and initialises it. */ | ||
| 482 | if(p_surewarehk_Init(msg,threadsafe)==SUREWAREHOOK_ERROR_UNIT_FAILURE) | ||
| 483 | { | ||
| 484 | SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,SUREWARE_R_UNIT_FAILURE); | ||
| 485 | goto err; | ||
| 486 | } | ||
| 487 | if(p_surewarehk_Init(msg,threadsafe)==SUREWAREHOOK_ERROR_UNIT_FAILURE) | ||
| 488 | { | ||
| 489 | SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,SUREWARE_R_UNIT_FAILURE); | ||
| 490 | goto err; | ||
| 491 | } | ||
| 492 | /* try to load the default private key, if failed does not return a failure but | ||
| 493 | wait for an explicit ENGINE_load_privakey */ | ||
| 494 | surewarehk_load_privkey(e,NULL,NULL,NULL); | ||
| 495 | |||
| 496 | /* Everything's fine. */ | ||
| 497 | #ifndef OPENSSL_NO_RSA | ||
| 498 | if (rsaHndidx == -1) | ||
| 499 | rsaHndidx = RSA_get_ex_new_index(0, | ||
| 500 | "SureWareHook RSA key handle", | ||
| 501 | NULL, NULL, surewarehk_ex_free); | ||
| 502 | #endif | ||
| 503 | #ifndef OPENSSL_NO_DSA | ||
| 504 | if (dsaHndidx == -1) | ||
| 505 | dsaHndidx = DSA_get_ex_new_index(0, | ||
| 506 | "SureWareHook DSA key handle", | ||
| 507 | NULL, NULL, surewarehk_ex_free); | ||
| 508 | #endif | ||
| 509 | |||
| 510 | return 1; | ||
| 511 | err: | ||
| 512 | if(surewarehk_dso) | ||
| 513 | DSO_free(surewarehk_dso); | ||
| 514 | surewarehk_dso = NULL; | ||
| 515 | p_surewarehk_Init = NULL; | ||
| 516 | p_surewarehk_Finish = NULL; | ||
| 517 | p_surewarehk_Rand_Bytes = NULL; | ||
| 518 | p_surewarehk_Rand_Seed = NULL; | ||
| 519 | p_surewarehk_Load_Privkey = NULL; | ||
| 520 | p_surewarehk_Load_Rsa_Pubkey = NULL; | ||
| 521 | p_surewarehk_Free = NULL; | ||
| 522 | p_surewarehk_Rsa_Priv_Dec = NULL; | ||
| 523 | p_surewarehk_Rsa_Sign = NULL; | ||
| 524 | p_surewarehk_Dsa_Sign = NULL; | ||
| 525 | p_surewarehk_Info_Pubkey = NULL; | ||
| 526 | p_surewarehk_Load_Dsa_Pubkey = NULL; | ||
| 527 | p_surewarehk_Mod_Exp = NULL; | ||
| 528 | return 0; | ||
| 529 | } | ||
| 530 | |||
| 531 | static int surewarehk_finish(ENGINE *e) | ||
| 532 | { | ||
| 533 | int to_return = 1; | ||
| 534 | if(surewarehk_dso == NULL) | ||
| 535 | { | ||
| 536 | SUREWAREerr(SUREWARE_F_SUREWAREHK_FINISH,ENGINE_R_NOT_LOADED); | ||
| 537 | to_return = 0; | ||
| 538 | goto err; | ||
| 539 | } | ||
| 540 | p_surewarehk_Finish(); | ||
| 541 | if(!DSO_free(surewarehk_dso)) | ||
| 542 | { | ||
| 543 | SUREWAREerr(SUREWARE_F_SUREWAREHK_FINISH,ENGINE_R_DSO_FAILURE); | ||
| 544 | to_return = 0; | ||
| 545 | goto err; | ||
| 546 | } | ||
| 547 | err: | ||
| 548 | if (logstream) | ||
| 549 | BIO_free(logstream); | ||
| 550 | surewarehk_dso = NULL; | ||
| 551 | p_surewarehk_Init = NULL; | ||
| 552 | p_surewarehk_Finish = NULL; | ||
| 553 | p_surewarehk_Rand_Bytes = NULL; | ||
| 554 | p_surewarehk_Rand_Seed = NULL; | ||
| 555 | p_surewarehk_Load_Privkey = NULL; | ||
| 556 | p_surewarehk_Load_Rsa_Pubkey = NULL; | ||
| 557 | p_surewarehk_Free = NULL; | ||
| 558 | p_surewarehk_Rsa_Priv_Dec = NULL; | ||
| 559 | p_surewarehk_Rsa_Sign = NULL; | ||
| 560 | p_surewarehk_Dsa_Sign = NULL; | ||
| 561 | p_surewarehk_Info_Pubkey = NULL; | ||
| 562 | p_surewarehk_Load_Dsa_Pubkey = NULL; | ||
| 563 | p_surewarehk_Mod_Exp = NULL; | ||
| 564 | return to_return; | ||
| 565 | } | ||
| 566 | |||
| 567 | static void surewarehk_error_handling(char *const msg,int func,int ret) | ||
| 568 | { | ||
| 569 | switch (ret) | ||
| 570 | { | ||
| 571 | case SUREWAREHOOK_ERROR_UNIT_FAILURE: | ||
| 572 | ENGINEerr(func,SUREWARE_R_UNIT_FAILURE); | ||
| 573 | break; | ||
| 574 | case SUREWAREHOOK_ERROR_FALLBACK: | ||
| 575 | ENGINEerr(func,SUREWARE_R_REQUEST_FALLBACK); | ||
| 576 | break; | ||
| 577 | case SUREWAREHOOK_ERROR_DATA_SIZE: | ||
| 578 | ENGINEerr(func,SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
| 579 | break; | ||
| 580 | case SUREWAREHOOK_ERROR_INVALID_PAD: | ||
| 581 | ENGINEerr(func,RSA_R_PADDING_CHECK_FAILED); | ||
| 582 | break; | ||
| 583 | default: | ||
| 584 | ENGINEerr(func,SUREWARE_R_REQUEST_FAILED); | ||
| 585 | break; | ||
| 586 | case 1:/*nothing*/ | ||
| 587 | msg[0]='\0'; | ||
| 588 | } | ||
| 589 | if (*msg) | ||
| 590 | { | ||
| 591 | ERR_add_error_data(1,msg); | ||
| 592 | if (logstream) | ||
| 593 | { | ||
| 594 | CRYPTO_w_lock(CRYPTO_LOCK_BIO); | ||
| 595 | BIO_write(logstream, msg, strlen(msg)); | ||
| 596 | CRYPTO_w_unlock(CRYPTO_LOCK_BIO); | ||
| 597 | } | ||
| 598 | } | ||
| 599 | } | ||
| 600 | |||
| 601 | static int surewarehk_rand_bytes(unsigned char *buf, int num) | ||
| 602 | { | ||
| 603 | int ret=0; | ||
| 604 | char msg[64]="ENGINE_rand_bytes"; | ||
| 605 | if(!p_surewarehk_Rand_Bytes) | ||
| 606 | { | ||
| 607 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RAND_BYTES,ENGINE_R_NOT_INITIALISED); | ||
| 608 | } | ||
| 609 | else | ||
| 610 | { | ||
| 611 | ret = p_surewarehk_Rand_Bytes(msg,buf, num); | ||
| 612 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RAND_BYTES,ret); | ||
| 613 | } | ||
| 614 | return ret==1 ? 1 : 0; | ||
| 615 | } | ||
| 616 | |||
| 617 | static void surewarehk_rand_seed(const void *buf, int num) | ||
| 618 | { | ||
| 619 | int ret=0; | ||
| 620 | char msg[64]="ENGINE_rand_seed"; | ||
| 621 | if(!p_surewarehk_Rand_Seed) | ||
| 622 | { | ||
| 623 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RAND_SEED,ENGINE_R_NOT_INITIALISED); | ||
| 624 | } | ||
| 625 | else | ||
| 626 | { | ||
| 627 | ret = p_surewarehk_Rand_Seed(msg,buf, num); | ||
| 628 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RAND_SEED,ret); | ||
| 629 | } | ||
| 630 | } | ||
| 631 | |||
| 632 | static void surewarehk_rand_add(const void *buf, int num, double entropy) | ||
| 633 | { | ||
| 634 | surewarehk_rand_seed(buf,num); | ||
| 635 | } | ||
| 636 | |||
| 637 | static EVP_PKEY* sureware_load_public(ENGINE *e,const char *key_id,char *hptr,unsigned long el,char keytype) | ||
| 638 | { | ||
| 639 | EVP_PKEY *res = NULL; | ||
| 640 | #ifndef OPENSSL_NO_RSA | ||
| 641 | RSA *rsatmp = NULL; | ||
| 642 | #endif | ||
| 643 | #ifndef OPENSSL_NO_DSA | ||
| 644 | DSA *dsatmp=NULL; | ||
| 645 | #endif | ||
| 646 | char msg[64]="sureware_load_public"; | ||
| 647 | int ret=0; | ||
| 648 | if(!p_surewarehk_Load_Rsa_Pubkey || !p_surewarehk_Load_Dsa_Pubkey) | ||
| 649 | { | ||
| 650 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ENGINE_R_NOT_INITIALISED); | ||
| 651 | goto err; | ||
| 652 | } | ||
| 653 | switch (keytype) | ||
| 654 | { | ||
| 655 | #ifndef OPENSSL_NO_RSA | ||
| 656 | case 1: /*RSA*/ | ||
| 657 | /* set private external reference */ | ||
| 658 | rsatmp = RSA_new_method(e); | ||
| 659 | RSA_set_ex_data(rsatmp,rsaHndidx,hptr); | ||
| 660 | rsatmp->flags |= RSA_FLAG_EXT_PKEY; | ||
| 661 | |||
| 662 | /* set public big nums*/ | ||
| 663 | rsatmp->e = BN_new(); | ||
| 664 | rsatmp->n = BN_new(); | ||
| 665 | bn_expand2(rsatmp->e, el/sizeof(BN_ULONG)); | ||
| 666 | bn_expand2(rsatmp->n, el/sizeof(BN_ULONG)); | ||
| 667 | if (!rsatmp->e || rsatmp->e->dmax!=(int)(el/sizeof(BN_ULONG))|| | ||
| 668 | !rsatmp->n || rsatmp->n->dmax!=(int)(el/sizeof(BN_ULONG))) | ||
| 669 | goto err; | ||
| 670 | ret=p_surewarehk_Load_Rsa_Pubkey(msg,key_id,el, | ||
| 671 | (unsigned long *)rsatmp->n->d, | ||
| 672 | (unsigned long *)rsatmp->e->d); | ||
| 673 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ret); | ||
| 674 | if (ret!=1) | ||
| 675 | { | ||
| 676 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY); | ||
| 677 | goto err; | ||
| 678 | } | ||
| 679 | /* normalise pub e and pub n */ | ||
| 680 | rsatmp->e->top=el/sizeof(BN_ULONG); | ||
| 681 | bn_fix_top(rsatmp->e); | ||
| 682 | rsatmp->n->top=el/sizeof(BN_ULONG); | ||
| 683 | bn_fix_top(rsatmp->n); | ||
| 684 | /* create an EVP object: engine + rsa key */ | ||
| 685 | res = EVP_PKEY_new(); | ||
| 686 | EVP_PKEY_assign_RSA(res, rsatmp); | ||
| 687 | break; | ||
| 688 | #endif | ||
| 689 | |||
| 690 | #ifndef OPENSSL_NO_DSA | ||
| 691 | case 2:/*DSA*/ | ||
| 692 | /* set private/public external reference */ | ||
| 693 | dsatmp = DSA_new_method(e); | ||
| 694 | DSA_set_ex_data(dsatmp,dsaHndidx,hptr); | ||
| 695 | /*dsatmp->flags |= DSA_FLAG_EXT_PKEY;*/ | ||
| 696 | |||
| 697 | /* set public key*/ | ||
| 698 | dsatmp->pub_key = BN_new(); | ||
| 699 | dsatmp->p = BN_new(); | ||
| 700 | dsatmp->q = BN_new(); | ||
| 701 | dsatmp->g = BN_new(); | ||
| 702 | bn_expand2(dsatmp->pub_key, el/sizeof(BN_ULONG)); | ||
| 703 | bn_expand2(dsatmp->p, el/sizeof(BN_ULONG)); | ||
| 704 | bn_expand2(dsatmp->q, 20/sizeof(BN_ULONG)); | ||
| 705 | bn_expand2(dsatmp->g, el/sizeof(BN_ULONG)); | ||
| 706 | if (!dsatmp->pub_key || dsatmp->pub_key->dmax!=(int)(el/sizeof(BN_ULONG))|| | ||
| 707 | !dsatmp->p || dsatmp->p->dmax!=(int)(el/sizeof(BN_ULONG)) || | ||
| 708 | !dsatmp->q || dsatmp->q->dmax!=20/sizeof(BN_ULONG) || | ||
| 709 | !dsatmp->g || dsatmp->g->dmax!=(int)(el/sizeof(BN_ULONG))) | ||
| 710 | goto err; | ||
| 711 | |||
| 712 | ret=p_surewarehk_Load_Dsa_Pubkey(msg,key_id,el, | ||
| 713 | (unsigned long *)dsatmp->pub_key->d, | ||
| 714 | (unsigned long *)dsatmp->p->d, | ||
| 715 | (unsigned long *)dsatmp->q->d, | ||
| 716 | (unsigned long *)dsatmp->g->d); | ||
| 717 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ret); | ||
| 718 | if (ret!=1) | ||
| 719 | { | ||
| 720 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY); | ||
| 721 | goto err; | ||
| 722 | } | ||
| 723 | /* set parameters */ | ||
| 724 | /* normalise pubkey and parameters in case of */ | ||
| 725 | dsatmp->pub_key->top=el/sizeof(BN_ULONG); | ||
| 726 | bn_fix_top(dsatmp->pub_key); | ||
| 727 | dsatmp->p->top=el/sizeof(BN_ULONG); | ||
| 728 | bn_fix_top(dsatmp->p); | ||
| 729 | dsatmp->q->top=20/sizeof(BN_ULONG); | ||
| 730 | bn_fix_top(dsatmp->q); | ||
| 731 | dsatmp->g->top=el/sizeof(BN_ULONG); | ||
| 732 | bn_fix_top(dsatmp->g); | ||
| 733 | |||
| 734 | /* create an EVP object: engine + rsa key */ | ||
| 735 | res = EVP_PKEY_new(); | ||
| 736 | EVP_PKEY_assign_DSA(res, dsatmp); | ||
| 737 | break; | ||
| 738 | #endif | ||
| 739 | |||
| 740 | default: | ||
| 741 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PRIVATE_KEY); | ||
| 742 | goto err; | ||
| 743 | } | ||
| 744 | return res; | ||
| 745 | err: | ||
| 746 | if (res) | ||
| 747 | EVP_PKEY_free(res); | ||
| 748 | #ifndef OPENSSL_NO_RSA | ||
| 749 | if (rsatmp) | ||
| 750 | RSA_free(rsatmp); | ||
| 751 | #endif | ||
| 752 | #ifndef OPENSSL_NO_DSA | ||
| 753 | if (dsatmp) | ||
| 754 | DSA_free(dsatmp); | ||
| 755 | #endif | ||
| 756 | return NULL; | ||
| 757 | } | ||
| 758 | |||
| 759 | static EVP_PKEY *surewarehk_load_privkey(ENGINE *e, const char *key_id, | ||
| 760 | UI_METHOD *ui_method, void *callback_data) | ||
| 761 | { | ||
| 762 | EVP_PKEY *res = NULL; | ||
| 763 | int ret=0; | ||
| 764 | unsigned long el=0; | ||
| 765 | char *hptr=NULL; | ||
| 766 | char keytype=0; | ||
| 767 | char msg[64]="ENGINE_load_privkey"; | ||
| 768 | |||
| 769 | if(!p_surewarehk_Load_Privkey) | ||
| 770 | { | ||
| 771 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_NOT_INITIALISED); | ||
| 772 | } | ||
| 773 | else | ||
| 774 | { | ||
| 775 | ret=p_surewarehk_Load_Privkey(msg,key_id,&hptr,&el,&keytype); | ||
| 776 | if (ret!=1) | ||
| 777 | { | ||
| 778 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PRIVATE_KEY); | ||
| 779 | ERR_add_error_data(1,msg); | ||
| 780 | } | ||
| 781 | else | ||
| 782 | res=sureware_load_public(e,key_id,hptr,el,keytype); | ||
| 783 | } | ||
| 784 | return res; | ||
| 785 | } | ||
| 786 | |||
| 787 | static EVP_PKEY *surewarehk_load_pubkey(ENGINE *e, const char *key_id, | ||
| 788 | UI_METHOD *ui_method, void *callback_data) | ||
| 789 | { | ||
| 790 | EVP_PKEY *res = NULL; | ||
| 791 | int ret=0; | ||
| 792 | unsigned long el=0; | ||
| 793 | char *hptr=NULL; | ||
| 794 | char keytype=0; | ||
| 795 | char msg[64]="ENGINE_load_pubkey"; | ||
| 796 | |||
| 797 | if(!p_surewarehk_Info_Pubkey) | ||
| 798 | { | ||
| 799 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ENGINE_R_NOT_INITIALISED); | ||
| 800 | } | ||
| 801 | else | ||
| 802 | { | ||
| 803 | /* call once to identify if DSA or RSA */ | ||
| 804 | ret=p_surewarehk_Info_Pubkey(msg,key_id,&el,&keytype); | ||
| 805 | if (ret!=1) | ||
| 806 | { | ||
| 807 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY); | ||
| 808 | ERR_add_error_data(1,msg); | ||
| 809 | } | ||
| 810 | else | ||
| 811 | res=sureware_load_public(e,key_id,hptr,el,keytype); | ||
| 812 | } | ||
| 813 | return res; | ||
| 814 | } | ||
| 815 | |||
| 816 | /* This cleans up an RSA/DSA KM key(do not destroy the key into the hardware) | ||
| 817 | , called when ex_data is freed */ | ||
| 818 | static void surewarehk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
| 819 | int idx,long argl, void *argp) | ||
| 820 | { | ||
| 821 | if(!p_surewarehk_Free) | ||
| 822 | { | ||
| 823 | SUREWAREerr(SUREWARE_F_SUREWAREHK_EX_FREE,ENGINE_R_NOT_INITIALISED); | ||
| 824 | } | ||
| 825 | else | ||
| 826 | p_surewarehk_Free((char *)item,0); | ||
| 827 | } | ||
| 828 | |||
| 829 | #if 0 | ||
| 830 | /* This cleans up an DH KM key (destroys the key into hardware), | ||
| 831 | called when ex_data is freed */ | ||
| 832 | static void surewarehk_dh_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
| 833 | int idx,long argl, void *argp) | ||
| 834 | { | ||
| 835 | if(!p_surewarehk_Free) | ||
| 836 | { | ||
| 837 | SUREWAREerr(SUREWARE_F_SUREWAREHK_EX_FREE,ENGINE_R_NOT_INITIALISED); | ||
| 838 | } | ||
| 839 | else | ||
| 840 | p_surewarehk_Free((char *)item,1); | ||
| 841 | } | ||
| 842 | #endif | ||
| 843 | |||
| 844 | /* | ||
| 845 | * return number of decrypted bytes | ||
| 846 | */ | ||
| 847 | #ifndef OPENSSL_NO_RSA | ||
| 848 | static int surewarehk_rsa_priv_dec(int flen,const unsigned char *from,unsigned char *to, | ||
| 849 | RSA *rsa,int padding) | ||
| 850 | { | ||
| 851 | int ret=0,tlen; | ||
| 852 | char *buf=NULL,*hptr=NULL; | ||
| 853 | char msg[64]="ENGINE_rsa_priv_dec"; | ||
| 854 | if (!p_surewarehk_Rsa_Priv_Dec) | ||
| 855 | { | ||
| 856 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ENGINE_R_NOT_INITIALISED); | ||
| 857 | } | ||
| 858 | /* extract ref to private key */ | ||
| 859 | else if (!(hptr=RSA_get_ex_data(rsa, rsaHndidx))) | ||
| 860 | { | ||
| 861 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,SUREWARE_R_MISSING_KEY_COMPONENTS); | ||
| 862 | goto err; | ||
| 863 | } | ||
| 864 | /* analyse what padding we can do into the hardware */ | ||
| 865 | if (padding==RSA_PKCS1_PADDING) | ||
| 866 | { | ||
| 867 | /* do it one shot */ | ||
| 868 | ret=p_surewarehk_Rsa_Priv_Dec(msg,flen,(unsigned char *)from,&tlen,to,hptr,SUREWARE_PKCS1_PAD); | ||
| 869 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ret); | ||
| 870 | if (ret!=1) | ||
| 871 | goto err; | ||
| 872 | ret=tlen; | ||
| 873 | } | ||
| 874 | else /* do with no padding into hardware */ | ||
| 875 | { | ||
| 876 | ret=p_surewarehk_Rsa_Priv_Dec(msg,flen,(unsigned char *)from,&tlen,to,hptr,SUREWARE_NO_PAD); | ||
| 877 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ret); | ||
| 878 | if (ret!=1) | ||
| 879 | goto err; | ||
| 880 | /* intermediate buffer for padding */ | ||
| 881 | if ((buf=OPENSSL_malloc(tlen)) == NULL) | ||
| 882 | { | ||
| 883 | RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ERR_R_MALLOC_FAILURE); | ||
| 884 | goto err; | ||
| 885 | } | ||
| 886 | memcpy(buf,to,tlen);/* transfert to into buf */ | ||
| 887 | switch (padding) /* check padding in software */ | ||
| 888 | { | ||
| 889 | #ifndef OPENSSL_NO_SHA | ||
| 890 | case RSA_PKCS1_OAEP_PADDING: | ||
| 891 | ret=RSA_padding_check_PKCS1_OAEP(to,tlen,(unsigned char *)buf,tlen,tlen,NULL,0); | ||
| 892 | break; | ||
| 893 | #endif | ||
| 894 | case RSA_SSLV23_PADDING: | ||
| 895 | ret=RSA_padding_check_SSLv23(to,tlen,(unsigned char *)buf,flen,tlen); | ||
| 896 | break; | ||
| 897 | case RSA_NO_PADDING: | ||
| 898 | ret=RSA_padding_check_none(to,tlen,(unsigned char *)buf,flen,tlen); | ||
| 899 | break; | ||
| 900 | default: | ||
| 901 | RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,RSA_R_UNKNOWN_PADDING_TYPE); | ||
| 902 | goto err; | ||
| 903 | } | ||
| 904 | if (ret < 0) | ||
| 905 | RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,RSA_R_PADDING_CHECK_FAILED); | ||
| 906 | } | ||
| 907 | err: | ||
| 908 | if (buf) | ||
| 909 | { | ||
| 910 | OPENSSL_cleanse(buf,tlen); | ||
| 911 | OPENSSL_free(buf); | ||
| 912 | } | ||
| 913 | return ret; | ||
| 914 | } | ||
| 915 | |||
| 916 | /* | ||
| 917 | * Does what OpenSSL rsa_priv_enc does. | ||
| 918 | */ | ||
| 919 | static int surewarehk_rsa_sign(int flen,const unsigned char *from,unsigned char *to, | ||
| 920 | RSA *rsa,int padding) | ||
| 921 | { | ||
| 922 | int ret=0,tlen; | ||
| 923 | char *hptr=NULL; | ||
| 924 | char msg[64]="ENGINE_rsa_sign"; | ||
| 925 | if (!p_surewarehk_Rsa_Sign) | ||
| 926 | { | ||
| 927 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,ENGINE_R_NOT_INITIALISED); | ||
| 928 | } | ||
| 929 | /* extract ref to private key */ | ||
| 930 | else if (!(hptr=RSA_get_ex_data(rsa, rsaHndidx))) | ||
| 931 | { | ||
| 932 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,SUREWARE_R_MISSING_KEY_COMPONENTS); | ||
| 933 | } | ||
| 934 | else | ||
| 935 | { | ||
| 936 | switch (padding) | ||
| 937 | { | ||
| 938 | case RSA_PKCS1_PADDING: /* do it in one shot */ | ||
| 939 | ret=p_surewarehk_Rsa_Sign(msg,flen,(unsigned char *)from,&tlen,to,hptr,SUREWARE_PKCS1_PAD); | ||
| 940 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,ret); | ||
| 941 | break; | ||
| 942 | case RSA_NO_PADDING: | ||
| 943 | default: | ||
| 944 | RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,RSA_R_UNKNOWN_PADDING_TYPE); | ||
| 945 | } | ||
| 946 | } | ||
| 947 | return ret==1 ? tlen : ret; | ||
| 948 | } | ||
| 949 | |||
| 950 | #endif | ||
| 951 | |||
| 952 | #ifndef OPENSSL_NO_DSA | ||
| 953 | /* DSA sign and verify */ | ||
| 954 | static DSA_SIG * surewarehk_dsa_do_sign(const unsigned char *from, int flen, DSA *dsa) | ||
| 955 | { | ||
| 956 | int ret=0; | ||
| 957 | char *hptr=NULL; | ||
| 958 | DSA_SIG *psign=NULL; | ||
| 959 | char msg[64]="ENGINE_dsa_do_sign"; | ||
| 960 | if (!p_surewarehk_Dsa_Sign) | ||
| 961 | { | ||
| 962 | SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ENGINE_R_NOT_INITIALISED); | ||
| 963 | } | ||
| 964 | /* extract ref to private key */ | ||
| 965 | else if (!(hptr=DSA_get_ex_data(dsa, dsaHndidx))) | ||
| 966 | { | ||
| 967 | SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,SUREWARE_R_MISSING_KEY_COMPONENTS); | ||
| 968 | } | ||
| 969 | else | ||
| 970 | { | ||
| 971 | if((psign = DSA_SIG_new()) == NULL) | ||
| 972 | { | ||
| 973 | SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ERR_R_MALLOC_FAILURE); | ||
| 974 | goto err; | ||
| 975 | } | ||
| 976 | psign->r=BN_new(); | ||
| 977 | psign->s=BN_new(); | ||
| 978 | bn_expand2(psign->r, 20/sizeof(BN_ULONG)); | ||
| 979 | bn_expand2(psign->s, 20/sizeof(BN_ULONG)); | ||
| 980 | if (!psign->r || psign->r->dmax!=20/sizeof(BN_ULONG) || | ||
| 981 | !psign->s || psign->s->dmax!=20/sizeof(BN_ULONG)) | ||
| 982 | goto err; | ||
| 983 | ret=p_surewarehk_Dsa_Sign(msg,flen,from, | ||
| 984 | (unsigned long *)psign->r->d, | ||
| 985 | (unsigned long *)psign->s->d, | ||
| 986 | hptr); | ||
| 987 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ret); | ||
| 988 | } | ||
| 989 | psign->r->top=20/sizeof(BN_ULONG); | ||
| 990 | bn_fix_top(psign->r); | ||
| 991 | psign->s->top=20/sizeof(BN_ULONG); | ||
| 992 | bn_fix_top(psign->s); | ||
| 993 | |||
| 994 | err: | ||
| 995 | if (psign) | ||
| 996 | { | ||
| 997 | DSA_SIG_free(psign); | ||
| 998 | psign=NULL; | ||
| 999 | } | ||
| 1000 | return psign; | ||
| 1001 | } | ||
| 1002 | #endif | ||
| 1003 | |||
| 1004 | static int surewarehk_modexp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 1005 | const BIGNUM *m, BN_CTX *ctx) | ||
| 1006 | { | ||
| 1007 | int ret=0; | ||
| 1008 | char msg[64]="ENGINE_modexp"; | ||
| 1009 | if (!p_surewarehk_Mod_Exp) | ||
| 1010 | { | ||
| 1011 | SUREWAREerr(SUREWARE_F_SUREWAREHK_MOD_EXP,ENGINE_R_NOT_INITIALISED); | ||
| 1012 | } | ||
| 1013 | else | ||
| 1014 | { | ||
| 1015 | bn_expand2(r,m->top); | ||
| 1016 | if (r && r->dmax==m->top) | ||
| 1017 | { | ||
| 1018 | /* do it*/ | ||
| 1019 | ret=p_surewarehk_Mod_Exp(msg, | ||
| 1020 | m->top*sizeof(BN_ULONG), | ||
| 1021 | (unsigned long *)m->d, | ||
| 1022 | p->top*sizeof(BN_ULONG), | ||
| 1023 | (unsigned long *)p->d, | ||
| 1024 | a->top*sizeof(BN_ULONG), | ||
| 1025 | (unsigned long *)a->d, | ||
| 1026 | (unsigned long *)r->d); | ||
| 1027 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_MOD_EXP,ret); | ||
| 1028 | if (ret==1) | ||
| 1029 | { | ||
| 1030 | /* normalise result */ | ||
| 1031 | r->top=m->top; | ||
| 1032 | bn_fix_top(r); | ||
| 1033 | } | ||
| 1034 | } | ||
| 1035 | } | ||
| 1036 | return ret; | ||
| 1037 | } | ||
| 1038 | #endif /* !OPENSSL_NO_HW_SureWare */ | ||
| 1039 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_ubsec.c b/src/lib/libcrypto/engine/hw_ubsec.c deleted file mode 100644 index 8fb834af31..0000000000 --- a/src/lib/libcrypto/engine/hw_ubsec.c +++ /dev/null | |||
| @@ -1,1061 +0,0 @@ | |||
| 1 | /* crypto/engine/hw_ubsec.c */ | ||
| 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | * | ||
| 5 | * Cloned shamelessly by Joe Tardo. | ||
| 6 | */ | ||
| 7 | /* ==================================================================== | ||
| 8 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
| 9 | * | ||
| 10 | * Redistribution and use in source and binary forms, with or without | ||
| 11 | * modification, are permitted provided that the following conditions | ||
| 12 | * are met: | ||
| 13 | * | ||
| 14 | * 1. Redistributions of source code must retain the above copyright | ||
| 15 | * notice, this list of conditions and the following disclaimer. | ||
| 16 | * | ||
| 17 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 18 | * notice, this list of conditions and the following disclaimer in | ||
| 19 | * the documentation and/or other materials provided with the | ||
| 20 | * distribution. | ||
| 21 | * | ||
| 22 | * 3. All advertising materials mentioning features or use of this | ||
| 23 | * software must display the following acknowledgment: | ||
| 24 | * "This product includes software developed by the OpenSSL Project | ||
| 25 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 26 | * | ||
| 27 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 28 | * endorse or promote products derived from this software without | ||
| 29 | * prior written permission. For written permission, please contact | ||
| 30 | * licensing@OpenSSL.org. | ||
| 31 | * | ||
| 32 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 33 | * nor may "OpenSSL" appear in their names without prior written | ||
| 34 | * permission of the OpenSSL Project. | ||
| 35 | * | ||
| 36 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 37 | * acknowledgment: | ||
| 38 | * "This product includes software developed by the OpenSSL Project | ||
| 39 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 42 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 44 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 45 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 46 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 47 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 48 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 49 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 50 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 51 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 52 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 53 | * ==================================================================== | ||
| 54 | * | ||
| 55 | * This product includes cryptographic software written by Eric Young | ||
| 56 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 57 | * Hudson (tjh@cryptsoft.com). | ||
| 58 | * | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <openssl/crypto.h> | ||
| 63 | #include "cryptlib.h" | ||
| 64 | #include <openssl/dso.h> | ||
| 65 | #include <openssl/engine.h> | ||
| 66 | |||
| 67 | #ifndef OPENSSL_NO_HW | ||
| 68 | #ifndef OPENSSL_NO_HW_UBSEC | ||
| 69 | |||
| 70 | #ifdef FLAT_INC | ||
| 71 | #include "hw_ubsec.h" | ||
| 72 | #else | ||
| 73 | #include "vendor_defns/hw_ubsec.h" | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #define UBSEC_LIB_NAME "ubsec engine" | ||
| 77 | #include "hw_ubsec_err.c" | ||
| 78 | |||
| 79 | #define FAIL_TO_SOFTWARE -15 | ||
| 80 | |||
| 81 | static int ubsec_destroy(ENGINE *e); | ||
| 82 | static int ubsec_init(ENGINE *e); | ||
| 83 | static int ubsec_finish(ENGINE *e); | ||
| 84 | static int ubsec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
| 85 | static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 86 | const BIGNUM *m, BN_CTX *ctx); | ||
| 87 | static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 88 | const BIGNUM *q, const BIGNUM *dp, | ||
| 89 | const BIGNUM *dq, const BIGNUM *qinv, BN_CTX *ctx); | ||
| 90 | #ifndef OPENSSL_NO_RSA | ||
| 91 | static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa); | ||
| 92 | #endif | ||
| 93 | static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 94 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 95 | #ifndef OPENSSL_NO_DSA | ||
| 96 | #ifdef NOT_USED | ||
| 97 | static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
| 98 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
| 99 | BN_CTX *ctx, BN_MONT_CTX *in_mont); | ||
| 100 | static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
| 101 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 102 | BN_MONT_CTX *m_ctx); | ||
| 103 | #endif | ||
| 104 | static DSA_SIG *ubsec_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | ||
| 105 | static int ubsec_dsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 106 | DSA_SIG *sig, DSA *dsa); | ||
| 107 | #endif | ||
| 108 | #ifndef OPENSSL_NO_DH | ||
| 109 | static int ubsec_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 110 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 111 | BN_MONT_CTX *m_ctx); | ||
| 112 | static int ubsec_dh_compute_key(unsigned char *key,const BIGNUM *pub_key,DH *dh); | ||
| 113 | static int ubsec_dh_generate_key(DH *dh); | ||
| 114 | #endif | ||
| 115 | |||
| 116 | #ifdef NOT_USED | ||
| 117 | static int ubsec_rand_bytes(unsigned char *buf, int num); | ||
| 118 | static int ubsec_rand_status(void); | ||
| 119 | #endif | ||
| 120 | |||
| 121 | #define UBSEC_CMD_SO_PATH ENGINE_CMD_BASE | ||
| 122 | static const ENGINE_CMD_DEFN ubsec_cmd_defns[] = { | ||
| 123 | {UBSEC_CMD_SO_PATH, | ||
| 124 | "SO_PATH", | ||
| 125 | "Specifies the path to the 'ubsec' shared library", | ||
| 126 | ENGINE_CMD_FLAG_STRING}, | ||
| 127 | {0, NULL, NULL, 0} | ||
| 128 | }; | ||
| 129 | |||
| 130 | #ifndef OPENSSL_NO_RSA | ||
| 131 | /* Our internal RSA_METHOD that we provide pointers to */ | ||
| 132 | static RSA_METHOD ubsec_rsa = | ||
| 133 | { | ||
| 134 | "UBSEC RSA method", | ||
| 135 | NULL, | ||
| 136 | NULL, | ||
| 137 | NULL, | ||
| 138 | NULL, | ||
| 139 | ubsec_rsa_mod_exp, | ||
| 140 | ubsec_mod_exp_mont, | ||
| 141 | NULL, | ||
| 142 | NULL, | ||
| 143 | 0, | ||
| 144 | NULL, | ||
| 145 | NULL, | ||
| 146 | NULL | ||
| 147 | }; | ||
| 148 | #endif | ||
| 149 | |||
| 150 | #ifndef OPENSSL_NO_DSA | ||
| 151 | /* Our internal DSA_METHOD that we provide pointers to */ | ||
| 152 | static DSA_METHOD ubsec_dsa = | ||
| 153 | { | ||
| 154 | "UBSEC DSA method", | ||
| 155 | ubsec_dsa_do_sign, /* dsa_do_sign */ | ||
| 156 | NULL, /* dsa_sign_setup */ | ||
| 157 | ubsec_dsa_verify, /* dsa_do_verify */ | ||
| 158 | NULL, /* ubsec_dsa_mod_exp */ /* dsa_mod_exp */ | ||
| 159 | NULL, /* ubsec_mod_exp_dsa */ /* bn_mod_exp */ | ||
| 160 | NULL, /* init */ | ||
| 161 | NULL, /* finish */ | ||
| 162 | 0, /* flags */ | ||
| 163 | NULL /* app_data */ | ||
| 164 | }; | ||
| 165 | #endif | ||
| 166 | |||
| 167 | #ifndef OPENSSL_NO_DH | ||
| 168 | /* Our internal DH_METHOD that we provide pointers to */ | ||
| 169 | static DH_METHOD ubsec_dh = | ||
| 170 | { | ||
| 171 | "UBSEC DH method", | ||
| 172 | ubsec_dh_generate_key, | ||
| 173 | ubsec_dh_compute_key, | ||
| 174 | ubsec_mod_exp_dh, | ||
| 175 | NULL, | ||
| 176 | NULL, | ||
| 177 | 0, | ||
| 178 | NULL | ||
| 179 | }; | ||
| 180 | #endif | ||
| 181 | |||
| 182 | /* Constants used when creating the ENGINE */ | ||
| 183 | static const char *engine_ubsec_id = "ubsec"; | ||
| 184 | static const char *engine_ubsec_name = "UBSEC hardware engine support"; | ||
| 185 | |||
| 186 | /* This internal function is used by ENGINE_ubsec() and possibly by the | ||
| 187 | * "dynamic" ENGINE support too */ | ||
| 188 | static int bind_helper(ENGINE *e) | ||
| 189 | { | ||
| 190 | #ifndef OPENSSL_NO_RSA | ||
| 191 | const RSA_METHOD *meth1; | ||
| 192 | #endif | ||
| 193 | #ifndef OPENSSL_NO_DH | ||
| 194 | #ifndef HAVE_UBSEC_DH | ||
| 195 | const DH_METHOD *meth3; | ||
| 196 | #endif /* HAVE_UBSEC_DH */ | ||
| 197 | #endif | ||
| 198 | if(!ENGINE_set_id(e, engine_ubsec_id) || | ||
| 199 | !ENGINE_set_name(e, engine_ubsec_name) || | ||
| 200 | #ifndef OPENSSL_NO_RSA | ||
| 201 | !ENGINE_set_RSA(e, &ubsec_rsa) || | ||
| 202 | #endif | ||
| 203 | #ifndef OPENSSL_NO_DSA | ||
| 204 | !ENGINE_set_DSA(e, &ubsec_dsa) || | ||
| 205 | #endif | ||
| 206 | #ifndef OPENSSL_NO_DH | ||
| 207 | !ENGINE_set_DH(e, &ubsec_dh) || | ||
| 208 | #endif | ||
| 209 | !ENGINE_set_destroy_function(e, ubsec_destroy) || | ||
| 210 | !ENGINE_set_init_function(e, ubsec_init) || | ||
| 211 | !ENGINE_set_finish_function(e, ubsec_finish) || | ||
| 212 | !ENGINE_set_ctrl_function(e, ubsec_ctrl) || | ||
| 213 | !ENGINE_set_cmd_defns(e, ubsec_cmd_defns)) | ||
| 214 | return 0; | ||
| 215 | |||
| 216 | #ifndef OPENSSL_NO_RSA | ||
| 217 | /* We know that the "PKCS1_SSLeay()" functions hook properly | ||
| 218 | * to the Broadcom-specific mod_exp and mod_exp_crt so we use | ||
| 219 | * those functions. NB: We don't use ENGINE_openssl() or | ||
| 220 | * anything "more generic" because something like the RSAref | ||
| 221 | * code may not hook properly, and if you own one of these | ||
| 222 | * cards then you have the right to do RSA operations on it | ||
| 223 | * anyway! */ | ||
| 224 | meth1 = RSA_PKCS1_SSLeay(); | ||
| 225 | ubsec_rsa.rsa_pub_enc = meth1->rsa_pub_enc; | ||
| 226 | ubsec_rsa.rsa_pub_dec = meth1->rsa_pub_dec; | ||
| 227 | ubsec_rsa.rsa_priv_enc = meth1->rsa_priv_enc; | ||
| 228 | ubsec_rsa.rsa_priv_dec = meth1->rsa_priv_dec; | ||
| 229 | #endif | ||
| 230 | |||
| 231 | #ifndef OPENSSL_NO_DH | ||
| 232 | #ifndef HAVE_UBSEC_DH | ||
| 233 | /* Much the same for Diffie-Hellman */ | ||
| 234 | meth3 = DH_OpenSSL(); | ||
| 235 | ubsec_dh.generate_key = meth3->generate_key; | ||
| 236 | ubsec_dh.compute_key = meth3->compute_key; | ||
| 237 | #endif /* HAVE_UBSEC_DH */ | ||
| 238 | #endif | ||
| 239 | |||
| 240 | /* Ensure the ubsec error handling is set up */ | ||
| 241 | ERR_load_UBSEC_strings(); | ||
| 242 | return 1; | ||
| 243 | } | ||
| 244 | |||
| 245 | #ifndef ENGINE_DYNAMIC_SUPPORT | ||
| 246 | static ENGINE *engine_ubsec(void) | ||
| 247 | { | ||
| 248 | ENGINE *ret = ENGINE_new(); | ||
| 249 | if(!ret) | ||
| 250 | return NULL; | ||
| 251 | if(!bind_helper(ret)) | ||
| 252 | { | ||
| 253 | ENGINE_free(ret); | ||
| 254 | return NULL; | ||
| 255 | } | ||
| 256 | return ret; | ||
| 257 | } | ||
| 258 | |||
| 259 | void ENGINE_load_ubsec(void) | ||
| 260 | { | ||
| 261 | /* Copied from eng_[openssl|dyn].c */ | ||
| 262 | ENGINE *toadd = engine_ubsec(); | ||
| 263 | if(!toadd) return; | ||
| 264 | ENGINE_add(toadd); | ||
| 265 | ENGINE_free(toadd); | ||
| 266 | ERR_clear_error(); | ||
| 267 | } | ||
| 268 | #endif | ||
| 269 | |||
| 270 | /* This is a process-global DSO handle used for loading and unloading | ||
| 271 | * the UBSEC library. NB: This is only set (or unset) during an | ||
| 272 | * init() or finish() call (reference counts permitting) and they're | ||
| 273 | * operating with global locks, so this should be thread-safe | ||
| 274 | * implicitly. */ | ||
| 275 | |||
| 276 | static DSO *ubsec_dso = NULL; | ||
| 277 | |||
| 278 | /* These are the function pointers that are (un)set when the library has | ||
| 279 | * successfully (un)loaded. */ | ||
| 280 | |||
| 281 | static t_UBSEC_ubsec_bytes_to_bits *p_UBSEC_ubsec_bytes_to_bits = NULL; | ||
| 282 | static t_UBSEC_ubsec_bits_to_bytes *p_UBSEC_ubsec_bits_to_bytes = NULL; | ||
| 283 | static t_UBSEC_ubsec_open *p_UBSEC_ubsec_open = NULL; | ||
| 284 | static t_UBSEC_ubsec_close *p_UBSEC_ubsec_close = NULL; | ||
| 285 | #ifndef OPENSSL_NO_DH | ||
| 286 | static t_UBSEC_diffie_hellman_generate_ioctl | ||
| 287 | *p_UBSEC_diffie_hellman_generate_ioctl = NULL; | ||
| 288 | static t_UBSEC_diffie_hellman_agree_ioctl *p_UBSEC_diffie_hellman_agree_ioctl = NULL; | ||
| 289 | #endif | ||
| 290 | /* #ifndef OPENSSL_NO_RSA */ | ||
| 291 | static t_UBSEC_rsa_mod_exp_ioctl *p_UBSEC_rsa_mod_exp_ioctl = NULL; | ||
| 292 | static t_UBSEC_rsa_mod_exp_crt_ioctl *p_UBSEC_rsa_mod_exp_crt_ioctl = NULL; | ||
| 293 | /* #endif */ | ||
| 294 | #ifndef OPENSSL_NO_DSA | ||
| 295 | static t_UBSEC_dsa_sign_ioctl *p_UBSEC_dsa_sign_ioctl = NULL; | ||
| 296 | static t_UBSEC_dsa_verify_ioctl *p_UBSEC_dsa_verify_ioctl = NULL; | ||
| 297 | #endif | ||
| 298 | static t_UBSEC_math_accelerate_ioctl *p_UBSEC_math_accelerate_ioctl = NULL; | ||
| 299 | static t_UBSEC_rng_ioctl *p_UBSEC_rng_ioctl = NULL; | ||
| 300 | static t_UBSEC_max_key_len_ioctl *p_UBSEC_max_key_len_ioctl = NULL; | ||
| 301 | |||
| 302 | static int max_key_len = 1024; /* ??? */ | ||
| 303 | |||
| 304 | /* | ||
| 305 | * These are the static string constants for the DSO file name and the function | ||
| 306 | * symbol names to bind to. | ||
| 307 | */ | ||
| 308 | |||
| 309 | static const char *UBSEC_LIBNAME = NULL; | ||
| 310 | static const char *get_UBSEC_LIBNAME(void) | ||
| 311 | { | ||
| 312 | if(UBSEC_LIBNAME) | ||
| 313 | return UBSEC_LIBNAME; | ||
| 314 | return "ubsec"; | ||
| 315 | } | ||
| 316 | static void free_UBSEC_LIBNAME(void) | ||
| 317 | { | ||
| 318 | if(UBSEC_LIBNAME) | ||
| 319 | OPENSSL_free((void*)UBSEC_LIBNAME); | ||
| 320 | UBSEC_LIBNAME = NULL; | ||
| 321 | } | ||
| 322 | static long set_UBSEC_LIBNAME(const char *name) | ||
| 323 | { | ||
| 324 | free_UBSEC_LIBNAME(); | ||
| 325 | return (((UBSEC_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0); | ||
| 326 | } | ||
| 327 | static const char *UBSEC_F1 = "ubsec_bytes_to_bits"; | ||
| 328 | static const char *UBSEC_F2 = "ubsec_bits_to_bytes"; | ||
| 329 | static const char *UBSEC_F3 = "ubsec_open"; | ||
| 330 | static const char *UBSEC_F4 = "ubsec_close"; | ||
| 331 | #ifndef OPENSSL_NO_DH | ||
| 332 | static const char *UBSEC_F5 = "diffie_hellman_generate_ioctl"; | ||
| 333 | static const char *UBSEC_F6 = "diffie_hellman_agree_ioctl"; | ||
| 334 | #endif | ||
| 335 | /* #ifndef OPENSSL_NO_RSA */ | ||
| 336 | static const char *UBSEC_F7 = "rsa_mod_exp_ioctl"; | ||
| 337 | static const char *UBSEC_F8 = "rsa_mod_exp_crt_ioctl"; | ||
| 338 | /* #endif */ | ||
| 339 | #ifndef OPENSSL_NO_DSA | ||
| 340 | static const char *UBSEC_F9 = "dsa_sign_ioctl"; | ||
| 341 | static const char *UBSEC_F10 = "dsa_verify_ioctl"; | ||
| 342 | #endif | ||
| 343 | static const char *UBSEC_F11 = "math_accelerate_ioctl"; | ||
| 344 | static const char *UBSEC_F12 = "rng_ioctl"; | ||
| 345 | static const char *UBSEC_F13 = "ubsec_max_key_len_ioctl"; | ||
| 346 | |||
| 347 | /* Destructor (complements the "ENGINE_ubsec()" constructor) */ | ||
| 348 | static int ubsec_destroy(ENGINE *e) | ||
| 349 | { | ||
| 350 | free_UBSEC_LIBNAME(); | ||
| 351 | ERR_unload_UBSEC_strings(); | ||
| 352 | return 1; | ||
| 353 | } | ||
| 354 | |||
| 355 | /* (de)initialisation functions. */ | ||
| 356 | static int ubsec_init(ENGINE *e) | ||
| 357 | { | ||
| 358 | t_UBSEC_ubsec_bytes_to_bits *p1; | ||
| 359 | t_UBSEC_ubsec_bits_to_bytes *p2; | ||
| 360 | t_UBSEC_ubsec_open *p3; | ||
| 361 | t_UBSEC_ubsec_close *p4; | ||
| 362 | #ifndef OPENSSL_NO_DH | ||
| 363 | t_UBSEC_diffie_hellman_generate_ioctl *p5; | ||
| 364 | t_UBSEC_diffie_hellman_agree_ioctl *p6; | ||
| 365 | #endif | ||
| 366 | /* #ifndef OPENSSL_NO_RSA */ | ||
| 367 | t_UBSEC_rsa_mod_exp_ioctl *p7; | ||
| 368 | t_UBSEC_rsa_mod_exp_crt_ioctl *p8; | ||
| 369 | /* #endif */ | ||
| 370 | #ifndef OPENSSL_NO_DSA | ||
| 371 | t_UBSEC_dsa_sign_ioctl *p9; | ||
| 372 | t_UBSEC_dsa_verify_ioctl *p10; | ||
| 373 | #endif | ||
| 374 | t_UBSEC_math_accelerate_ioctl *p11; | ||
| 375 | t_UBSEC_rng_ioctl *p12; | ||
| 376 | t_UBSEC_max_key_len_ioctl *p13; | ||
| 377 | int fd = 0; | ||
| 378 | |||
| 379 | if(ubsec_dso != NULL) | ||
| 380 | { | ||
| 381 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_ALREADY_LOADED); | ||
| 382 | goto err; | ||
| 383 | } | ||
| 384 | /* | ||
| 385 | * Attempt to load libubsec.so/ubsec.dll/whatever. | ||
| 386 | */ | ||
| 387 | ubsec_dso = DSO_load(NULL, get_UBSEC_LIBNAME(), NULL, 0); | ||
| 388 | if(ubsec_dso == NULL) | ||
| 389 | { | ||
| 390 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE); | ||
| 391 | goto err; | ||
| 392 | } | ||
| 393 | |||
| 394 | if ( | ||
| 395 | !(p1 = (t_UBSEC_ubsec_bytes_to_bits *) DSO_bind_func(ubsec_dso, UBSEC_F1)) || | ||
| 396 | !(p2 = (t_UBSEC_ubsec_bits_to_bytes *) DSO_bind_func(ubsec_dso, UBSEC_F2)) || | ||
| 397 | !(p3 = (t_UBSEC_ubsec_open *) DSO_bind_func(ubsec_dso, UBSEC_F3)) || | ||
| 398 | !(p4 = (t_UBSEC_ubsec_close *) DSO_bind_func(ubsec_dso, UBSEC_F4)) || | ||
| 399 | #ifndef OPENSSL_NO_DH | ||
| 400 | !(p5 = (t_UBSEC_diffie_hellman_generate_ioctl *) | ||
| 401 | DSO_bind_func(ubsec_dso, UBSEC_F5)) || | ||
| 402 | !(p6 = (t_UBSEC_diffie_hellman_agree_ioctl *) | ||
| 403 | DSO_bind_func(ubsec_dso, UBSEC_F6)) || | ||
| 404 | #endif | ||
| 405 | /* #ifndef OPENSSL_NO_RSA */ | ||
| 406 | !(p7 = (t_UBSEC_rsa_mod_exp_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F7)) || | ||
| 407 | !(p8 = (t_UBSEC_rsa_mod_exp_crt_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F8)) || | ||
| 408 | /* #endif */ | ||
| 409 | #ifndef OPENSSL_NO_DSA | ||
| 410 | !(p9 = (t_UBSEC_dsa_sign_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F9)) || | ||
| 411 | !(p10 = (t_UBSEC_dsa_verify_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F10)) || | ||
| 412 | #endif | ||
| 413 | !(p11 = (t_UBSEC_math_accelerate_ioctl *) | ||
| 414 | DSO_bind_func(ubsec_dso, UBSEC_F11)) || | ||
| 415 | !(p12 = (t_UBSEC_rng_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F12)) || | ||
| 416 | !(p13 = (t_UBSEC_max_key_len_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F13))) | ||
| 417 | { | ||
| 418 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE); | ||
| 419 | goto err; | ||
| 420 | } | ||
| 421 | |||
| 422 | /* Copy the pointers */ | ||
| 423 | p_UBSEC_ubsec_bytes_to_bits = p1; | ||
| 424 | p_UBSEC_ubsec_bits_to_bytes = p2; | ||
| 425 | p_UBSEC_ubsec_open = p3; | ||
| 426 | p_UBSEC_ubsec_close = p4; | ||
| 427 | #ifndef OPENSSL_NO_DH | ||
| 428 | p_UBSEC_diffie_hellman_generate_ioctl = p5; | ||
| 429 | p_UBSEC_diffie_hellman_agree_ioctl = p6; | ||
| 430 | #endif | ||
| 431 | #ifndef OPENSSL_NO_RSA | ||
| 432 | p_UBSEC_rsa_mod_exp_ioctl = p7; | ||
| 433 | p_UBSEC_rsa_mod_exp_crt_ioctl = p8; | ||
| 434 | #endif | ||
| 435 | #ifndef OPENSSL_NO_DSA | ||
| 436 | p_UBSEC_dsa_sign_ioctl = p9; | ||
| 437 | p_UBSEC_dsa_verify_ioctl = p10; | ||
| 438 | #endif | ||
| 439 | p_UBSEC_math_accelerate_ioctl = p11; | ||
| 440 | p_UBSEC_rng_ioctl = p12; | ||
| 441 | p_UBSEC_max_key_len_ioctl = p13; | ||
| 442 | |||
| 443 | /* Perform an open to see if there's actually any unit running. */ | ||
| 444 | if (((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) > 0) && (p_UBSEC_max_key_len_ioctl(fd, &max_key_len) == 0)) | ||
| 445 | { | ||
| 446 | p_UBSEC_ubsec_close(fd); | ||
| 447 | return 1; | ||
| 448 | } | ||
| 449 | else | ||
| 450 | { | ||
| 451 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
| 452 | } | ||
| 453 | |||
| 454 | err: | ||
| 455 | if(ubsec_dso) | ||
| 456 | DSO_free(ubsec_dso); | ||
| 457 | ubsec_dso = NULL; | ||
| 458 | p_UBSEC_ubsec_bytes_to_bits = NULL; | ||
| 459 | p_UBSEC_ubsec_bits_to_bytes = NULL; | ||
| 460 | p_UBSEC_ubsec_open = NULL; | ||
| 461 | p_UBSEC_ubsec_close = NULL; | ||
| 462 | #ifndef OPENSSL_NO_DH | ||
| 463 | p_UBSEC_diffie_hellman_generate_ioctl = NULL; | ||
| 464 | p_UBSEC_diffie_hellman_agree_ioctl = NULL; | ||
| 465 | #endif | ||
| 466 | #ifndef OPENSSL_NO_RSA | ||
| 467 | p_UBSEC_rsa_mod_exp_ioctl = NULL; | ||
| 468 | p_UBSEC_rsa_mod_exp_crt_ioctl = NULL; | ||
| 469 | #endif | ||
| 470 | #ifndef OPENSSL_NO_DSA | ||
| 471 | p_UBSEC_dsa_sign_ioctl = NULL; | ||
| 472 | p_UBSEC_dsa_verify_ioctl = NULL; | ||
| 473 | #endif | ||
| 474 | p_UBSEC_math_accelerate_ioctl = NULL; | ||
| 475 | p_UBSEC_rng_ioctl = NULL; | ||
| 476 | p_UBSEC_max_key_len_ioctl = NULL; | ||
| 477 | |||
| 478 | return 0; | ||
| 479 | } | ||
| 480 | |||
| 481 | static int ubsec_finish(ENGINE *e) | ||
| 482 | { | ||
| 483 | free_UBSEC_LIBNAME(); | ||
| 484 | if(ubsec_dso == NULL) | ||
| 485 | { | ||
| 486 | UBSECerr(UBSEC_F_UBSEC_FINISH, UBSEC_R_NOT_LOADED); | ||
| 487 | return 0; | ||
| 488 | } | ||
| 489 | if(!DSO_free(ubsec_dso)) | ||
| 490 | { | ||
| 491 | UBSECerr(UBSEC_F_UBSEC_FINISH, UBSEC_R_DSO_FAILURE); | ||
| 492 | return 0; | ||
| 493 | } | ||
| 494 | ubsec_dso = NULL; | ||
| 495 | p_UBSEC_ubsec_bytes_to_bits = NULL; | ||
| 496 | p_UBSEC_ubsec_bits_to_bytes = NULL; | ||
| 497 | p_UBSEC_ubsec_open = NULL; | ||
| 498 | p_UBSEC_ubsec_close = NULL; | ||
| 499 | #ifndef OPENSSL_NO_DH | ||
| 500 | p_UBSEC_diffie_hellman_generate_ioctl = NULL; | ||
| 501 | p_UBSEC_diffie_hellman_agree_ioctl = NULL; | ||
| 502 | #endif | ||
| 503 | #ifndef OPENSSL_NO_RSA | ||
| 504 | p_UBSEC_rsa_mod_exp_ioctl = NULL; | ||
| 505 | p_UBSEC_rsa_mod_exp_crt_ioctl = NULL; | ||
| 506 | #endif | ||
| 507 | #ifndef OPENSSL_NO_DSA | ||
| 508 | p_UBSEC_dsa_sign_ioctl = NULL; | ||
| 509 | p_UBSEC_dsa_verify_ioctl = NULL; | ||
| 510 | #endif | ||
| 511 | p_UBSEC_math_accelerate_ioctl = NULL; | ||
| 512 | p_UBSEC_rng_ioctl = NULL; | ||
| 513 | p_UBSEC_max_key_len_ioctl = NULL; | ||
| 514 | return 1; | ||
| 515 | } | ||
| 516 | |||
| 517 | static int ubsec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
| 518 | { | ||
| 519 | int initialised = ((ubsec_dso == NULL) ? 0 : 1); | ||
| 520 | switch(cmd) | ||
| 521 | { | ||
| 522 | case UBSEC_CMD_SO_PATH: | ||
| 523 | if(p == NULL) | ||
| 524 | { | ||
| 525 | UBSECerr(UBSEC_F_UBSEC_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
| 526 | return 0; | ||
| 527 | } | ||
| 528 | if(initialised) | ||
| 529 | { | ||
| 530 | UBSECerr(UBSEC_F_UBSEC_CTRL,UBSEC_R_ALREADY_LOADED); | ||
| 531 | return 0; | ||
| 532 | } | ||
| 533 | return set_UBSEC_LIBNAME((const char *)p); | ||
| 534 | default: | ||
| 535 | break; | ||
| 536 | } | ||
| 537 | UBSECerr(UBSEC_F_UBSEC_CTRL,UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
| 538 | return 0; | ||
| 539 | } | ||
| 540 | |||
| 541 | static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 542 | const BIGNUM *m, BN_CTX *ctx) | ||
| 543 | { | ||
| 544 | int y_len = 0; | ||
| 545 | int fd; | ||
| 546 | |||
| 547 | if(ubsec_dso == NULL) | ||
| 548 | { | ||
| 549 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_NOT_LOADED); | ||
| 550 | return 0; | ||
| 551 | } | ||
| 552 | |||
| 553 | /* Check if hardware can't handle this argument. */ | ||
| 554 | y_len = BN_num_bits(m); | ||
| 555 | if (y_len > max_key_len) { | ||
| 556 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
| 557 | return BN_mod_exp(r, a, p, m, ctx); | ||
| 558 | } | ||
| 559 | |||
| 560 | if(!bn_wexpand(r, m->top)) | ||
| 561 | { | ||
| 562 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_BN_EXPAND_FAIL); | ||
| 563 | return 0; | ||
| 564 | } | ||
| 565 | |||
| 566 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) { | ||
| 567 | fd = 0; | ||
| 568 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
| 569 | return BN_mod_exp(r, a, p, m, ctx); | ||
| 570 | } | ||
| 571 | |||
| 572 | if (p_UBSEC_rsa_mod_exp_ioctl(fd, (unsigned char *)a->d, BN_num_bits(a), | ||
| 573 | (unsigned char *)m->d, BN_num_bits(m), (unsigned char *)p->d, | ||
| 574 | BN_num_bits(p), (unsigned char *)r->d, &y_len) != 0) | ||
| 575 | { | ||
| 576 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_REQUEST_FAILED); | ||
| 577 | p_UBSEC_ubsec_close(fd); | ||
| 578 | |||
| 579 | return BN_mod_exp(r, a, p, m, ctx); | ||
| 580 | } | ||
| 581 | |||
| 582 | p_UBSEC_ubsec_close(fd); | ||
| 583 | |||
| 584 | r->top = (BN_num_bits(m)+BN_BITS2-1)/BN_BITS2; | ||
| 585 | return 1; | ||
| 586 | } | ||
| 587 | |||
| 588 | #ifndef OPENSSL_NO_RSA | ||
| 589 | static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | ||
| 590 | { | ||
| 591 | BN_CTX *ctx; | ||
| 592 | int to_return = 0; | ||
| 593 | |||
| 594 | if((ctx = BN_CTX_new()) == NULL) | ||
| 595 | goto err; | ||
| 596 | |||
| 597 | if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) | ||
| 598 | { | ||
| 599 | UBSECerr(UBSEC_F_UBSEC_RSA_MOD_EXP, UBSEC_R_MISSING_KEY_COMPONENTS); | ||
| 600 | goto err; | ||
| 601 | } | ||
| 602 | |||
| 603 | to_return = ubsec_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1, | ||
| 604 | rsa->dmq1, rsa->iqmp, ctx); | ||
| 605 | if (to_return == FAIL_TO_SOFTWARE) | ||
| 606 | { | ||
| 607 | /* | ||
| 608 | * Do in software as hardware failed. | ||
| 609 | */ | ||
| 610 | const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 611 | to_return = (*meth->rsa_mod_exp)(r0, I, rsa); | ||
| 612 | } | ||
| 613 | err: | ||
| 614 | if(ctx) | ||
| 615 | BN_CTX_free(ctx); | ||
| 616 | return to_return; | ||
| 617 | } | ||
| 618 | #endif | ||
| 619 | |||
| 620 | static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 621 | const BIGNUM *q, const BIGNUM *dp, | ||
| 622 | const BIGNUM *dq, const BIGNUM *qinv, BN_CTX *ctx) | ||
| 623 | { | ||
| 624 | int y_len, | ||
| 625 | m_len, | ||
| 626 | fd; | ||
| 627 | |||
| 628 | m_len = BN_num_bytes(p) + BN_num_bytes(q) + 1; | ||
| 629 | y_len = BN_num_bits(p) + BN_num_bits(q); | ||
| 630 | |||
| 631 | /* Check if hardware can't handle this argument. */ | ||
| 632 | if (y_len > max_key_len) { | ||
| 633 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
| 634 | return FAIL_TO_SOFTWARE; | ||
| 635 | } | ||
| 636 | |||
| 637 | if (!bn_wexpand(r, p->top + q->top + 1)) { | ||
| 638 | UBSECerr(UBSEC_F_UBSEC_RSA_MOD_EXP_CRT, UBSEC_R_BN_EXPAND_FAIL); | ||
| 639 | return 0; | ||
| 640 | } | ||
| 641 | |||
| 642 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) { | ||
| 643 | fd = 0; | ||
| 644 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
| 645 | return FAIL_TO_SOFTWARE; | ||
| 646 | } | ||
| 647 | |||
| 648 | if (p_UBSEC_rsa_mod_exp_crt_ioctl(fd, | ||
| 649 | (unsigned char *)a->d, BN_num_bits(a), | ||
| 650 | (unsigned char *)qinv->d, BN_num_bits(qinv), | ||
| 651 | (unsigned char *)dp->d, BN_num_bits(dp), | ||
| 652 | (unsigned char *)p->d, BN_num_bits(p), | ||
| 653 | (unsigned char *)dq->d, BN_num_bits(dq), | ||
| 654 | (unsigned char *)q->d, BN_num_bits(q), | ||
| 655 | (unsigned char *)r->d, &y_len) != 0) { | ||
| 656 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_REQUEST_FAILED); | ||
| 657 | p_UBSEC_ubsec_close(fd); | ||
| 658 | return FAIL_TO_SOFTWARE; | ||
| 659 | } | ||
| 660 | |||
| 661 | p_UBSEC_ubsec_close(fd); | ||
| 662 | |||
| 663 | r->top = (BN_num_bits(p) + BN_num_bits(q) + BN_BITS2 - 1)/BN_BITS2; | ||
| 664 | return 1; | ||
| 665 | } | ||
| 666 | |||
| 667 | #ifndef OPENSSL_NO_DSA | ||
| 668 | #ifdef NOT_USED | ||
| 669 | static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
| 670 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
| 671 | BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
| 672 | { | ||
| 673 | BIGNUM t; | ||
| 674 | int to_return = 0; | ||
| 675 | |||
| 676 | BN_init(&t); | ||
| 677 | /* let rr = a1 ^ p1 mod m */ | ||
| 678 | if (!ubsec_mod_exp(rr,a1,p1,m,ctx)) goto end; | ||
| 679 | /* let t = a2 ^ p2 mod m */ | ||
| 680 | if (!ubsec_mod_exp(&t,a2,p2,m,ctx)) goto end; | ||
| 681 | /* let rr = rr * t mod m */ | ||
| 682 | if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end; | ||
| 683 | to_return = 1; | ||
| 684 | end: | ||
| 685 | BN_free(&t); | ||
| 686 | return to_return; | ||
| 687 | } | ||
| 688 | |||
| 689 | static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
| 690 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 691 | BN_MONT_CTX *m_ctx) | ||
| 692 | { | ||
| 693 | return ubsec_mod_exp(r, a, p, m, ctx); | ||
| 694 | } | ||
| 695 | #endif | ||
| 696 | #endif | ||
| 697 | |||
| 698 | /* | ||
| 699 | * This function is aliased to mod_exp (with the mont stuff dropped). | ||
| 700 | */ | ||
| 701 | static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 702 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
| 703 | { | ||
| 704 | int ret = 0; | ||
| 705 | |||
| 706 | #ifndef OPENSSL_NO_RSA | ||
| 707 | /* Do in software if the key is too large for the hardware. */ | ||
| 708 | if (BN_num_bits(m) > max_key_len) | ||
| 709 | { | ||
| 710 | const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
| 711 | ret = (*meth->bn_mod_exp)(r, a, p, m, ctx, m_ctx); | ||
| 712 | } | ||
| 713 | else | ||
| 714 | #endif | ||
| 715 | { | ||
| 716 | ret = ubsec_mod_exp(r, a, p, m, ctx); | ||
| 717 | } | ||
| 718 | |||
| 719 | return ret; | ||
| 720 | } | ||
| 721 | |||
| 722 | #ifndef OPENSSL_NO_DH | ||
| 723 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | ||
| 724 | static int ubsec_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
| 725 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
| 726 | BN_MONT_CTX *m_ctx) | ||
| 727 | { | ||
| 728 | return ubsec_mod_exp(r, a, p, m, ctx); | ||
| 729 | } | ||
| 730 | #endif | ||
| 731 | |||
| 732 | #ifndef OPENSSL_NO_DSA | ||
| 733 | static DSA_SIG *ubsec_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
| 734 | { | ||
| 735 | DSA_SIG *to_return = NULL; | ||
| 736 | int s_len = 160, r_len = 160, d_len, fd; | ||
| 737 | BIGNUM m, *r=NULL, *s=NULL; | ||
| 738 | |||
| 739 | BN_init(&m); | ||
| 740 | |||
| 741 | s = BN_new(); | ||
| 742 | r = BN_new(); | ||
| 743 | if ((s == NULL) || (r==NULL)) | ||
| 744 | goto err; | ||
| 745 | |||
| 746 | d_len = p_UBSEC_ubsec_bytes_to_bits((unsigned char *)dgst, dlen); | ||
| 747 | |||
| 748 | if(!bn_wexpand(r, (160+BN_BITS2-1)/BN_BITS2) || | ||
| 749 | (!bn_wexpand(s, (160+BN_BITS2-1)/BN_BITS2))) { | ||
| 750 | UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL); | ||
| 751 | goto err; | ||
| 752 | } | ||
| 753 | |||
| 754 | if (BN_bin2bn(dgst,dlen,&m) == NULL) { | ||
| 755 | UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL); | ||
| 756 | goto err; | ||
| 757 | } | ||
| 758 | |||
| 759 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) { | ||
| 760 | const DSA_METHOD *meth; | ||
| 761 | fd = 0; | ||
| 762 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
| 763 | meth = DSA_OpenSSL(); | ||
| 764 | to_return = meth->dsa_do_sign(dgst, dlen, dsa); | ||
| 765 | goto err; | ||
| 766 | } | ||
| 767 | |||
| 768 | if (p_UBSEC_dsa_sign_ioctl(fd, 0, /* compute hash before signing */ | ||
| 769 | (unsigned char *)dgst, d_len, | ||
| 770 | NULL, 0, /* compute random value */ | ||
| 771 | (unsigned char *)dsa->p->d, BN_num_bits(dsa->p), | ||
| 772 | (unsigned char *)dsa->q->d, BN_num_bits(dsa->q), | ||
| 773 | (unsigned char *)dsa->g->d, BN_num_bits(dsa->g), | ||
| 774 | (unsigned char *)dsa->priv_key->d, BN_num_bits(dsa->priv_key), | ||
| 775 | (unsigned char *)r->d, &r_len, | ||
| 776 | (unsigned char *)s->d, &s_len ) != 0) { | ||
| 777 | const DSA_METHOD *meth; | ||
| 778 | |||
| 779 | UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_REQUEST_FAILED); | ||
| 780 | p_UBSEC_ubsec_close(fd); | ||
| 781 | meth = DSA_OpenSSL(); | ||
| 782 | to_return = meth->dsa_do_sign(dgst, dlen, dsa); | ||
| 783 | |||
| 784 | goto err; | ||
| 785 | } | ||
| 786 | |||
| 787 | p_UBSEC_ubsec_close(fd); | ||
| 788 | |||
| 789 | r->top = (160+BN_BITS2-1)/BN_BITS2; | ||
| 790 | s->top = (160+BN_BITS2-1)/BN_BITS2; | ||
| 791 | |||
| 792 | to_return = DSA_SIG_new(); | ||
| 793 | if(to_return == NULL) { | ||
| 794 | UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL); | ||
| 795 | goto err; | ||
| 796 | } | ||
| 797 | |||
| 798 | to_return->r = r; | ||
| 799 | to_return->s = s; | ||
| 800 | |||
| 801 | err: | ||
| 802 | if (!to_return) { | ||
| 803 | if (r) BN_free(r); | ||
| 804 | if (s) BN_free(s); | ||
| 805 | } | ||
| 806 | BN_clear_free(&m); | ||
| 807 | return to_return; | ||
| 808 | } | ||
| 809 | |||
| 810 | static int ubsec_dsa_verify(const unsigned char *dgst, int dgst_len, | ||
| 811 | DSA_SIG *sig, DSA *dsa) | ||
| 812 | { | ||
| 813 | int v_len, d_len; | ||
| 814 | int to_return = 0; | ||
| 815 | int fd; | ||
| 816 | BIGNUM v; | ||
| 817 | |||
| 818 | BN_init(&v); | ||
| 819 | |||
| 820 | if(!bn_wexpand(&v, dsa->p->top)) { | ||
| 821 | UBSECerr(UBSEC_F_UBSEC_DSA_VERIFY ,UBSEC_R_BN_EXPAND_FAIL); | ||
| 822 | goto err; | ||
| 823 | } | ||
| 824 | |||
| 825 | v_len = BN_num_bits(dsa->p); | ||
| 826 | |||
| 827 | d_len = p_UBSEC_ubsec_bytes_to_bits((unsigned char *)dgst, dgst_len); | ||
| 828 | |||
| 829 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) { | ||
| 830 | const DSA_METHOD *meth; | ||
| 831 | fd = 0; | ||
| 832 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
| 833 | meth = DSA_OpenSSL(); | ||
| 834 | to_return = meth->dsa_do_verify(dgst, dgst_len, sig, dsa); | ||
| 835 | goto err; | ||
| 836 | } | ||
| 837 | |||
| 838 | if (p_UBSEC_dsa_verify_ioctl(fd, 0, /* compute hash before signing */ | ||
| 839 | (unsigned char *)dgst, d_len, | ||
| 840 | (unsigned char *)dsa->p->d, BN_num_bits(dsa->p), | ||
| 841 | (unsigned char *)dsa->q->d, BN_num_bits(dsa->q), | ||
| 842 | (unsigned char *)dsa->g->d, BN_num_bits(dsa->g), | ||
| 843 | (unsigned char *)dsa->pub_key->d, BN_num_bits(dsa->pub_key), | ||
| 844 | (unsigned char *)sig->r->d, BN_num_bits(sig->r), | ||
| 845 | (unsigned char *)sig->s->d, BN_num_bits(sig->s), | ||
| 846 | (unsigned char *)v.d, &v_len) != 0) { | ||
| 847 | const DSA_METHOD *meth; | ||
| 848 | UBSECerr(UBSEC_F_UBSEC_DSA_VERIFY , UBSEC_R_REQUEST_FAILED); | ||
| 849 | p_UBSEC_ubsec_close(fd); | ||
| 850 | |||
| 851 | meth = DSA_OpenSSL(); | ||
| 852 | to_return = meth->dsa_do_verify(dgst, dgst_len, sig, dsa); | ||
| 853 | |||
| 854 | goto err; | ||
| 855 | } | ||
| 856 | |||
| 857 | p_UBSEC_ubsec_close(fd); | ||
| 858 | |||
| 859 | to_return = 1; | ||
| 860 | err: | ||
| 861 | BN_clear_free(&v); | ||
| 862 | return to_return; | ||
| 863 | } | ||
| 864 | #endif | ||
| 865 | |||
| 866 | #ifndef OPENSSL_NO_DH | ||
| 867 | static int ubsec_dh_compute_key (unsigned char *key,const BIGNUM *pub_key,DH *dh) | ||
| 868 | { | ||
| 869 | int ret = -1, | ||
| 870 | k_len, | ||
| 871 | fd; | ||
| 872 | |||
| 873 | k_len = BN_num_bits(dh->p); | ||
| 874 | |||
| 875 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) | ||
| 876 | { | ||
| 877 | const DH_METHOD *meth; | ||
| 878 | ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
| 879 | meth = DH_OpenSSL(); | ||
| 880 | ret = meth->compute_key(key, pub_key, dh); | ||
| 881 | goto err; | ||
| 882 | } | ||
| 883 | |||
| 884 | if (p_UBSEC_diffie_hellman_agree_ioctl(fd, | ||
| 885 | (unsigned char *)dh->priv_key->d, BN_num_bits(dh->priv_key), | ||
| 886 | (unsigned char *)pub_key->d, BN_num_bits(pub_key), | ||
| 887 | (unsigned char *)dh->p->d, BN_num_bits(dh->p), | ||
| 888 | key, &k_len) != 0) | ||
| 889 | { | ||
| 890 | /* Hardware's a no go, failover to software */ | ||
| 891 | const DH_METHOD *meth; | ||
| 892 | ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED); | ||
| 893 | p_UBSEC_ubsec_close(fd); | ||
| 894 | |||
| 895 | meth = DH_OpenSSL(); | ||
| 896 | ret = meth->compute_key(key, pub_key, dh); | ||
| 897 | |||
| 898 | goto err; | ||
| 899 | } | ||
| 900 | |||
| 901 | p_UBSEC_ubsec_close(fd); | ||
| 902 | |||
| 903 | ret = p_UBSEC_ubsec_bits_to_bytes(k_len); | ||
| 904 | err: | ||
| 905 | return ret; | ||
| 906 | } | ||
| 907 | |||
| 908 | static int ubsec_dh_generate_key (DH *dh) | ||
| 909 | { | ||
| 910 | int ret = 0, | ||
| 911 | random_bits = 0, | ||
| 912 | pub_key_len = 0, | ||
| 913 | priv_key_len = 0, | ||
| 914 | fd; | ||
| 915 | BIGNUM *pub_key = NULL; | ||
| 916 | BIGNUM *priv_key = NULL; | ||
| 917 | |||
| 918 | /* | ||
| 919 | * How many bits should Random x be? dh_key.c | ||
| 920 | * sets the range from 0 to num_bits(modulus) ??? | ||
| 921 | */ | ||
| 922 | |||
| 923 | if (dh->priv_key == NULL) | ||
| 924 | { | ||
| 925 | priv_key = BN_new(); | ||
| 926 | if (priv_key == NULL) goto err; | ||
| 927 | priv_key_len = BN_num_bits(dh->p); | ||
| 928 | bn_wexpand(priv_key, dh->p->top); | ||
| 929 | do | ||
| 930 | if (!BN_rand_range(priv_key, dh->p)) goto err; | ||
| 931 | while (BN_is_zero(priv_key)); | ||
| 932 | random_bits = BN_num_bits(priv_key); | ||
| 933 | } | ||
| 934 | else | ||
| 935 | { | ||
| 936 | priv_key = dh->priv_key; | ||
| 937 | } | ||
| 938 | |||
| 939 | if (dh->pub_key == NULL) | ||
| 940 | { | ||
| 941 | pub_key = BN_new(); | ||
| 942 | pub_key_len = BN_num_bits(dh->p); | ||
| 943 | bn_wexpand(pub_key, dh->p->top); | ||
| 944 | if(pub_key == NULL) goto err; | ||
| 945 | } | ||
| 946 | else | ||
| 947 | { | ||
| 948 | pub_key = dh->pub_key; | ||
| 949 | } | ||
| 950 | |||
| 951 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) | ||
| 952 | { | ||
| 953 | const DH_METHOD *meth; | ||
| 954 | ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
| 955 | meth = DH_OpenSSL(); | ||
| 956 | ret = meth->generate_key(dh); | ||
| 957 | goto err; | ||
| 958 | } | ||
| 959 | |||
| 960 | if (p_UBSEC_diffie_hellman_generate_ioctl(fd, | ||
| 961 | (unsigned char *)priv_key->d, &priv_key_len, | ||
| 962 | (unsigned char *)pub_key->d, &pub_key_len, | ||
| 963 | (unsigned char *)dh->g->d, BN_num_bits(dh->g), | ||
| 964 | (unsigned char *)dh->p->d, BN_num_bits(dh->p), | ||
| 965 | 0, 0, random_bits) != 0) | ||
| 966 | { | ||
| 967 | /* Hardware's a no go, failover to software */ | ||
| 968 | const DH_METHOD *meth; | ||
| 969 | |||
| 970 | ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED); | ||
| 971 | p_UBSEC_ubsec_close(fd); | ||
| 972 | |||
| 973 | meth = DH_OpenSSL(); | ||
| 974 | ret = meth->generate_key(dh); | ||
| 975 | |||
| 976 | goto err; | ||
| 977 | } | ||
| 978 | |||
| 979 | p_UBSEC_ubsec_close(fd); | ||
| 980 | |||
| 981 | dh->pub_key = pub_key; | ||
| 982 | dh->pub_key->top = (pub_key_len + BN_BITS2-1) / BN_BITS2; | ||
| 983 | dh->priv_key = priv_key; | ||
| 984 | dh->priv_key->top = (priv_key_len + BN_BITS2-1) / BN_BITS2; | ||
| 985 | |||
| 986 | ret = 1; | ||
| 987 | err: | ||
| 988 | return ret; | ||
| 989 | } | ||
| 990 | #endif | ||
| 991 | |||
| 992 | #ifdef NOT_USED | ||
| 993 | static int ubsec_rand_bytes(unsigned char * buf, | ||
| 994 | int num) | ||
| 995 | { | ||
| 996 | int ret = 0, | ||
| 997 | fd; | ||
| 998 | |||
| 999 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) | ||
| 1000 | { | ||
| 1001 | const RAND_METHOD *meth; | ||
| 1002 | ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
| 1003 | num = p_UBSEC_ubsec_bits_to_bytes(num); | ||
| 1004 | meth = RAND_SSLeay(); | ||
| 1005 | meth->seed(buf, num); | ||
| 1006 | ret = meth->bytes(buf, num); | ||
| 1007 | goto err; | ||
| 1008 | } | ||
| 1009 | |||
| 1010 | num *= 8; /* bytes to bits */ | ||
| 1011 | |||
| 1012 | if (p_UBSEC_rng_ioctl(fd, | ||
| 1013 | UBSEC_RNG_DIRECT, | ||
| 1014 | buf, | ||
| 1015 | &num) != 0) | ||
| 1016 | { | ||
| 1017 | /* Hardware's a no go, failover to software */ | ||
| 1018 | const RAND_METHOD *meth; | ||
| 1019 | |||
| 1020 | ENGINEerr(UBSEC_F_UBSEC_RNG_BYTES, UBSEC_R_REQUEST_FAILED); | ||
| 1021 | p_UBSEC_ubsec_close(fd); | ||
| 1022 | |||
| 1023 | num = p_UBSEC_ubsec_bits_to_bytes(num); | ||
| 1024 | meth = RAND_SSLeay(); | ||
| 1025 | meth->seed(buf, num); | ||
| 1026 | ret = meth->bytes(buf, num); | ||
| 1027 | |||
| 1028 | goto err; | ||
| 1029 | } | ||
| 1030 | |||
| 1031 | p_UBSEC_ubsec_close(fd); | ||
| 1032 | |||
| 1033 | ret = 1; | ||
| 1034 | err: | ||
| 1035 | return(ret); | ||
| 1036 | } | ||
| 1037 | |||
| 1038 | |||
| 1039 | static int ubsec_rand_status(void) | ||
| 1040 | { | ||
| 1041 | return 0; | ||
| 1042 | } | ||
| 1043 | #endif | ||
| 1044 | |||
| 1045 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | ||
| 1046 | * shared-library. */ | ||
| 1047 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
| 1048 | static int bind_fn(ENGINE *e, const char *id) | ||
| 1049 | { | ||
| 1050 | if(id && (strcmp(id, engine_ubsec_id) != 0)) | ||
| 1051 | return 0; | ||
| 1052 | if(!bind_helper(e)) | ||
| 1053 | return 0; | ||
| 1054 | return 1; | ||
| 1055 | } | ||
| 1056 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
| 1057 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | ||
| 1058 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | ||
| 1059 | |||
| 1060 | #endif /* !OPENSSL_NO_HW_UBSEC */ | ||
| 1061 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/vendor_defns/sureware.h b/src/lib/libcrypto/engine/vendor_defns/sureware.h deleted file mode 100644 index 4bc22027f9..0000000000 --- a/src/lib/libcrypto/engine/vendor_defns/sureware.h +++ /dev/null | |||
| @@ -1,239 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Written by Corinne Dive-Reclus(cdive@baltimore.com) | ||
| 3 | * | ||
| 4 | * Copyright@2001 Baltimore Technologies Ltd. | ||
| 5 | * * | ||
| 6 | * THIS FILE IS PROVIDED BY BALTIMORE TECHNOLOGIES ``AS IS'' AND * | ||
| 7 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * | ||
| 8 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * | ||
| 9 | * ARE DISCLAIMED. IN NO EVENT SHALL BALTIMORE TECHNOLOGIES BE LIABLE * | ||
| 10 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * | ||
| 11 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * | ||
| 12 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * | ||
| 13 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * | ||
| 14 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * | ||
| 15 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * | ||
| 16 | * SUCH DAMAGE. * | ||
| 17 | * | ||
| 18 | * | ||
| 19 | */ | ||
| 20 | #ifdef WIN32 | ||
| 21 | #define SW_EXPORT __declspec ( dllexport ) | ||
| 22 | #else | ||
| 23 | #define SW_EXPORT | ||
| 24 | #endif | ||
| 25 | |||
| 26 | /* | ||
| 27 | * List of exposed SureWare errors | ||
| 28 | */ | ||
| 29 | #define SUREWAREHOOK_ERROR_FAILED -1 | ||
| 30 | #define SUREWAREHOOK_ERROR_FALLBACK -2 | ||
| 31 | #define SUREWAREHOOK_ERROR_UNIT_FAILURE -3 | ||
| 32 | #define SUREWAREHOOK_ERROR_DATA_SIZE -4 | ||
| 33 | #define SUREWAREHOOK_ERROR_INVALID_PAD -5 | ||
| 34 | /* | ||
| 35 | * -----------------WARNING----------------------------------- | ||
| 36 | * In all the following functions: | ||
| 37 | * msg is a string with at least 24 bytes free. | ||
| 38 | * A 24 bytes string will be concatenated to the existing content of msg. | ||
| 39 | */ | ||
| 40 | /* | ||
| 41 | * SureWare Initialisation function | ||
| 42 | * in param threadsafe, if !=0, thread safe enabled | ||
| 43 | * return SureWareHOOK_ERROR_UNIT_FAILURE if failure, 1 if success | ||
| 44 | */ | ||
| 45 | typedef int SureWareHook_Init_t(char*const msg,int threadsafe); | ||
| 46 | extern SW_EXPORT SureWareHook_Init_t SureWareHook_Init; | ||
| 47 | /* | ||
| 48 | * SureWare Finish function | ||
| 49 | */ | ||
| 50 | typedef void SureWareHook_Finish_t(); | ||
| 51 | extern SW_EXPORT SureWareHook_Finish_t SureWareHook_Finish; | ||
| 52 | /* | ||
| 53 | * PRE_CONDITION: | ||
| 54 | * DO NOT CALL ANY OF THE FOLLOWING FUNCTIONS IN CASE OF INIT FAILURE | ||
| 55 | */ | ||
| 56 | /* | ||
| 57 | * SureWare RAND Bytes function | ||
| 58 | * In case of failure, the content of buf is unpredictable. | ||
| 59 | * return 1 if success | ||
| 60 | * SureWareHOOK_ERROR_FALLBACK if function not available in hardware | ||
| 61 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
| 62 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
| 63 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
| 64 | * | ||
| 65 | * in/out param buf : a num bytes long buffer where random bytes will be put | ||
| 66 | * in param num : the number of bytes into buf | ||
| 67 | */ | ||
| 68 | typedef int SureWareHook_Rand_Bytes_t(char*const msg,unsigned char *buf, int num); | ||
| 69 | extern SW_EXPORT SureWareHook_Rand_Bytes_t SureWareHook_Rand_Bytes; | ||
| 70 | |||
| 71 | /* | ||
| 72 | * SureWare RAND Seed function | ||
| 73 | * Adds some seed to the Hardware Random Number Generator | ||
| 74 | * return 1 if success | ||
| 75 | * SureWareHOOK_ERROR_FALLBACK if function not available in hardware | ||
| 76 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
| 77 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
| 78 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
| 79 | * | ||
| 80 | * in param buf : the seed to add into the HRNG | ||
| 81 | * in param num : the number of bytes into buf | ||
| 82 | */ | ||
| 83 | typedef int SureWareHook_Rand_Seed_t(char*const msg,const void *buf, int num); | ||
| 84 | extern SW_EXPORT SureWareHook_Rand_Seed_t SureWareHook_Rand_Seed; | ||
| 85 | |||
| 86 | /* | ||
| 87 | * SureWare Load Private Key function | ||
| 88 | * return 1 if success | ||
| 89 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
| 90 | * No hardware is contact for this function. | ||
| 91 | * | ||
| 92 | * in param key_id :the name of the private protected key file without the extension | ||
| 93 | ".sws" | ||
| 94 | * out param hptr : a pointer to a buffer allocated by SureWare_Hook | ||
| 95 | * out param num: the effective key length in bytes | ||
| 96 | * out param keytype: 1 if RSA 2 if DSA | ||
| 97 | */ | ||
| 98 | typedef int SureWareHook_Load_Privkey_t(char*const msg,const char *key_id,char **hptr,unsigned long *num,char *keytype); | ||
| 99 | extern SW_EXPORT SureWareHook_Load_Privkey_t SureWareHook_Load_Privkey; | ||
| 100 | |||
| 101 | /* | ||
| 102 | * SureWare Info Public Key function | ||
| 103 | * return 1 if success | ||
| 104 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
| 105 | * No hardware is contact for this function. | ||
| 106 | * | ||
| 107 | * in param key_id :the name of the private protected key file without the extension | ||
| 108 | ".swp" | ||
| 109 | * out param hptr : a pointer to a buffer allocated by SureWare_Hook | ||
| 110 | * out param num: the effective key length in bytes | ||
| 111 | * out param keytype: 1 if RSA 2 if DSA | ||
| 112 | */ | ||
| 113 | typedef int SureWareHook_Info_Pubkey_t(char*const msg,const char *key_id,unsigned long *num, | ||
| 114 | char *keytype); | ||
| 115 | extern SW_EXPORT SureWareHook_Info_Pubkey_t SureWareHook_Info_Pubkey; | ||
| 116 | |||
| 117 | /* | ||
| 118 | * SureWare Load Public Key function | ||
| 119 | * return 1 if success | ||
| 120 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
| 121 | * No hardware is contact for this function. | ||
| 122 | * | ||
| 123 | * in param key_id :the name of the public protected key file without the extension | ||
| 124 | ".swp" | ||
| 125 | * in param num : the bytes size of n and e | ||
| 126 | * out param n: where to write modulus in bn format | ||
| 127 | * out param e: where to write exponent in bn format | ||
| 128 | */ | ||
| 129 | typedef int SureWareHook_Load_Rsa_Pubkey_t(char*const msg,const char *key_id,unsigned long num, | ||
| 130 | unsigned long *n, unsigned long *e); | ||
| 131 | extern SW_EXPORT SureWareHook_Load_Rsa_Pubkey_t SureWareHook_Load_Rsa_Pubkey; | ||
| 132 | |||
| 133 | /* | ||
| 134 | * SureWare Load DSA Public Key function | ||
| 135 | * return 1 if success | ||
| 136 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
| 137 | * No hardware is contact for this function. | ||
| 138 | * | ||
| 139 | * in param key_id :the name of the public protected key file without the extension | ||
| 140 | ".swp" | ||
| 141 | * in param num : the bytes size of n and e | ||
| 142 | * out param pub: where to write pub key in bn format | ||
| 143 | * out param p: where to write prime in bn format | ||
| 144 | * out param q: where to write sunprime (length 20 bytes) in bn format | ||
| 145 | * out param g: where to write base in bn format | ||
| 146 | */ | ||
| 147 | typedef int SureWareHook_Load_Dsa_Pubkey_t(char*const msg,const char *key_id,unsigned long num, | ||
| 148 | unsigned long *pub, unsigned long *p,unsigned long*q, | ||
| 149 | unsigned long *g); | ||
| 150 | extern SW_EXPORT SureWareHook_Load_Dsa_Pubkey_t SureWareHook_Load_Dsa_Pubkey; | ||
| 151 | |||
| 152 | /* | ||
| 153 | * SureWare Free function | ||
| 154 | * Destroy the key into the hardware if destroy==1 | ||
| 155 | */ | ||
| 156 | typedef void SureWareHook_Free_t(char *p,int destroy); | ||
| 157 | extern SW_EXPORT SureWareHook_Free_t SureWareHook_Free; | ||
| 158 | |||
| 159 | #define SUREWARE_PKCS1_PAD 1 | ||
| 160 | #define SUREWARE_ISO9796_PAD 2 | ||
| 161 | #define SUREWARE_NO_PAD 0 | ||
| 162 | /* | ||
| 163 | * SureWare RSA Private Decryption | ||
| 164 | * return 1 if success | ||
| 165 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
| 166 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
| 167 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
| 168 | * | ||
| 169 | * in param flen : byte size of from and to | ||
| 170 | * in param from : encrypted data buffer, should be a not-null valid pointer | ||
| 171 | * out param tlen: byte size of decrypted data, if error, unexpected value | ||
| 172 | * out param to : decrypted data buffer, should be a not-null valid pointer | ||
| 173 | * in param prsa: a protected key pointer, should be a not-null valid pointer | ||
| 174 | * int padding: padding id as follow | ||
| 175 | * SUREWARE_PKCS1_PAD | ||
| 176 | * SUREWARE_NO_PAD | ||
| 177 | * | ||
| 178 | */ | ||
| 179 | typedef int SureWareHook_Rsa_Priv_Dec_t(char*const msg,int flen,unsigned char *from, | ||
| 180 | int *tlen,unsigned char *to, | ||
| 181 | char *prsa,int padding); | ||
| 182 | extern SW_EXPORT SureWareHook_Rsa_Priv_Dec_t SureWareHook_Rsa_Priv_Dec; | ||
| 183 | /* | ||
| 184 | * SureWare RSA Signature | ||
| 185 | * return 1 if success | ||
| 186 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
| 187 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
| 188 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
| 189 | * | ||
| 190 | * in param flen : byte size of from and to | ||
| 191 | * in param from : encrypted data buffer, should be a not-null valid pointer | ||
| 192 | * out param tlen: byte size of decrypted data, if error, unexpected value | ||
| 193 | * out param to : decrypted data buffer, should be a not-null valid pointer | ||
| 194 | * in param prsa: a protected key pointer, should be a not-null valid pointer | ||
| 195 | * int padding: padding id as follow | ||
| 196 | * SUREWARE_PKCS1_PAD | ||
| 197 | * SUREWARE_ISO9796_PAD | ||
| 198 | * | ||
| 199 | */ | ||
| 200 | typedef int SureWareHook_Rsa_Sign_t(char*const msg,int flen,unsigned char *from, | ||
| 201 | int *tlen,unsigned char *to, | ||
| 202 | char *prsa,int padding); | ||
| 203 | extern SW_EXPORT SureWareHook_Rsa_Sign_t SureWareHook_Rsa_Sign; | ||
| 204 | /* | ||
| 205 | * SureWare DSA Signature | ||
| 206 | * return 1 if success | ||
| 207 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
| 208 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
| 209 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
| 210 | * | ||
| 211 | * in param flen : byte size of from and to | ||
| 212 | * in param from : encrypted data buffer, should be a not-null valid pointer | ||
| 213 | * out param to : decrypted data buffer, should be a 40bytes valid pointer | ||
| 214 | * in param pdsa: a protected key pointer, should be a not-null valid pointer | ||
| 215 | * | ||
| 216 | */ | ||
| 217 | typedef int SureWareHook_Dsa_Sign_t(char*const msg,int flen,const unsigned char *from, | ||
| 218 | unsigned long *r,unsigned long *s,char *pdsa); | ||
| 219 | extern SW_EXPORT SureWareHook_Dsa_Sign_t SureWareHook_Dsa_Sign; | ||
| 220 | |||
| 221 | |||
| 222 | /* | ||
| 223 | * SureWare Mod Exp | ||
| 224 | * return 1 if success | ||
| 225 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
| 226 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
| 227 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
| 228 | * | ||
| 229 | * mod and res are mlen bytes long. | ||
| 230 | * exp is elen bytes long | ||
| 231 | * data is dlen bytes long | ||
| 232 | * mlen,elen and dlen are all multiple of sizeof(unsigned long) | ||
| 233 | */ | ||
| 234 | typedef int SureWareHook_Mod_Exp_t(char*const msg,int mlen,const unsigned long *mod, | ||
| 235 | int elen,const unsigned long *exponent, | ||
| 236 | int dlen,unsigned long *data, | ||
| 237 | unsigned long *res); | ||
| 238 | extern SW_EXPORT SureWareHook_Mod_Exp_t SureWareHook_Mod_Exp; | ||
| 239 | |||
diff --git a/src/lib/libcrypto/err/err_def.c b/src/lib/libcrypto/err/err_def.c deleted file mode 100644 index 7ed3d84955..0000000000 --- a/src/lib/libcrypto/err/err_def.c +++ /dev/null | |||
| @@ -1,665 +0,0 @@ | |||
| 1 | /* crypto/err/err_def.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | /* ==================================================================== | ||
| 59 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
| 60 | * | ||
| 61 | * Redistribution and use in source and binary forms, with or without | ||
| 62 | * modification, are permitted provided that the following conditions | ||
| 63 | * are met: | ||
| 64 | * | ||
| 65 | * 1. Redistributions of source code must retain the above copyright | ||
| 66 | * notice, this list of conditions and the following disclaimer. | ||
| 67 | * | ||
| 68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 69 | * notice, this list of conditions and the following disclaimer in | ||
| 70 | * the documentation and/or other materials provided with the | ||
| 71 | * distribution. | ||
| 72 | * | ||
| 73 | * 3. All advertising materials mentioning features or use of this | ||
| 74 | * software must display the following acknowledgment: | ||
| 75 | * "This product includes software developed by the OpenSSL Project | ||
| 76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 77 | * | ||
| 78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 79 | * endorse or promote products derived from this software without | ||
| 80 | * prior written permission. For written permission, please contact | ||
| 81 | * openssl-core@openssl.org. | ||
| 82 | * | ||
| 83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 84 | * nor may "OpenSSL" appear in their names without prior written | ||
| 85 | * permission of the OpenSSL Project. | ||
| 86 | * | ||
| 87 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 88 | * acknowledgment: | ||
| 89 | * "This product includes software developed by the OpenSSL Project | ||
| 90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 91 | * | ||
| 92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 104 | * ==================================================================== | ||
| 105 | * | ||
| 106 | * This product includes cryptographic software written by Eric Young | ||
| 107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 108 | * Hudson (tjh@cryptsoft.com). | ||
| 109 | * | ||
| 110 | */ | ||
| 111 | |||
| 112 | #include <stdio.h> | ||
| 113 | #include <stdarg.h> | ||
| 114 | #include <string.h> | ||
| 115 | #include "cryptlib.h" | ||
| 116 | #include <openssl/lhash.h> | ||
| 117 | #include <openssl/crypto.h> | ||
| 118 | #include <openssl/buffer.h> | ||
| 119 | #include <openssl/bio.h> | ||
| 120 | #include <openssl/err.h> | ||
| 121 | |||
| 122 | #define err_clear_data(p,i) \ | ||
| 123 | do { \ | ||
| 124 | if (((p)->err_data[i] != NULL) && \ | ||
| 125 | (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \ | ||
| 126 | { \ | ||
| 127 | OPENSSL_free((p)->err_data[i]); \ | ||
| 128 | (p)->err_data[i]=NULL; \ | ||
| 129 | } \ | ||
| 130 | (p)->err_data_flags[i]=0; \ | ||
| 131 | } while(0) | ||
| 132 | |||
| 133 | #define err_clear(p,i) \ | ||
| 134 | do { \ | ||
| 135 | (p)->err_flags[i]=0; \ | ||
| 136 | (p)->err_buffer[i]=0; \ | ||
| 137 | err_clear_data(p,i); \ | ||
| 138 | (p)->err_file[i]=NULL; \ | ||
| 139 | (p)->err_line[i]= -1; \ | ||
| 140 | } while(0) | ||
| 141 | |||
| 142 | static void err_load_strings(int lib, ERR_STRING_DATA *str); | ||
| 143 | |||
| 144 | static void ERR_STATE_free(ERR_STATE *s); | ||
| 145 | |||
| 146 | /* Define the predeclared (but externally opaque) "ERR_FNS" type */ | ||
| 147 | struct st_ERR_FNS | ||
| 148 | { | ||
| 149 | /* Works on the "error_hash" string table */ | ||
| 150 | LHASH *(*cb_err_get)(int create); | ||
| 151 | void (*cb_err_del)(void); | ||
| 152 | ERR_STRING_DATA *(*cb_err_get_item)(const ERR_STRING_DATA *); | ||
| 153 | ERR_STRING_DATA *(*cb_err_set_item)(ERR_STRING_DATA *); | ||
| 154 | ERR_STRING_DATA *(*cb_err_del_item)(ERR_STRING_DATA *); | ||
| 155 | /* Works on the "thread_hash" error-state table */ | ||
| 156 | LHASH *(*cb_thread_get)(int create); | ||
| 157 | void (*cb_thread_release)(LHASH **hash); | ||
| 158 | ERR_STATE *(*cb_thread_get_item)(const ERR_STATE *); | ||
| 159 | ERR_STATE *(*cb_thread_set_item)(ERR_STATE *); | ||
| 160 | void (*cb_thread_del_item)(const ERR_STATE *); | ||
| 161 | /* Returns the next available error "library" numbers */ | ||
| 162 | int (*cb_get_next_lib)(void); | ||
| 163 | }; | ||
| 164 | |||
| 165 | /* Predeclarations of the "err_defaults" functions */ | ||
| 166 | static LHASH *int_err_get(int create); | ||
| 167 | static void int_err_del(void); | ||
| 168 | static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *); | ||
| 169 | static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *); | ||
| 170 | static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *); | ||
| 171 | static LHASH *int_thread_get(int create); | ||
| 172 | static void int_thread_release(LHASH **hash); | ||
| 173 | static ERR_STATE *int_thread_get_item(const ERR_STATE *); | ||
| 174 | static ERR_STATE *int_thread_set_item(ERR_STATE *); | ||
| 175 | static void int_thread_del_item(const ERR_STATE *); | ||
| 176 | static int int_err_get_next_lib(void); | ||
| 177 | /* The static ERR_FNS table using these defaults functions */ | ||
| 178 | static const ERR_FNS err_defaults = | ||
| 179 | { | ||
| 180 | int_err_get, | ||
| 181 | int_err_del, | ||
| 182 | int_err_get_item, | ||
| 183 | int_err_set_item, | ||
| 184 | int_err_del_item, | ||
| 185 | int_thread_get, | ||
| 186 | int_thread_release, | ||
| 187 | int_thread_get_item, | ||
| 188 | int_thread_set_item, | ||
| 189 | int_thread_del_item, | ||
| 190 | int_err_get_next_lib | ||
| 191 | }; | ||
| 192 | |||
| 193 | /* The replacable table of ERR_FNS functions we use at run-time */ | ||
| 194 | static const ERR_FNS *err_fns = NULL; | ||
| 195 | |||
| 196 | /* Eg. rather than using "err_get()", use "ERRFN(err_get)()". */ | ||
| 197 | #define ERRFN(a) err_fns->cb_##a | ||
| 198 | |||
| 199 | /* The internal state used by "err_defaults" - as such, the setting, reading, | ||
| 200 | * creating, and deleting of this data should only be permitted via the | ||
| 201 | * "err_defaults" functions. This way, a linked module can completely defer all | ||
| 202 | * ERR state operation (together with requisite locking) to the implementations | ||
| 203 | * and state in the loading application. */ | ||
| 204 | static LHASH *int_error_hash = NULL; | ||
| 205 | static LHASH *int_thread_hash = NULL; | ||
| 206 | static int int_thread_hash_references = 0; | ||
| 207 | static int int_err_library_number= ERR_LIB_USER; | ||
| 208 | |||
| 209 | /* Internal function that checks whether "err_fns" is set and if not, sets it to | ||
| 210 | * the defaults. */ | ||
| 211 | static void err_fns_check(void) | ||
| 212 | { | ||
| 213 | if (err_fns) return; | ||
| 214 | |||
| 215 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 216 | if (!err_fns) | ||
| 217 | err_fns = &err_defaults; | ||
| 218 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 219 | } | ||
| 220 | |||
| 221 | /* API functions to get or set the underlying ERR functions. */ | ||
| 222 | |||
| 223 | const ERR_FNS *ERR_get_implementation(void) | ||
| 224 | { | ||
| 225 | err_fns_check(); | ||
| 226 | return err_fns; | ||
| 227 | } | ||
| 228 | |||
| 229 | int ERR_set_implementation(const ERR_FNS *fns) | ||
| 230 | { | ||
| 231 | int ret = 0; | ||
| 232 | |||
| 233 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 234 | /* It's too late if 'err_fns' is non-NULL. BTW: not much point setting | ||
| 235 | * an error is there?! */ | ||
| 236 | if (!err_fns) | ||
| 237 | { | ||
| 238 | err_fns = fns; | ||
| 239 | ret = 1; | ||
| 240 | } | ||
| 241 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 242 | return ret; | ||
| 243 | } | ||
| 244 | |||
| 245 | /* These are the callbacks provided to "lh_new()" when creating the LHASH tables | ||
| 246 | * internal to the "err_defaults" implementation. */ | ||
| 247 | |||
| 248 | /* static unsigned long err_hash(ERR_STRING_DATA *a); */ | ||
| 249 | static unsigned long err_hash(const void *a_void); | ||
| 250 | /* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b); */ | ||
| 251 | static int err_cmp(const void *a_void, const void *b_void); | ||
| 252 | /* static unsigned long pid_hash(ERR_STATE *pid); */ | ||
| 253 | static unsigned long pid_hash(const void *pid_void); | ||
| 254 | /* static int pid_cmp(ERR_STATE *a,ERR_STATE *pid); */ | ||
| 255 | static int pid_cmp(const void *a_void,const void *pid_void); | ||
| 256 | |||
| 257 | /* The internal functions used in the "err_defaults" implementation */ | ||
| 258 | |||
| 259 | static LHASH *int_err_get(int create) | ||
| 260 | { | ||
| 261 | LHASH *ret = NULL; | ||
| 262 | |||
| 263 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 264 | if (!int_error_hash && create) | ||
| 265 | { | ||
| 266 | CRYPTO_push_info("int_err_get (err.c)"); | ||
| 267 | int_error_hash = lh_new(err_hash, err_cmp); | ||
| 268 | CRYPTO_pop_info(); | ||
| 269 | } | ||
| 270 | if (int_error_hash) | ||
| 271 | ret = int_error_hash; | ||
| 272 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 273 | |||
| 274 | return ret; | ||
| 275 | } | ||
| 276 | |||
| 277 | static void int_err_del(void) | ||
| 278 | { | ||
| 279 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 280 | if (int_error_hash) | ||
| 281 | { | ||
| 282 | lh_free(int_error_hash); | ||
| 283 | int_error_hash = NULL; | ||
| 284 | } | ||
| 285 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 286 | } | ||
| 287 | |||
| 288 | static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d) | ||
| 289 | { | ||
| 290 | ERR_STRING_DATA *p; | ||
| 291 | LHASH *hash; | ||
| 292 | |||
| 293 | err_fns_check(); | ||
| 294 | hash = ERRFN(err_get)(0); | ||
| 295 | if (!hash) | ||
| 296 | return NULL; | ||
| 297 | |||
| 298 | CRYPTO_r_lock(CRYPTO_LOCK_ERR); | ||
| 299 | p = (ERR_STRING_DATA *)lh_retrieve(hash, d); | ||
| 300 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR); | ||
| 301 | |||
| 302 | return p; | ||
| 303 | } | ||
| 304 | |||
| 305 | static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *d) | ||
| 306 | { | ||
| 307 | ERR_STRING_DATA *p; | ||
| 308 | LHASH *hash; | ||
| 309 | |||
| 310 | err_fns_check(); | ||
| 311 | hash = ERRFN(err_get)(1); | ||
| 312 | if (!hash) | ||
| 313 | return NULL; | ||
| 314 | |||
| 315 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 316 | p = (ERR_STRING_DATA *)lh_insert(hash, d); | ||
| 317 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 318 | |||
| 319 | return p; | ||
| 320 | } | ||
| 321 | |||
| 322 | static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d) | ||
| 323 | { | ||
| 324 | ERR_STRING_DATA *p; | ||
| 325 | LHASH *hash; | ||
| 326 | |||
| 327 | err_fns_check(); | ||
| 328 | hash = ERRFN(err_get)(0); | ||
| 329 | if (!hash) | ||
| 330 | return NULL; | ||
| 331 | |||
| 332 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 333 | p = (ERR_STRING_DATA *)lh_delete(hash, d); | ||
| 334 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 335 | |||
| 336 | return p; | ||
| 337 | } | ||
| 338 | |||
| 339 | static LHASH *int_thread_get(int create) | ||
| 340 | { | ||
| 341 | LHASH *ret = NULL; | ||
| 342 | |||
| 343 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 344 | if (!int_thread_hash && create) | ||
| 345 | { | ||
| 346 | CRYPTO_push_info("int_thread_get (err.c)"); | ||
| 347 | int_thread_hash = lh_new(pid_hash, pid_cmp); | ||
| 348 | CRYPTO_pop_info(); | ||
| 349 | } | ||
| 350 | if (int_thread_hash) | ||
| 351 | { | ||
| 352 | int_thread_hash_references++; | ||
| 353 | ret = int_thread_hash; | ||
| 354 | } | ||
| 355 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 356 | return ret; | ||
| 357 | } | ||
| 358 | |||
| 359 | static void int_thread_release(LHASH **hash) | ||
| 360 | { | ||
| 361 | int i; | ||
| 362 | |||
| 363 | if (hash == NULL || *hash == NULL) | ||
| 364 | return; | ||
| 365 | |||
| 366 | i = CRYPTO_add(&int_thread_hash_references, -1, CRYPTO_LOCK_ERR); | ||
| 367 | |||
| 368 | #ifdef REF_PRINT | ||
| 369 | fprintf(stderr,"%4d:%s\n",int_thread_hash_references,"ERR"); | ||
| 370 | #endif | ||
| 371 | if (i > 0) return; | ||
| 372 | #ifdef REF_CHECK | ||
| 373 | if (i < 0) | ||
| 374 | { | ||
| 375 | fprintf(stderr,"int_thread_release, bad reference count\n"); | ||
| 376 | abort(); /* ok */ | ||
| 377 | } | ||
| 378 | #endif | ||
| 379 | *hash = NULL; | ||
| 380 | } | ||
| 381 | |||
| 382 | static ERR_STATE *int_thread_get_item(const ERR_STATE *d) | ||
| 383 | { | ||
| 384 | ERR_STATE *p; | ||
| 385 | LHASH *hash; | ||
| 386 | |||
| 387 | err_fns_check(); | ||
| 388 | hash = ERRFN(thread_get)(0); | ||
| 389 | if (!hash) | ||
| 390 | return NULL; | ||
| 391 | |||
| 392 | CRYPTO_r_lock(CRYPTO_LOCK_ERR); | ||
| 393 | p = (ERR_STATE *)lh_retrieve(hash, d); | ||
| 394 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR); | ||
| 395 | |||
| 396 | ERRFN(thread_release)(&hash); | ||
| 397 | return p; | ||
| 398 | } | ||
| 399 | |||
| 400 | static ERR_STATE *int_thread_set_item(ERR_STATE *d) | ||
| 401 | { | ||
| 402 | ERR_STATE *p; | ||
| 403 | LHASH *hash; | ||
| 404 | |||
| 405 | err_fns_check(); | ||
| 406 | hash = ERRFN(thread_get)(1); | ||
| 407 | if (!hash) | ||
| 408 | return NULL; | ||
| 409 | |||
| 410 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 411 | p = (ERR_STATE *)lh_insert(hash, d); | ||
| 412 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 413 | |||
| 414 | ERRFN(thread_release)(&hash); | ||
| 415 | return p; | ||
| 416 | } | ||
| 417 | |||
| 418 | static void int_thread_del_item(const ERR_STATE *d) | ||
| 419 | { | ||
| 420 | ERR_STATE *p; | ||
| 421 | LHASH *hash; | ||
| 422 | |||
| 423 | err_fns_check(); | ||
| 424 | hash = ERRFN(thread_get)(0); | ||
| 425 | if (!hash) | ||
| 426 | return; | ||
| 427 | |||
| 428 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 429 | p = (ERR_STATE *)lh_delete(hash, d); | ||
| 430 | /* make sure we don't leak memory */ | ||
| 431 | if (int_thread_hash_references == 1 | ||
| 432 | && int_thread_hash && (lh_num_items(int_thread_hash) == 0)) | ||
| 433 | { | ||
| 434 | lh_free(int_thread_hash); | ||
| 435 | int_thread_hash = NULL; | ||
| 436 | } | ||
| 437 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 438 | |||
| 439 | ERRFN(thread_release)(&hash); | ||
| 440 | if (p) | ||
| 441 | ERR_STATE_free(p); | ||
| 442 | } | ||
| 443 | |||
| 444 | static int int_err_get_next_lib(void) | ||
| 445 | { | ||
| 446 | int ret; | ||
| 447 | |||
| 448 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 449 | ret = int_err_library_number++; | ||
| 450 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 451 | |||
| 452 | return ret; | ||
| 453 | } | ||
| 454 | |||
| 455 | static void ERR_STATE_free(ERR_STATE *s) | ||
| 456 | { | ||
| 457 | int i; | ||
| 458 | |||
| 459 | if (s == NULL) | ||
| 460 | return; | ||
| 461 | |||
| 462 | for (i=0; i<ERR_NUM_ERRORS; i++) | ||
| 463 | { | ||
| 464 | err_clear_data(s,i); | ||
| 465 | } | ||
| 466 | OPENSSL_free(s); | ||
| 467 | } | ||
| 468 | |||
| 469 | static void err_load_strings(int lib, ERR_STRING_DATA *str) | ||
| 470 | { | ||
| 471 | while (str->error) | ||
| 472 | { | ||
| 473 | if (lib) | ||
| 474 | str->error|=ERR_PACK(lib,0,0); | ||
| 475 | ERRFN(err_set_item)(str); | ||
| 476 | str++; | ||
| 477 | } | ||
| 478 | } | ||
| 479 | |||
| 480 | void ERR_load_strings(int lib, ERR_STRING_DATA *str) | ||
| 481 | { | ||
| 482 | err_fns_check(); | ||
| 483 | err_load_strings(lib, str); | ||
| 484 | } | ||
| 485 | |||
| 486 | void ERR_unload_strings(int lib, ERR_STRING_DATA *str) | ||
| 487 | { | ||
| 488 | while (str->error) | ||
| 489 | { | ||
| 490 | if (lib) | ||
| 491 | str->error|=ERR_PACK(lib,0,0); | ||
| 492 | ERRFN(err_del_item)(str); | ||
| 493 | str++; | ||
| 494 | } | ||
| 495 | } | ||
| 496 | |||
| 497 | void ERR_free_strings(void) | ||
| 498 | { | ||
| 499 | err_fns_check(); | ||
| 500 | ERRFN(err_del)(); | ||
| 501 | } | ||
| 502 | |||
| 503 | LHASH *ERR_get_string_table(void) | ||
| 504 | { | ||
| 505 | err_fns_check(); | ||
| 506 | return ERRFN(err_get)(0); | ||
| 507 | } | ||
| 508 | |||
| 509 | LHASH *ERR_get_err_state_table(void) | ||
| 510 | { | ||
| 511 | err_fns_check(); | ||
| 512 | return ERRFN(thread_get)(0); | ||
| 513 | } | ||
| 514 | |||
| 515 | void ERR_release_err_state_table(LHASH **hash) | ||
| 516 | { | ||
| 517 | err_fns_check(); | ||
| 518 | ERRFN(thread_release)(hash); | ||
| 519 | } | ||
| 520 | |||
| 521 | const char *ERR_lib_error_string(unsigned long e) | ||
| 522 | { | ||
| 523 | ERR_STRING_DATA d,*p; | ||
| 524 | unsigned long l; | ||
| 525 | |||
| 526 | err_fns_check(); | ||
| 527 | l=ERR_GET_LIB(e); | ||
| 528 | d.error=ERR_PACK(l,0,0); | ||
| 529 | p=ERRFN(err_get_item)(&d); | ||
| 530 | return((p == NULL)?NULL:p->string); | ||
| 531 | } | ||
| 532 | |||
| 533 | const char *ERR_func_error_string(unsigned long e) | ||
| 534 | { | ||
| 535 | ERR_STRING_DATA d,*p; | ||
| 536 | unsigned long l,f; | ||
| 537 | |||
| 538 | err_fns_check(); | ||
| 539 | l=ERR_GET_LIB(e); | ||
| 540 | f=ERR_GET_FUNC(e); | ||
| 541 | d.error=ERR_PACK(l,f,0); | ||
| 542 | p=ERRFN(err_get_item)(&d); | ||
| 543 | return((p == NULL)?NULL:p->string); | ||
| 544 | } | ||
| 545 | |||
| 546 | const char *ERR_reason_error_string(unsigned long e) | ||
| 547 | { | ||
| 548 | ERR_STRING_DATA d,*p=NULL; | ||
| 549 | unsigned long l,r; | ||
| 550 | |||
| 551 | err_fns_check(); | ||
| 552 | l=ERR_GET_LIB(e); | ||
| 553 | r=ERR_GET_REASON(e); | ||
| 554 | d.error=ERR_PACK(l,0,r); | ||
| 555 | p=ERRFN(err_get_item)(&d); | ||
| 556 | if (!p) | ||
| 557 | { | ||
| 558 | d.error=ERR_PACK(0,0,r); | ||
| 559 | p=ERRFN(err_get_item)(&d); | ||
| 560 | } | ||
| 561 | return((p == NULL)?NULL:p->string); | ||
| 562 | } | ||
| 563 | |||
| 564 | /* static unsigned long err_hash(ERR_STRING_DATA *a) */ | ||
| 565 | static unsigned long err_hash(const void *a_void) | ||
| 566 | { | ||
| 567 | unsigned long ret,l; | ||
| 568 | |||
| 569 | l=((const ERR_STRING_DATA *)a_void)->error; | ||
| 570 | ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l); | ||
| 571 | return(ret^ret%19*13); | ||
| 572 | } | ||
| 573 | |||
| 574 | /* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */ | ||
| 575 | static int err_cmp(const void *a_void, const void *b_void) | ||
| 576 | { | ||
| 577 | return((int)(((const ERR_STRING_DATA *)a_void)->error - | ||
| 578 | ((const ERR_STRING_DATA *)b_void)->error)); | ||
| 579 | } | ||
| 580 | |||
| 581 | /* static unsigned long pid_hash(ERR_STATE *a) */ | ||
| 582 | static unsigned long pid_hash(const void *a_void) | ||
| 583 | { | ||
| 584 | return(((const ERR_STATE *)a_void)->pid*13); | ||
| 585 | } | ||
| 586 | |||
| 587 | /* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */ | ||
| 588 | static int pid_cmp(const void *a_void, const void *b_void) | ||
| 589 | { | ||
| 590 | return((int)((long)((const ERR_STATE *)a_void)->pid - | ||
| 591 | (long)((const ERR_STATE *)b_void)->pid)); | ||
| 592 | } | ||
| 593 | #ifdef OPENSSL_FIPS | ||
| 594 | static void int_err_remove_state(unsigned long pid) | ||
| 595 | #else | ||
| 596 | void ERR_remove_state(unsigned long pid) | ||
| 597 | #endif | ||
| 598 | { | ||
| 599 | ERR_STATE tmp; | ||
| 600 | |||
| 601 | err_fns_check(); | ||
| 602 | if (pid == 0) | ||
| 603 | pid=(unsigned long)CRYPTO_thread_id(); | ||
| 604 | tmp.pid=pid; | ||
| 605 | /* thread_del_item automatically destroys the LHASH if the number of | ||
| 606 | * items reaches zero. */ | ||
| 607 | ERRFN(thread_del_item)(&tmp); | ||
| 608 | } | ||
| 609 | |||
| 610 | #ifdef OPENSSL_FIPS | ||
| 611 | static ERR_STATE *int_err_get_state(void) | ||
| 612 | #else | ||
| 613 | ERR_STATE *ERR_get_state(void) | ||
| 614 | #endif | ||
| 615 | { | ||
| 616 | static ERR_STATE fallback; | ||
| 617 | ERR_STATE *ret,tmp,*tmpp=NULL; | ||
| 618 | int i; | ||
| 619 | unsigned long pid; | ||
| 620 | |||
| 621 | err_fns_check(); | ||
| 622 | pid=(unsigned long)CRYPTO_thread_id(); | ||
| 623 | tmp.pid=pid; | ||
| 624 | ret=ERRFN(thread_get_item)(&tmp); | ||
| 625 | |||
| 626 | /* ret == the error state, if NULL, make a new one */ | ||
| 627 | if (ret == NULL) | ||
| 628 | { | ||
| 629 | ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE)); | ||
| 630 | if (ret == NULL) return(&fallback); | ||
| 631 | ret->pid=pid; | ||
| 632 | ret->top=0; | ||
| 633 | ret->bottom=0; | ||
| 634 | for (i=0; i<ERR_NUM_ERRORS; i++) | ||
| 635 | { | ||
| 636 | ret->err_data[i]=NULL; | ||
| 637 | ret->err_data_flags[i]=0; | ||
| 638 | } | ||
| 639 | tmpp = ERRFN(thread_set_item)(ret); | ||
| 640 | /* To check if insertion failed, do a get. */ | ||
| 641 | if (ERRFN(thread_get_item)(ret) != ret) | ||
| 642 | { | ||
| 643 | ERR_STATE_free(ret); /* could not insert it */ | ||
| 644 | return(&fallback); | ||
| 645 | } | ||
| 646 | /* If a race occured in this function and we came second, tmpp | ||
| 647 | * is the first one that we just replaced. */ | ||
| 648 | if (tmpp) | ||
| 649 | ERR_STATE_free(tmpp); | ||
| 650 | } | ||
| 651 | return ret; | ||
| 652 | } | ||
| 653 | |||
| 654 | #ifdef OPENSSL_FIPS | ||
| 655 | void int_ERR_lib_init(void) | ||
| 656 | { | ||
| 657 | int_ERR_set_state_func(int_err_get_state, int_err_remove_state); | ||
| 658 | } | ||
| 659 | #endif | ||
| 660 | |||
| 661 | int ERR_get_next_error_library(void) | ||
| 662 | { | ||
| 663 | err_fns_check(); | ||
| 664 | return ERRFN(get_next_lib)(); | ||
| 665 | } | ||
diff --git a/src/lib/libcrypto/err/err_str.c b/src/lib/libcrypto/err/err_str.c deleted file mode 100644 index d39040888d..0000000000 --- a/src/lib/libcrypto/err/err_str.c +++ /dev/null | |||
| @@ -1,295 +0,0 @@ | |||
| 1 | /* crypto/err/err_str.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | /* ==================================================================== | ||
| 59 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
| 60 | * | ||
| 61 | * Redistribution and use in source and binary forms, with or without | ||
| 62 | * modification, are permitted provided that the following conditions | ||
| 63 | * are met: | ||
| 64 | * | ||
| 65 | * 1. Redistributions of source code must retain the above copyright | ||
| 66 | * notice, this list of conditions and the following disclaimer. | ||
| 67 | * | ||
| 68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 69 | * notice, this list of conditions and the following disclaimer in | ||
| 70 | * the documentation and/or other materials provided with the | ||
| 71 | * distribution. | ||
| 72 | * | ||
| 73 | * 3. All advertising materials mentioning features or use of this | ||
| 74 | * software must display the following acknowledgment: | ||
| 75 | * "This product includes software developed by the OpenSSL Project | ||
| 76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 77 | * | ||
| 78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 79 | * endorse or promote products derived from this software without | ||
| 80 | * prior written permission. For written permission, please contact | ||
| 81 | * openssl-core@openssl.org. | ||
| 82 | * | ||
| 83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 84 | * nor may "OpenSSL" appear in their names without prior written | ||
| 85 | * permission of the OpenSSL Project. | ||
| 86 | * | ||
| 87 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 88 | * acknowledgment: | ||
| 89 | * "This product includes software developed by the OpenSSL Project | ||
| 90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 91 | * | ||
| 92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 104 | * ==================================================================== | ||
| 105 | * | ||
| 106 | * This product includes cryptographic software written by Eric Young | ||
| 107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 108 | * Hudson (tjh@cryptsoft.com). | ||
| 109 | * | ||
| 110 | */ | ||
| 111 | |||
| 112 | #include <stdio.h> | ||
| 113 | #include <stdarg.h> | ||
| 114 | #include <string.h> | ||
| 115 | #include "cryptlib.h" | ||
| 116 | #include <openssl/lhash.h> | ||
| 117 | #include <openssl/crypto.h> | ||
| 118 | #include <openssl/buffer.h> | ||
| 119 | #include <openssl/bio.h> | ||
| 120 | #include <openssl/err.h> | ||
| 121 | |||
| 122 | #ifndef OPENSSL_NO_ERR | ||
| 123 | static ERR_STRING_DATA ERR_str_libraries[]= | ||
| 124 | { | ||
| 125 | {ERR_PACK(ERR_LIB_NONE,0,0) ,"unknown library"}, | ||
| 126 | {ERR_PACK(ERR_LIB_SYS,0,0) ,"system library"}, | ||
| 127 | {ERR_PACK(ERR_LIB_BN,0,0) ,"bignum routines"}, | ||
| 128 | {ERR_PACK(ERR_LIB_RSA,0,0) ,"rsa routines"}, | ||
| 129 | {ERR_PACK(ERR_LIB_DH,0,0) ,"Diffie-Hellman routines"}, | ||
| 130 | {ERR_PACK(ERR_LIB_EVP,0,0) ,"digital envelope routines"}, | ||
| 131 | {ERR_PACK(ERR_LIB_BUF,0,0) ,"memory buffer routines"}, | ||
| 132 | {ERR_PACK(ERR_LIB_OBJ,0,0) ,"object identifier routines"}, | ||
| 133 | {ERR_PACK(ERR_LIB_PEM,0,0) ,"PEM routines"}, | ||
| 134 | {ERR_PACK(ERR_LIB_DSA,0,0) ,"dsa routines"}, | ||
| 135 | {ERR_PACK(ERR_LIB_X509,0,0) ,"x509 certificate routines"}, | ||
| 136 | {ERR_PACK(ERR_LIB_ASN1,0,0) ,"asn1 encoding routines"}, | ||
| 137 | {ERR_PACK(ERR_LIB_CONF,0,0) ,"configuration file routines"}, | ||
| 138 | {ERR_PACK(ERR_LIB_CRYPTO,0,0) ,"common libcrypto routines"}, | ||
| 139 | {ERR_PACK(ERR_LIB_EC,0,0) ,"elliptic curve routines"}, | ||
| 140 | {ERR_PACK(ERR_LIB_SSL,0,0) ,"SSL routines"}, | ||
| 141 | {ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"}, | ||
| 142 | {ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"}, | ||
| 143 | {ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"}, | ||
| 144 | {ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"}, | ||
| 145 | {ERR_PACK(ERR_LIB_RAND,0,0) ,"random number generator"}, | ||
| 146 | {ERR_PACK(ERR_LIB_DSO,0,0) ,"DSO support routines"}, | ||
| 147 | {ERR_PACK(ERR_LIB_ENGINE,0,0) ,"engine routines"}, | ||
| 148 | {ERR_PACK(ERR_LIB_OCSP,0,0) ,"OCSP routines"}, | ||
| 149 | {ERR_PACK(ERR_LIB_FIPS,0,0) ,"FIPS routines"}, | ||
| 150 | {ERR_PACK(ERR_LIB_CMS,0,0) ,"CMS routines"}, | ||
| 151 | {ERR_PACK(ERR_LIB_JPAKE,0,0) ,"JPAKE routines"}, | ||
| 152 | {0,NULL}, | ||
| 153 | }; | ||
| 154 | |||
| 155 | static ERR_STRING_DATA ERR_str_functs[]= | ||
| 156 | { | ||
| 157 | {ERR_PACK(0,SYS_F_FOPEN,0), "fopen"}, | ||
| 158 | {ERR_PACK(0,SYS_F_CONNECT,0), "connect"}, | ||
| 159 | {ERR_PACK(0,SYS_F_GETSERVBYNAME,0), "getservbyname"}, | ||
| 160 | {ERR_PACK(0,SYS_F_SOCKET,0), "socket"}, | ||
| 161 | {ERR_PACK(0,SYS_F_IOCTLSOCKET,0), "ioctlsocket"}, | ||
| 162 | {ERR_PACK(0,SYS_F_BIND,0), "bind"}, | ||
| 163 | {ERR_PACK(0,SYS_F_LISTEN,0), "listen"}, | ||
| 164 | {ERR_PACK(0,SYS_F_ACCEPT,0), "accept"}, | ||
| 165 | #ifdef OPENSSL_SYS_WINDOWS | ||
| 166 | {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"}, | ||
| 167 | #endif | ||
| 168 | {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"}, | ||
| 169 | {ERR_PACK(0,SYS_F_FREAD,0), "fread"}, | ||
| 170 | {0,NULL}, | ||
| 171 | }; | ||
| 172 | |||
| 173 | static ERR_STRING_DATA ERR_str_reasons[]= | ||
| 174 | { | ||
| 175 | {ERR_R_SYS_LIB ,"system lib"}, | ||
| 176 | {ERR_R_BN_LIB ,"BN lib"}, | ||
| 177 | {ERR_R_RSA_LIB ,"RSA lib"}, | ||
| 178 | {ERR_R_DH_LIB ,"DH lib"}, | ||
| 179 | {ERR_R_EVP_LIB ,"EVP lib"}, | ||
| 180 | {ERR_R_BUF_LIB ,"BUF lib"}, | ||
| 181 | {ERR_R_OBJ_LIB ,"OBJ lib"}, | ||
| 182 | {ERR_R_PEM_LIB ,"PEM lib"}, | ||
| 183 | {ERR_R_DSA_LIB ,"DSA lib"}, | ||
| 184 | {ERR_R_X509_LIB ,"X509 lib"}, | ||
| 185 | {ERR_R_ASN1_LIB ,"ASN1 lib"}, | ||
| 186 | {ERR_R_CONF_LIB ,"CONF lib"}, | ||
| 187 | {ERR_R_CRYPTO_LIB ,"CRYPTO lib"}, | ||
| 188 | {ERR_R_EC_LIB ,"EC lib"}, | ||
| 189 | {ERR_R_SSL_LIB ,"SSL lib"}, | ||
| 190 | {ERR_R_BIO_LIB ,"BIO lib"}, | ||
| 191 | {ERR_R_PKCS7_LIB ,"PKCS7 lib"}, | ||
| 192 | {ERR_R_X509V3_LIB ,"X509V3 lib"}, | ||
| 193 | {ERR_R_PKCS12_LIB ,"PKCS12 lib"}, | ||
| 194 | {ERR_R_RAND_LIB ,"RAND lib"}, | ||
| 195 | {ERR_R_DSO_LIB ,"DSO lib"}, | ||
| 196 | {ERR_R_ENGINE_LIB ,"ENGINE lib"}, | ||
| 197 | {ERR_R_OCSP_LIB ,"OCSP lib"}, | ||
| 198 | |||
| 199 | {ERR_R_NESTED_ASN1_ERROR ,"nested asn1 error"}, | ||
| 200 | {ERR_R_BAD_ASN1_OBJECT_HEADER ,"bad asn1 object header"}, | ||
| 201 | {ERR_R_BAD_GET_ASN1_OBJECT_CALL ,"bad get asn1 object call"}, | ||
| 202 | {ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"}, | ||
| 203 | {ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"}, | ||
| 204 | {ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"}, | ||
| 205 | |||
| 206 | {ERR_R_FATAL ,"fatal"}, | ||
| 207 | {ERR_R_MALLOC_FAILURE ,"malloc failure"}, | ||
| 208 | {ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"}, | ||
| 209 | {ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"}, | ||
| 210 | {ERR_R_INTERNAL_ERROR ,"internal error"}, | ||
| 211 | {ERR_R_DISABLED ,"called a function that was disabled at compile-time"}, | ||
| 212 | |||
| 213 | {0,NULL}, | ||
| 214 | }; | ||
| 215 | #endif | ||
| 216 | |||
| 217 | #ifndef OPENSSL_NO_ERR | ||
| 218 | #define NUM_SYS_STR_REASONS 127 | ||
| 219 | #define LEN_SYS_STR_REASON 32 | ||
| 220 | |||
| 221 | static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1]; | ||
| 222 | /* SYS_str_reasons is filled with copies of strerror() results at | ||
| 223 | * initialization. | ||
| 224 | * 'errno' values up to 127 should cover all usual errors, | ||
| 225 | * others will be displayed numerically by ERR_error_string. | ||
| 226 | * It is crucial that we have something for each reason code | ||
| 227 | * that occurs in ERR_str_reasons, or bogus reason strings | ||
| 228 | * will be returned for SYSerr, which always gets an errno | ||
| 229 | * value and never one of those 'standard' reason codes. */ | ||
| 230 | |||
| 231 | static void build_SYS_str_reasons(void) | ||
| 232 | { | ||
| 233 | /* OPENSSL_malloc cannot be used here, use static storage instead */ | ||
| 234 | static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON]; | ||
| 235 | int i; | ||
| 236 | static int init = 1; | ||
| 237 | |||
| 238 | CRYPTO_r_lock(CRYPTO_LOCK_ERR); | ||
| 239 | if (!init) | ||
| 240 | { | ||
| 241 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR); | ||
| 242 | return; | ||
| 243 | } | ||
| 244 | |||
| 245 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR); | ||
| 246 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 247 | if (!init) | ||
| 248 | { | ||
| 249 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 250 | return; | ||
| 251 | } | ||
| 252 | |||
| 253 | for (i = 1; i <= NUM_SYS_STR_REASONS; i++) | ||
| 254 | { | ||
| 255 | ERR_STRING_DATA *str = &SYS_str_reasons[i - 1]; | ||
| 256 | |||
| 257 | str->error = (unsigned long)i; | ||
| 258 | if (str->string == NULL) | ||
| 259 | { | ||
| 260 | char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]); | ||
| 261 | char *src = strerror(i); | ||
| 262 | if (src != NULL) | ||
| 263 | { | ||
| 264 | strncpy(*dest, src, sizeof *dest); | ||
| 265 | (*dest)[sizeof *dest - 1] = '\0'; | ||
| 266 | str->string = *dest; | ||
| 267 | } | ||
| 268 | } | ||
| 269 | if (str->string == NULL) | ||
| 270 | str->string = "unknown"; | ||
| 271 | } | ||
| 272 | |||
| 273 | /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL}, | ||
| 274 | * as required by ERR_load_strings. */ | ||
| 275 | |||
| 276 | init = 0; | ||
| 277 | |||
| 278 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 279 | } | ||
| 280 | #endif | ||
| 281 | |||
| 282 | void ERR_load_ERR_strings(void) | ||
| 283 | { | ||
| 284 | #ifndef OPENSSL_NO_ERR | ||
| 285 | if (ERR_func_error_string(ERR_str_functs[0].error) == NULL) | ||
| 286 | { | ||
| 287 | ERR_load_strings(0,ERR_str_libraries); | ||
| 288 | ERR_load_strings(0,ERR_str_reasons); | ||
| 289 | ERR_load_strings(ERR_LIB_SYS,ERR_str_functs); | ||
| 290 | build_SYS_str_reasons(); | ||
| 291 | ERR_load_strings(ERR_LIB_SYS,SYS_str_reasons); | ||
| 292 | } | ||
| 293 | #endif | ||
| 294 | } | ||
| 295 | |||
diff --git a/src/lib/libcrypto/evp/e_seed.c b/src/lib/libcrypto/evp/e_seed.c new file mode 100644 index 0000000000..2d1759d276 --- /dev/null +++ b/src/lib/libcrypto/evp/e_seed.c | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | /* crypto/evp/e_seed.c -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 2007 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | #include <openssl/opensslconf.h> | ||
| 57 | #ifndef OPENSSL_NO_SEED | ||
| 58 | #include <openssl/evp.h> | ||
| 59 | #include <openssl/err.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <assert.h> | ||
| 62 | #include <openssl/seed.h> | ||
| 63 | #include "evp_locl.h" | ||
| 64 | |||
| 65 | static int seed_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc); | ||
| 66 | |||
| 67 | typedef struct | ||
| 68 | { | ||
| 69 | SEED_KEY_SCHEDULE ks; | ||
| 70 | } EVP_SEED_KEY; | ||
| 71 | |||
| 72 | IMPLEMENT_BLOCK_CIPHER(seed, ks, SEED, EVP_SEED_KEY, NID_seed, | ||
| 73 | 16, 16, 16, 128, | ||
| 74 | 0, seed_init_key, 0, 0, 0, 0) | ||
| 75 | |||
| 76 | static int seed_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 77 | const unsigned char *iv, int enc) | ||
| 78 | { | ||
| 79 | SEED_set_key(key, ctx->cipher_data); | ||
| 80 | return 1; | ||
| 81 | } | ||
| 82 | |||
| 83 | #endif | ||
diff --git a/src/lib/libcrypto/evp/enc_min.c b/src/lib/libcrypto/evp/enc_min.c deleted file mode 100644 index 7fba38ee24..0000000000 --- a/src/lib/libcrypto/evp/enc_min.c +++ /dev/null | |||
| @@ -1,390 +0,0 @@ | |||
| 1 | /* crypto/evp/enc_min.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/evp.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | #ifndef OPENSSL_NO_ENGINE | ||
| 65 | #include <openssl/engine.h> | ||
| 66 | #endif | ||
| 67 | #include "evp_locl.h" | ||
| 68 | |||
| 69 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) | ||
| 70 | { | ||
| 71 | #ifdef OPENSSL_FIPS | ||
| 72 | FIPS_selftest_check(); | ||
| 73 | #endif | ||
| 74 | memset(ctx,0,sizeof(EVP_CIPHER_CTX)); | ||
| 75 | /* ctx->cipher=NULL; */ | ||
| 76 | } | ||
| 77 | |||
| 78 | #ifdef OPENSSL_FIPS | ||
| 79 | |||
| 80 | /* The purpose of these is to trap programs that attempt to use non FIPS | ||
| 81 | * algorithms in FIPS mode and ignore the errors. | ||
| 82 | */ | ||
| 83 | |||
| 84 | static int bad_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 85 | const unsigned char *iv, int enc) | ||
| 86 | { FIPS_ERROR_IGNORED("Cipher init"); return 0;} | ||
| 87 | |||
| 88 | static int bad_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 89 | const unsigned char *in, unsigned int inl) | ||
| 90 | { FIPS_ERROR_IGNORED("Cipher update"); return 0;} | ||
| 91 | |||
| 92 | /* NB: no cleanup because it is allowed after failed init */ | ||
| 93 | |||
| 94 | static int bad_set_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ) | ||
| 95 | { FIPS_ERROR_IGNORED("Cipher set_asn1"); return 0;} | ||
| 96 | static int bad_get_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ) | ||
| 97 | { FIPS_ERROR_IGNORED("Cipher get_asn1"); return 0;} | ||
| 98 | static int bad_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) | ||
| 99 | { FIPS_ERROR_IGNORED("Cipher ctrl"); return 0;} | ||
| 100 | |||
| 101 | static const EVP_CIPHER bad_cipher = | ||
| 102 | { | ||
| 103 | 0, | ||
| 104 | 0, | ||
| 105 | 0, | ||
| 106 | 0, | ||
| 107 | 0, | ||
| 108 | bad_init, | ||
| 109 | bad_do_cipher, | ||
| 110 | NULL, | ||
| 111 | 0, | ||
| 112 | bad_set_asn1, | ||
| 113 | bad_get_asn1, | ||
| 114 | bad_ctrl, | ||
| 115 | NULL | ||
| 116 | }; | ||
| 117 | |||
| 118 | #endif | ||
| 119 | |||
| 120 | #ifndef OPENSSL_NO_ENGINE | ||
| 121 | |||
| 122 | #ifdef OPENSSL_FIPS | ||
| 123 | |||
| 124 | static int do_engine_null(ENGINE *impl) { return 0;} | ||
| 125 | static int do_evp_enc_engine_null(EVP_CIPHER_CTX *ctx, | ||
| 126 | const EVP_CIPHER **pciph, ENGINE *impl) | ||
| 127 | { return 1; } | ||
| 128 | |||
| 129 | static int (*do_engine_finish)(ENGINE *impl) | ||
| 130 | = do_engine_null; | ||
| 131 | |||
| 132 | static int (*do_evp_enc_engine) | ||
| 133 | (EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pciph, ENGINE *impl) | ||
| 134 | = do_evp_enc_engine_null; | ||
| 135 | |||
| 136 | void int_EVP_CIPHER_set_engine_callbacks( | ||
| 137 | int (*eng_ciph_fin)(ENGINE *impl), | ||
| 138 | int (*eng_ciph_evp) | ||
| 139 | (EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pciph, ENGINE *impl)) | ||
| 140 | { | ||
| 141 | do_engine_finish = eng_ciph_fin; | ||
| 142 | do_evp_enc_engine = eng_ciph_evp; | ||
| 143 | } | ||
| 144 | |||
| 145 | #else | ||
| 146 | |||
| 147 | #define do_engine_finish ENGINE_finish | ||
| 148 | |||
| 149 | static int do_evp_enc_engine(EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pcipher, ENGINE *impl) | ||
| 150 | { | ||
| 151 | if(impl) | ||
| 152 | { | ||
| 153 | if (!ENGINE_init(impl)) | ||
| 154 | { | ||
| 155 | EVPerr(EVP_F_DO_EVP_ENC_ENGINE, EVP_R_INITIALIZATION_ERROR); | ||
| 156 | return 0; | ||
| 157 | } | ||
| 158 | } | ||
| 159 | else | ||
| 160 | /* Ask if an ENGINE is reserved for this job */ | ||
| 161 | impl = ENGINE_get_cipher_engine((*pcipher)->nid); | ||
| 162 | if(impl) | ||
| 163 | { | ||
| 164 | /* There's an ENGINE for this job ... (apparently) */ | ||
| 165 | const EVP_CIPHER *c = ENGINE_get_cipher(impl, (*pcipher)->nid); | ||
| 166 | if(!c) | ||
| 167 | { | ||
| 168 | /* One positive side-effect of US's export | ||
| 169 | * control history, is that we should at least | ||
| 170 | * be able to avoid using US mispellings of | ||
| 171 | * "initialisation"? */ | ||
| 172 | EVPerr(EVP_F_DO_EVP_ENC_ENGINE, EVP_R_INITIALIZATION_ERROR); | ||
| 173 | return 0; | ||
| 174 | } | ||
| 175 | /* We'll use the ENGINE's private cipher definition */ | ||
| 176 | *pcipher = c; | ||
| 177 | /* Store the ENGINE functional reference so we know | ||
| 178 | * 'cipher' came from an ENGINE and we need to release | ||
| 179 | * it when done. */ | ||
| 180 | ctx->engine = impl; | ||
| 181 | } | ||
| 182 | else | ||
| 183 | ctx->engine = NULL; | ||
| 184 | return 1; | ||
| 185 | } | ||
| 186 | |||
| 187 | #endif | ||
| 188 | |||
| 189 | #endif | ||
| 190 | |||
| 191 | int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | ||
| 192 | const unsigned char *key, const unsigned char *iv, int enc) | ||
| 193 | { | ||
| 194 | if (enc == -1) | ||
| 195 | enc = ctx->encrypt; | ||
| 196 | else | ||
| 197 | { | ||
| 198 | if (enc) | ||
| 199 | enc = 1; | ||
| 200 | ctx->encrypt = enc; | ||
| 201 | } | ||
| 202 | #ifdef OPENSSL_FIPS | ||
| 203 | if(FIPS_selftest_failed()) | ||
| 204 | { | ||
| 205 | FIPSerr(FIPS_F_EVP_CIPHERINIT_EX,FIPS_R_FIPS_SELFTEST_FAILED); | ||
| 206 | ctx->cipher = &bad_cipher; | ||
| 207 | return 0; | ||
| 208 | } | ||
| 209 | #endif | ||
| 210 | #ifndef OPENSSL_NO_ENGINE | ||
| 211 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts | ||
| 212 | * so this context may already have an ENGINE! Try to avoid releasing | ||
| 213 | * the previous handle, re-querying for an ENGINE, and having a | ||
| 214 | * reinitialisation, when it may all be unecessary. */ | ||
| 215 | if (ctx->engine && ctx->cipher && (!cipher || | ||
| 216 | (cipher && (cipher->nid == ctx->cipher->nid)))) | ||
| 217 | goto skip_to_init; | ||
| 218 | #endif | ||
| 219 | if (cipher) | ||
| 220 | { | ||
| 221 | /* Ensure a context left lying around from last time is cleared | ||
| 222 | * (the previous check attempted to avoid this if the same | ||
| 223 | * ENGINE and EVP_CIPHER could be used). */ | ||
| 224 | EVP_CIPHER_CTX_cleanup(ctx); | ||
| 225 | |||
| 226 | /* Restore encrypt field: it is zeroed by cleanup */ | ||
| 227 | ctx->encrypt = enc; | ||
| 228 | #ifndef OPENSSL_NO_ENGINE | ||
| 229 | if (!do_evp_enc_engine(ctx, &cipher, impl)) | ||
| 230 | return 0; | ||
| 231 | #endif | ||
| 232 | |||
| 233 | ctx->cipher=cipher; | ||
| 234 | if (ctx->cipher->ctx_size) | ||
| 235 | { | ||
| 236 | ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size); | ||
| 237 | if (!ctx->cipher_data) | ||
| 238 | { | ||
| 239 | EVPerr(EVP_F_EVP_CIPHERINIT_EX, ERR_R_MALLOC_FAILURE); | ||
| 240 | return 0; | ||
| 241 | } | ||
| 242 | } | ||
| 243 | else | ||
| 244 | { | ||
| 245 | ctx->cipher_data = NULL; | ||
| 246 | } | ||
| 247 | ctx->key_len = cipher->key_len; | ||
| 248 | ctx->flags = 0; | ||
| 249 | if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT) | ||
| 250 | { | ||
| 251 | if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) | ||
| 252 | { | ||
| 253 | EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR); | ||
| 254 | return 0; | ||
| 255 | } | ||
| 256 | } | ||
| 257 | } | ||
| 258 | else if(!ctx->cipher) | ||
| 259 | { | ||
| 260 | EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_NO_CIPHER_SET); | ||
| 261 | return 0; | ||
| 262 | } | ||
| 263 | #ifndef OPENSSL_NO_ENGINE | ||
| 264 | skip_to_init: | ||
| 265 | #endif | ||
| 266 | /* we assume block size is a power of 2 in *cryptUpdate */ | ||
| 267 | OPENSSL_assert(ctx->cipher->block_size == 1 | ||
| 268 | || ctx->cipher->block_size == 8 | ||
| 269 | || ctx->cipher->block_size == 16); | ||
| 270 | |||
| 271 | if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) { | ||
| 272 | switch(EVP_CIPHER_CTX_mode(ctx)) { | ||
| 273 | |||
| 274 | case EVP_CIPH_STREAM_CIPHER: | ||
| 275 | case EVP_CIPH_ECB_MODE: | ||
| 276 | break; | ||
| 277 | |||
| 278 | case EVP_CIPH_CFB_MODE: | ||
| 279 | case EVP_CIPH_OFB_MODE: | ||
| 280 | |||
| 281 | ctx->num = 0; | ||
| 282 | |||
| 283 | case EVP_CIPH_CBC_MODE: | ||
| 284 | |||
| 285 | OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <= | ||
| 286 | (int)sizeof(ctx->iv)); | ||
| 287 | if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); | ||
| 288 | memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); | ||
| 289 | break; | ||
| 290 | |||
| 291 | default: | ||
| 292 | return 0; | ||
| 293 | break; | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 297 | #ifdef OPENSSL_FIPS | ||
| 298 | /* After 'key' is set no further parameters changes are permissible. | ||
| 299 | * So only check for non FIPS enabling at this point. | ||
| 300 | */ | ||
| 301 | if (key && FIPS_mode()) | ||
| 302 | { | ||
| 303 | if (!(ctx->cipher->flags & EVP_CIPH_FLAG_FIPS) | ||
| 304 | & !(ctx->flags & EVP_CIPH_FLAG_NON_FIPS_ALLOW)) | ||
| 305 | { | ||
| 306 | EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_DISABLED_FOR_FIPS); | ||
| 307 | #if 0 | ||
| 308 | ERR_add_error_data(2, "cipher=", | ||
| 309 | EVP_CIPHER_name(ctx->cipher)); | ||
| 310 | #endif | ||
| 311 | ctx->cipher = &bad_cipher; | ||
| 312 | return 0; | ||
| 313 | } | ||
| 314 | } | ||
| 315 | #endif | ||
| 316 | |||
| 317 | if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) { | ||
| 318 | if(!ctx->cipher->init(ctx,key,iv,enc)) return 0; | ||
| 319 | } | ||
| 320 | ctx->buf_len=0; | ||
| 321 | ctx->final_used=0; | ||
| 322 | ctx->block_mask=ctx->cipher->block_size-1; | ||
| 323 | return 1; | ||
| 324 | } | ||
| 325 | |||
| 326 | int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) | ||
| 327 | { | ||
| 328 | if (c->cipher != NULL) | ||
| 329 | { | ||
| 330 | if(c->cipher->cleanup && !c->cipher->cleanup(c)) | ||
| 331 | return 0; | ||
| 332 | /* Cleanse cipher context data */ | ||
| 333 | if (c->cipher_data) | ||
| 334 | OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size); | ||
| 335 | } | ||
| 336 | if (c->cipher_data) | ||
| 337 | OPENSSL_free(c->cipher_data); | ||
| 338 | #ifndef OPENSSL_NO_ENGINE | ||
| 339 | if (c->engine) | ||
| 340 | /* The EVP_CIPHER we used belongs to an ENGINE, release the | ||
| 341 | * functional reference we held for this reason. */ | ||
| 342 | do_engine_finish(c->engine); | ||
| 343 | #endif | ||
| 344 | memset(c,0,sizeof(EVP_CIPHER_CTX)); | ||
| 345 | return 1; | ||
| 346 | } | ||
| 347 | |||
| 348 | int EVP_Cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) | ||
| 349 | { | ||
| 350 | #ifdef OPENSSL_FIPS | ||
| 351 | FIPS_selftest_check(); | ||
| 352 | #endif | ||
| 353 | return ctx->cipher->do_cipher(ctx,out,in,inl); | ||
| 354 | } | ||
| 355 | |||
| 356 | int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) | ||
| 357 | { | ||
| 358 | int ret; | ||
| 359 | if(!ctx->cipher) { | ||
| 360 | EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_NO_CIPHER_SET); | ||
| 361 | return 0; | ||
| 362 | } | ||
| 363 | |||
| 364 | if(!ctx->cipher->ctrl) { | ||
| 365 | EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED); | ||
| 366 | return 0; | ||
| 367 | } | ||
| 368 | |||
| 369 | ret = ctx->cipher->ctrl(ctx, type, arg, ptr); | ||
| 370 | if(ret == -1) { | ||
| 371 | EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED); | ||
| 372 | return 0; | ||
| 373 | } | ||
| 374 | return ret; | ||
| 375 | } | ||
| 376 | |||
| 377 | unsigned long EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx) | ||
| 378 | { | ||
| 379 | return ctx->cipher->flags; | ||
| 380 | } | ||
| 381 | |||
| 382 | int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx) | ||
| 383 | { | ||
| 384 | return ctx->cipher->iv_len; | ||
| 385 | } | ||
| 386 | |||
| 387 | int EVP_CIPHER_nid(const EVP_CIPHER *cipher) | ||
| 388 | { | ||
| 389 | return cipher->nid; | ||
| 390 | } | ||
diff --git a/src/lib/libcrypto/fips_err.c b/src/lib/libcrypto/fips_err.c deleted file mode 100644 index 09f11748f6..0000000000 --- a/src/lib/libcrypto/fips_err.c +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | #include <openssl/opensslconf.h> | ||
| 2 | |||
| 3 | #ifdef OPENSSL_FIPS | ||
| 4 | # include "fips_err.h" | ||
| 5 | #else | ||
| 6 | static void *dummy=&dummy; | ||
| 7 | #endif | ||
diff --git a/src/lib/libcrypto/jpake/Makefile b/src/lib/libcrypto/jpake/Makefile new file mode 100644 index 0000000000..110c49ce0b --- /dev/null +++ b/src/lib/libcrypto/jpake/Makefile | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | DIR=jpake | ||
| 2 | TOP=../.. | ||
| 3 | |||
| 4 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 5 | |||
| 6 | LIB=$(TOP)/libcrypto.a | ||
| 7 | LIBOBJ=jpake.o jpake_err.o | ||
| 8 | LIBSRC=jpake.c jpake_err.c | ||
| 9 | |||
| 10 | EXHEADER=jpake.h | ||
| 11 | TEST=jpaketest.c | ||
| 12 | |||
| 13 | top: | ||
| 14 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 15 | |||
| 16 | all: lib | ||
| 17 | |||
| 18 | lib: $(LIBOBJ) | ||
| 19 | $(AR) $(LIB) $(LIBOBJ) | ||
| 20 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 21 | @touch lib | ||
| 22 | |||
| 23 | links: | ||
| 24 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 25 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 26 | |||
| 27 | install: | ||
| 28 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 29 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 30 | do \ | ||
| 31 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 32 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 33 | done; | ||
| 34 | |||
| 35 | depend: | ||
| 36 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 37 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 38 | |||
| 39 | dclean: | ||
| 40 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 41 | mv -f Makefile.new $(MAKEFILE) | ||
| 42 | |||
| 43 | clean: | ||
| 44 | rm -f *.s *.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff | ||
| 45 | |||
| 46 | jpaketest: top jpaketest.c $(LIB) | ||
| 47 | $(CC) $(CFLAGS) -Wall -Werror -g -o jpaketest jpaketest.c $(LIB) | ||
| 48 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 49 | |||
| 50 | jpake.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 51 | jpake.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 52 | jpake.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
| 53 | jpake.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 54 | jpake.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 55 | jpake.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 56 | jpake.o: ../../include/openssl/symhacks.h jpake.c jpake.h | ||
| 57 | jpake_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 58 | jpake_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 59 | jpake_err.o: ../../include/openssl/err.h ../../include/openssl/jpake.h | ||
| 60 | jpake_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 61 | jpake_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 62 | jpake_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 63 | jpake_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 64 | jpake_err.o: jpake_err.c | ||
diff --git a/src/lib/libcrypto/jpake/jpake.c b/src/lib/libcrypto/jpake/jpake.c new file mode 100644 index 0000000000..086d9f47e0 --- /dev/null +++ b/src/lib/libcrypto/jpake/jpake.c | |||
| @@ -0,0 +1,482 @@ | |||
| 1 | #include "jpake.h" | ||
| 2 | |||
| 3 | #include <openssl/crypto.h> | ||
| 4 | #include <openssl/sha.h> | ||
| 5 | #include <openssl/err.h> | ||
| 6 | #include <memory.h> | ||
| 7 | |||
| 8 | /* | ||
| 9 | * In the definition, (xa, xb, xc, xd) are Alice's (x1, x2, x3, x4) or | ||
| 10 | * Bob's (x3, x4, x1, x2). If you see what I mean. | ||
| 11 | */ | ||
| 12 | |||
| 13 | typedef struct | ||
| 14 | { | ||
| 15 | char *name; /* Must be unique */ | ||
| 16 | char *peer_name; | ||
| 17 | BIGNUM *p; | ||
| 18 | BIGNUM *g; | ||
| 19 | BIGNUM *q; | ||
| 20 | BIGNUM *gxc; /* Alice's g^{x3} or Bob's g^{x1} */ | ||
| 21 | BIGNUM *gxd; /* Alice's g^{x4} or Bob's g^{x2} */ | ||
| 22 | } JPAKE_CTX_PUBLIC; | ||
| 23 | |||
| 24 | struct JPAKE_CTX | ||
| 25 | { | ||
| 26 | JPAKE_CTX_PUBLIC p; | ||
| 27 | BIGNUM *secret; /* The shared secret */ | ||
| 28 | BN_CTX *ctx; | ||
| 29 | BIGNUM *xa; /* Alice's x1 or Bob's x3 */ | ||
| 30 | BIGNUM *xb; /* Alice's x2 or Bob's x4 */ | ||
| 31 | BIGNUM *key; /* The calculated (shared) key */ | ||
| 32 | }; | ||
| 33 | |||
| 34 | static void JPAKE_ZKP_init(JPAKE_ZKP *zkp) | ||
| 35 | { | ||
| 36 | zkp->gr = BN_new(); | ||
| 37 | zkp->b = BN_new(); | ||
| 38 | } | ||
| 39 | |||
| 40 | static void JPAKE_ZKP_release(JPAKE_ZKP *zkp) | ||
| 41 | { | ||
| 42 | BN_free(zkp->b); | ||
| 43 | BN_free(zkp->gr); | ||
| 44 | } | ||
| 45 | |||
| 46 | /* Two birds with one stone - make the global name as expected */ | ||
| 47 | #define JPAKE_STEP_PART_init JPAKE_STEP2_init | ||
| 48 | #define JPAKE_STEP_PART_release JPAKE_STEP2_release | ||
| 49 | |||
| 50 | void JPAKE_STEP_PART_init(JPAKE_STEP_PART *p) | ||
| 51 | { | ||
| 52 | p->gx = BN_new(); | ||
| 53 | JPAKE_ZKP_init(&p->zkpx); | ||
| 54 | } | ||
| 55 | |||
| 56 | void JPAKE_STEP_PART_release(JPAKE_STEP_PART *p) | ||
| 57 | { | ||
| 58 | JPAKE_ZKP_release(&p->zkpx); | ||
| 59 | BN_free(p->gx); | ||
| 60 | } | ||
| 61 | |||
| 62 | void JPAKE_STEP1_init(JPAKE_STEP1 *s1) | ||
| 63 | { | ||
| 64 | JPAKE_STEP_PART_init(&s1->p1); | ||
| 65 | JPAKE_STEP_PART_init(&s1->p2); | ||
| 66 | } | ||
| 67 | |||
| 68 | void JPAKE_STEP1_release(JPAKE_STEP1 *s1) | ||
| 69 | { | ||
| 70 | JPAKE_STEP_PART_release(&s1->p2); | ||
| 71 | JPAKE_STEP_PART_release(&s1->p1); | ||
| 72 | } | ||
| 73 | |||
| 74 | static void JPAKE_CTX_init(JPAKE_CTX *ctx, const char *name, | ||
| 75 | const char *peer_name, const BIGNUM *p, | ||
| 76 | const BIGNUM *g, const BIGNUM *q, | ||
| 77 | const BIGNUM *secret) | ||
| 78 | { | ||
| 79 | ctx->p.name = OPENSSL_strdup(name); | ||
| 80 | ctx->p.peer_name = OPENSSL_strdup(peer_name); | ||
| 81 | ctx->p.p = BN_dup(p); | ||
| 82 | ctx->p.g = BN_dup(g); | ||
| 83 | ctx->p.q = BN_dup(q); | ||
| 84 | ctx->secret = BN_dup(secret); | ||
| 85 | |||
| 86 | ctx->p.gxc = BN_new(); | ||
| 87 | ctx->p.gxd = BN_new(); | ||
| 88 | |||
| 89 | ctx->xa = BN_new(); | ||
| 90 | ctx->xb = BN_new(); | ||
| 91 | ctx->key = BN_new(); | ||
| 92 | ctx->ctx = BN_CTX_new(); | ||
| 93 | } | ||
| 94 | |||
| 95 | static void JPAKE_CTX_release(JPAKE_CTX *ctx) | ||
| 96 | { | ||
| 97 | BN_CTX_free(ctx->ctx); | ||
| 98 | BN_clear_free(ctx->key); | ||
| 99 | BN_clear_free(ctx->xb); | ||
| 100 | BN_clear_free(ctx->xa); | ||
| 101 | |||
| 102 | BN_free(ctx->p.gxd); | ||
| 103 | BN_free(ctx->p.gxc); | ||
| 104 | |||
| 105 | BN_clear_free(ctx->secret); | ||
| 106 | BN_free(ctx->p.q); | ||
| 107 | BN_free(ctx->p.g); | ||
| 108 | BN_free(ctx->p.p); | ||
| 109 | OPENSSL_free(ctx->p.peer_name); | ||
| 110 | OPENSSL_free(ctx->p.name); | ||
| 111 | |||
| 112 | memset(ctx, '\0', sizeof *ctx); | ||
| 113 | } | ||
| 114 | |||
| 115 | JPAKE_CTX *JPAKE_CTX_new(const char *name, const char *peer_name, | ||
| 116 | const BIGNUM *p, const BIGNUM *g, const BIGNUM *q, | ||
| 117 | const BIGNUM *secret) | ||
| 118 | { | ||
| 119 | JPAKE_CTX *ctx = OPENSSL_malloc(sizeof *ctx); | ||
| 120 | |||
| 121 | JPAKE_CTX_init(ctx, name, peer_name, p, g, q, secret); | ||
| 122 | |||
| 123 | return ctx; | ||
| 124 | } | ||
| 125 | |||
| 126 | void JPAKE_CTX_free(JPAKE_CTX *ctx) | ||
| 127 | { | ||
| 128 | JPAKE_CTX_release(ctx); | ||
| 129 | OPENSSL_free(ctx); | ||
| 130 | } | ||
| 131 | |||
| 132 | static void hashlength(SHA_CTX *sha, size_t l) | ||
| 133 | { | ||
| 134 | unsigned char b[2]; | ||
| 135 | |||
| 136 | OPENSSL_assert(l <= 0xffff); | ||
| 137 | b[0] = l >> 8; | ||
| 138 | b[1] = l&0xff; | ||
| 139 | SHA1_Update(sha, b, 2); | ||
| 140 | } | ||
| 141 | |||
| 142 | static void hashstring(SHA_CTX *sha, const char *string) | ||
| 143 | { | ||
| 144 | size_t l = strlen(string); | ||
| 145 | |||
| 146 | hashlength(sha, l); | ||
| 147 | SHA1_Update(sha, string, l); | ||
| 148 | } | ||
| 149 | |||
| 150 | static void hashbn(SHA_CTX *sha, const BIGNUM *bn) | ||
| 151 | { | ||
| 152 | size_t l = BN_num_bytes(bn); | ||
| 153 | unsigned char *bin = OPENSSL_malloc(l); | ||
| 154 | |||
| 155 | hashlength(sha, l); | ||
| 156 | BN_bn2bin(bn, bin); | ||
| 157 | SHA1_Update(sha, bin, l); | ||
| 158 | OPENSSL_free(bin); | ||
| 159 | } | ||
| 160 | |||
| 161 | /* h=hash(g, g^r, g^x, name) */ | ||
| 162 | static void zkp_hash(BIGNUM *h, const BIGNUM *zkpg, const JPAKE_STEP_PART *p, | ||
| 163 | const char *proof_name) | ||
| 164 | { | ||
| 165 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
| 166 | SHA_CTX sha; | ||
| 167 | |||
| 168 | /* | ||
| 169 | * XXX: hash should not allow moving of the boundaries - Java code | ||
| 170 | * is flawed in this respect. Length encoding seems simplest. | ||
| 171 | */ | ||
| 172 | SHA1_Init(&sha); | ||
| 173 | hashbn(&sha, zkpg); | ||
| 174 | OPENSSL_assert(!BN_is_zero(p->zkpx.gr)); | ||
| 175 | hashbn(&sha, p->zkpx.gr); | ||
| 176 | hashbn(&sha, p->gx); | ||
| 177 | hashstring(&sha, proof_name); | ||
| 178 | SHA1_Final(md, &sha); | ||
| 179 | BN_bin2bn(md, SHA_DIGEST_LENGTH, h); | ||
| 180 | } | ||
| 181 | |||
| 182 | /* | ||
| 183 | * Prove knowledge of x | ||
| 184 | * Note that p->gx has already been calculated | ||
| 185 | */ | ||
| 186 | static void generate_zkp(JPAKE_STEP_PART *p, const BIGNUM *x, | ||
| 187 | const BIGNUM *zkpg, JPAKE_CTX *ctx) | ||
| 188 | { | ||
| 189 | BIGNUM *r = BN_new(); | ||
| 190 | BIGNUM *h = BN_new(); | ||
| 191 | BIGNUM *t = BN_new(); | ||
| 192 | |||
| 193 | /* | ||
| 194 | * r in [0,q) | ||
| 195 | * XXX: Java chooses r in [0, 2^160) - i.e. distribution not uniform | ||
| 196 | */ | ||
| 197 | BN_rand_range(r, ctx->p.q); | ||
| 198 | /* g^r */ | ||
| 199 | BN_mod_exp(p->zkpx.gr, zkpg, r, ctx->p.p, ctx->ctx); | ||
| 200 | |||
| 201 | /* h=hash... */ | ||
| 202 | zkp_hash(h, zkpg, p, ctx->p.name); | ||
| 203 | |||
| 204 | /* b = r - x*h */ | ||
| 205 | BN_mod_mul(t, x, h, ctx->p.q, ctx->ctx); | ||
| 206 | BN_mod_sub(p->zkpx.b, r, t, ctx->p.q, ctx->ctx); | ||
| 207 | |||
| 208 | /* cleanup */ | ||
| 209 | BN_free(t); | ||
| 210 | BN_free(h); | ||
| 211 | BN_free(r); | ||
| 212 | } | ||
| 213 | |||
| 214 | static int verify_zkp(const JPAKE_STEP_PART *p, const BIGNUM *zkpg, | ||
| 215 | JPAKE_CTX *ctx) | ||
| 216 | { | ||
| 217 | BIGNUM *h = BN_new(); | ||
| 218 | BIGNUM *t1 = BN_new(); | ||
| 219 | BIGNUM *t2 = BN_new(); | ||
| 220 | BIGNUM *t3 = BN_new(); | ||
| 221 | int ret = 0; | ||
| 222 | |||
| 223 | zkp_hash(h, zkpg, p, ctx->p.peer_name); | ||
| 224 | |||
| 225 | /* t1 = g^b */ | ||
| 226 | BN_mod_exp(t1, zkpg, p->zkpx.b, ctx->p.p, ctx->ctx); | ||
| 227 | /* t2 = (g^x)^h = g^{hx} */ | ||
| 228 | BN_mod_exp(t2, p->gx, h, ctx->p.p, ctx->ctx); | ||
| 229 | /* t3 = t1 * t2 = g^{hx} * g^b = g^{hx+b} = g^r (allegedly) */ | ||
| 230 | BN_mod_mul(t3, t1, t2, ctx->p.p, ctx->ctx); | ||
| 231 | |||
| 232 | /* verify t3 == g^r */ | ||
| 233 | if(BN_cmp(t3, p->zkpx.gr) == 0) | ||
| 234 | ret = 1; | ||
| 235 | else | ||
| 236 | JPAKEerr(JPAKE_F_VERIFY_ZKP, JPAKE_R_ZKP_VERIFY_FAILED); | ||
| 237 | |||
| 238 | /* cleanup */ | ||
| 239 | BN_free(t3); | ||
| 240 | BN_free(t2); | ||
| 241 | BN_free(t1); | ||
| 242 | BN_free(h); | ||
| 243 | |||
| 244 | return ret; | ||
| 245 | } | ||
| 246 | |||
| 247 | static void generate_step_part(JPAKE_STEP_PART *p, const BIGNUM *x, | ||
| 248 | const BIGNUM *g, JPAKE_CTX *ctx) | ||
| 249 | { | ||
| 250 | BN_mod_exp(p->gx, g, x, ctx->p.p, ctx->ctx); | ||
| 251 | generate_zkp(p, x, g, ctx); | ||
| 252 | } | ||
| 253 | |||
| 254 | /* Generate each party's random numbers. xa is in [0, q), xb is in [1, q). */ | ||
| 255 | static void genrand(JPAKE_CTX *ctx) | ||
| 256 | { | ||
| 257 | BIGNUM *qm1; | ||
| 258 | |||
| 259 | /* xa in [0, q) */ | ||
| 260 | BN_rand_range(ctx->xa, ctx->p.q); | ||
| 261 | |||
| 262 | /* q-1 */ | ||
| 263 | qm1 = BN_new(); | ||
| 264 | BN_copy(qm1, ctx->p.q); | ||
| 265 | BN_sub_word(qm1, 1); | ||
| 266 | |||
| 267 | /* ... and xb in [0, q-1) */ | ||
| 268 | BN_rand_range(ctx->xb, qm1); | ||
| 269 | /* [1, q) */ | ||
| 270 | BN_add_word(ctx->xb, 1); | ||
| 271 | |||
| 272 | /* cleanup */ | ||
| 273 | BN_free(qm1); | ||
| 274 | } | ||
| 275 | |||
| 276 | int JPAKE_STEP1_generate(JPAKE_STEP1 *send, JPAKE_CTX *ctx) | ||
| 277 | { | ||
| 278 | genrand(ctx); | ||
| 279 | generate_step_part(&send->p1, ctx->xa, ctx->p.g, ctx); | ||
| 280 | generate_step_part(&send->p2, ctx->xb, ctx->p.g, ctx); | ||
| 281 | |||
| 282 | return 1; | ||
| 283 | } | ||
| 284 | |||
| 285 | int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received) | ||
| 286 | { | ||
| 287 | /* verify their ZKP(xc) */ | ||
| 288 | if(!verify_zkp(&received->p1, ctx->p.g, ctx)) | ||
| 289 | { | ||
| 290 | JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_VERIFY_X3_FAILED); | ||
| 291 | return 0; | ||
| 292 | } | ||
| 293 | |||
| 294 | /* verify their ZKP(xd) */ | ||
| 295 | if(!verify_zkp(&received->p2, ctx->p.g, ctx)) | ||
| 296 | { | ||
| 297 | JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_VERIFY_X4_FAILED); | ||
| 298 | return 0; | ||
| 299 | } | ||
| 300 | |||
| 301 | /* g^xd != 1 */ | ||
| 302 | if(BN_is_one(received->p2.gx)) | ||
| 303 | { | ||
| 304 | JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_G_TO_THE_X4_IS_ONE); | ||
| 305 | return 0; | ||
| 306 | } | ||
| 307 | |||
| 308 | /* Save the bits we need for later */ | ||
| 309 | BN_copy(ctx->p.gxc, received->p1.gx); | ||
| 310 | BN_copy(ctx->p.gxd, received->p2.gx); | ||
| 311 | |||
| 312 | return 1; | ||
| 313 | } | ||
| 314 | |||
| 315 | |||
| 316 | int JPAKE_STEP2_generate(JPAKE_STEP2 *send, JPAKE_CTX *ctx) | ||
| 317 | { | ||
| 318 | BIGNUM *t1 = BN_new(); | ||
| 319 | BIGNUM *t2 = BN_new(); | ||
| 320 | |||
| 321 | /* | ||
| 322 | * X = g^{(xa + xc + xd) * xb * s} | ||
| 323 | * t1 = g^xa | ||
| 324 | */ | ||
| 325 | BN_mod_exp(t1, ctx->p.g, ctx->xa, ctx->p.p, ctx->ctx); | ||
| 326 | /* t2 = t1 * g^{xc} = g^{xa} * g^{xc} = g^{xa + xc} */ | ||
| 327 | BN_mod_mul(t2, t1, ctx->p.gxc, ctx->p.p, ctx->ctx); | ||
| 328 | /* t1 = t2 * g^{xd} = g^{xa + xc + xd} */ | ||
| 329 | BN_mod_mul(t1, t2, ctx->p.gxd, ctx->p.p, ctx->ctx); | ||
| 330 | /* t2 = xb * s */ | ||
| 331 | BN_mod_mul(t2, ctx->xb, ctx->secret, ctx->p.q, ctx->ctx); | ||
| 332 | |||
| 333 | /* | ||
| 334 | * ZKP(xb * s) | ||
| 335 | * XXX: this is kinda funky, because we're using | ||
| 336 | * | ||
| 337 | * g' = g^{xa + xc + xd} | ||
| 338 | * | ||
| 339 | * as the generator, which means X is g'^{xb * s} | ||
| 340 | * X = t1^{t2} = t1^{xb * s} = g^{(xa + xc + xd) * xb * s} | ||
| 341 | */ | ||
| 342 | generate_step_part(send, t2, t1, ctx); | ||
| 343 | |||
| 344 | /* cleanup */ | ||
| 345 | BN_free(t1); | ||
| 346 | BN_free(t2); | ||
| 347 | |||
| 348 | return 1; | ||
| 349 | } | ||
| 350 | |||
| 351 | /* gx = g^{xc + xa + xb} * xd * s */ | ||
| 352 | static int compute_key(JPAKE_CTX *ctx, const BIGNUM *gx) | ||
| 353 | { | ||
| 354 | BIGNUM *t1 = BN_new(); | ||
| 355 | BIGNUM *t2 = BN_new(); | ||
| 356 | BIGNUM *t3 = BN_new(); | ||
| 357 | |||
| 358 | /* | ||
| 359 | * K = (gx/g^{xb * xd * s})^{xb} | ||
| 360 | * = (g^{(xc + xa + xb) * xd * s - xb * xd *s})^{xb} | ||
| 361 | * = (g^{(xa + xc) * xd * s})^{xb} | ||
| 362 | * = g^{(xa + xc) * xb * xd * s} | ||
| 363 | * [which is the same regardless of who calculates it] | ||
| 364 | */ | ||
| 365 | |||
| 366 | /* t1 = (g^{xd})^{xb} = g^{xb * xd} */ | ||
| 367 | BN_mod_exp(t1, ctx->p.gxd, ctx->xb, ctx->p.p, ctx->ctx); | ||
| 368 | /* t2 = -s = q-s */ | ||
| 369 | BN_sub(t2, ctx->p.q, ctx->secret); | ||
| 370 | /* t3 = t1^t2 = g^{-xb * xd * s} */ | ||
| 371 | BN_mod_exp(t3, t1, t2, ctx->p.p, ctx->ctx); | ||
| 372 | /* t1 = gx * t3 = X/g^{xb * xd * s} */ | ||
| 373 | BN_mod_mul(t1, gx, t3, ctx->p.p, ctx->ctx); | ||
| 374 | /* K = t1^{xb} */ | ||
| 375 | BN_mod_exp(ctx->key, t1, ctx->xb, ctx->p.p, ctx->ctx); | ||
| 376 | |||
| 377 | /* cleanup */ | ||
| 378 | BN_free(t3); | ||
| 379 | BN_free(t2); | ||
| 380 | BN_free(t1); | ||
| 381 | |||
| 382 | return 1; | ||
| 383 | } | ||
| 384 | |||
| 385 | int JPAKE_STEP2_process(JPAKE_CTX *ctx, const JPAKE_STEP2 *received) | ||
| 386 | { | ||
| 387 | BIGNUM *t1 = BN_new(); | ||
| 388 | BIGNUM *t2 = BN_new(); | ||
| 389 | int ret = 0; | ||
| 390 | |||
| 391 | /* | ||
| 392 | * g' = g^{xc + xa + xb} [from our POV] | ||
| 393 | * t1 = xa + xb | ||
| 394 | */ | ||
| 395 | BN_mod_add(t1, ctx->xa, ctx->xb, ctx->p.q, ctx->ctx); | ||
| 396 | /* t2 = g^{t1} = g^{xa+xb} */ | ||
| 397 | BN_mod_exp(t2, ctx->p.g, t1, ctx->p.p, ctx->ctx); | ||
| 398 | /* t1 = g^{xc} * t2 = g^{xc + xa + xb} */ | ||
| 399 | BN_mod_mul(t1, ctx->p.gxc, t2, ctx->p.p, ctx->ctx); | ||
| 400 | |||
| 401 | if(verify_zkp(received, t1, ctx)) | ||
| 402 | ret = 1; | ||
| 403 | else | ||
| 404 | JPAKEerr(JPAKE_F_JPAKE_STEP2_PROCESS, JPAKE_R_VERIFY_B_FAILED); | ||
| 405 | |||
| 406 | compute_key(ctx, received->gx); | ||
| 407 | |||
| 408 | /* cleanup */ | ||
| 409 | BN_free(t2); | ||
| 410 | BN_free(t1); | ||
| 411 | |||
| 412 | return ret; | ||
| 413 | } | ||
| 414 | |||
| 415 | static void quickhashbn(unsigned char *md, const BIGNUM *bn) | ||
| 416 | { | ||
| 417 | SHA_CTX sha; | ||
| 418 | |||
| 419 | SHA1_Init(&sha); | ||
| 420 | hashbn(&sha, bn); | ||
| 421 | SHA1_Final(md, &sha); | ||
| 422 | } | ||
| 423 | |||
| 424 | void JPAKE_STEP3A_init(JPAKE_STEP3A *s3a) | ||
| 425 | {} | ||
| 426 | |||
| 427 | int JPAKE_STEP3A_generate(JPAKE_STEP3A *send, JPAKE_CTX *ctx) | ||
| 428 | { | ||
| 429 | quickhashbn(send->hhk, ctx->key); | ||
| 430 | SHA1(send->hhk, sizeof send->hhk, send->hhk); | ||
| 431 | |||
| 432 | return 1; | ||
| 433 | } | ||
| 434 | |||
| 435 | int JPAKE_STEP3A_process(JPAKE_CTX *ctx, const JPAKE_STEP3A *received) | ||
| 436 | { | ||
| 437 | unsigned char hhk[SHA_DIGEST_LENGTH]; | ||
| 438 | |||
| 439 | quickhashbn(hhk, ctx->key); | ||
| 440 | SHA1(hhk, sizeof hhk, hhk); | ||
| 441 | if(memcmp(hhk, received->hhk, sizeof hhk)) | ||
| 442 | { | ||
| 443 | JPAKEerr(JPAKE_F_JPAKE_STEP3A_PROCESS, JPAKE_R_HASH_OF_HASH_OF_KEY_MISMATCH); | ||
| 444 | return 0; | ||
| 445 | } | ||
| 446 | return 1; | ||
| 447 | } | ||
| 448 | |||
| 449 | void JPAKE_STEP3A_release(JPAKE_STEP3A *s3a) | ||
| 450 | {} | ||
| 451 | |||
| 452 | void JPAKE_STEP3B_init(JPAKE_STEP3B *s3b) | ||
| 453 | {} | ||
| 454 | |||
| 455 | int JPAKE_STEP3B_generate(JPAKE_STEP3B *send, JPAKE_CTX *ctx) | ||
| 456 | { | ||
| 457 | quickhashbn(send->hk, ctx->key); | ||
| 458 | |||
| 459 | return 1; | ||
| 460 | } | ||
| 461 | |||
| 462 | int JPAKE_STEP3B_process(JPAKE_CTX *ctx, const JPAKE_STEP3B *received) | ||
| 463 | { | ||
| 464 | unsigned char hk[SHA_DIGEST_LENGTH]; | ||
| 465 | |||
| 466 | quickhashbn(hk, ctx->key); | ||
| 467 | if(memcmp(hk, received->hk, sizeof hk)) | ||
| 468 | { | ||
| 469 | JPAKEerr(JPAKE_F_JPAKE_STEP3B_PROCESS, JPAKE_R_HASH_OF_KEY_MISMATCH); | ||
| 470 | return 0; | ||
| 471 | } | ||
| 472 | return 1; | ||
| 473 | } | ||
| 474 | |||
| 475 | void JPAKE_STEP3B_release(JPAKE_STEP3B *s3b) | ||
| 476 | {} | ||
| 477 | |||
| 478 | const BIGNUM *JPAKE_get_shared_key(JPAKE_CTX *ctx) | ||
| 479 | { | ||
| 480 | return ctx->key; | ||
| 481 | } | ||
| 482 | |||
diff --git a/src/lib/libcrypto/jpake/jpake.h b/src/lib/libcrypto/jpake/jpake.h new file mode 100644 index 0000000000..693ea188cb --- /dev/null +++ b/src/lib/libcrypto/jpake/jpake.h | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | /* | ||
| 2 | * Implement J-PAKE, as described in | ||
| 3 | * http://grouper.ieee.org/groups/1363/Research/contributions/hao-ryan-2008.pdf | ||
| 4 | * | ||
| 5 | * With hints from http://www.cl.cam.ac.uk/~fh240/software/JPAKE2.java. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef HEADER_JPAKE_H | ||
| 9 | #define HEADER_JPAKE_H | ||
| 10 | |||
| 11 | #include <openssl/opensslconf.h> | ||
| 12 | |||
| 13 | #ifdef OPENSSL_NO_JPAKE | ||
| 14 | #error JPAKE is disabled. | ||
| 15 | #endif | ||
| 16 | |||
| 17 | #ifdef __cplusplus | ||
| 18 | extern "C" { | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #include <openssl/bn.h> | ||
| 22 | #include <openssl/sha.h> | ||
| 23 | |||
| 24 | typedef struct JPAKE_CTX JPAKE_CTX; | ||
| 25 | |||
| 26 | /* Note that "g" in the ZKPs is not necessarily the J-PAKE g. */ | ||
| 27 | typedef struct | ||
| 28 | { | ||
| 29 | BIGNUM *gr; /* g^r (r random) */ | ||
| 30 | BIGNUM *b; /* b = r - x*h, h=hash(g, g^r, g^x, name) */ | ||
| 31 | } JPAKE_ZKP; | ||
| 32 | |||
| 33 | typedef struct | ||
| 34 | { | ||
| 35 | BIGNUM *gx; /* g^x in step 1, g^(xa + xc + xd) * xb * s in step 2 */ | ||
| 36 | JPAKE_ZKP zkpx; /* ZKP(x) or ZKP(xb * s) */ | ||
| 37 | } JPAKE_STEP_PART; | ||
| 38 | |||
| 39 | typedef struct | ||
| 40 | { | ||
| 41 | JPAKE_STEP_PART p1; /* g^x3, ZKP(x3) or g^x1, ZKP(x1) */ | ||
| 42 | JPAKE_STEP_PART p2; /* g^x4, ZKP(x4) or g^x2, ZKP(x2) */ | ||
| 43 | } JPAKE_STEP1; | ||
| 44 | |||
| 45 | typedef JPAKE_STEP_PART JPAKE_STEP2; | ||
| 46 | |||
| 47 | typedef struct | ||
| 48 | { | ||
| 49 | unsigned char hhk[SHA_DIGEST_LENGTH]; | ||
| 50 | } JPAKE_STEP3A; | ||
| 51 | |||
| 52 | typedef struct | ||
| 53 | { | ||
| 54 | unsigned char hk[SHA_DIGEST_LENGTH]; | ||
| 55 | } JPAKE_STEP3B; | ||
| 56 | |||
| 57 | /* Parameters are copied */ | ||
| 58 | JPAKE_CTX *JPAKE_CTX_new(const char *name, const char *peer_name, | ||
| 59 | const BIGNUM *p, const BIGNUM *g, const BIGNUM *q, | ||
| 60 | const BIGNUM *secret); | ||
| 61 | void JPAKE_CTX_free(JPAKE_CTX *ctx); | ||
| 62 | |||
| 63 | /* | ||
| 64 | * Note that JPAKE_STEP1 can be used multiple times before release | ||
| 65 | * without another init. | ||
| 66 | */ | ||
| 67 | void JPAKE_STEP1_init(JPAKE_STEP1 *s1); | ||
| 68 | int JPAKE_STEP1_generate(JPAKE_STEP1 *send, JPAKE_CTX *ctx); | ||
| 69 | int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received); | ||
| 70 | void JPAKE_STEP1_release(JPAKE_STEP1 *s1); | ||
| 71 | |||
| 72 | /* | ||
| 73 | * Note that JPAKE_STEP2 can be used multiple times before release | ||
| 74 | * without another init. | ||
| 75 | */ | ||
| 76 | void JPAKE_STEP2_init(JPAKE_STEP2 *s2); | ||
| 77 | int JPAKE_STEP2_generate(JPAKE_STEP2 *send, JPAKE_CTX *ctx); | ||
| 78 | int JPAKE_STEP2_process(JPAKE_CTX *ctx, const JPAKE_STEP2 *received); | ||
| 79 | void JPAKE_STEP2_release(JPAKE_STEP2 *s2); | ||
| 80 | |||
| 81 | /* | ||
| 82 | * Optionally verify the shared key. If the shared secrets do not | ||
| 83 | * match, the two ends will disagree about the shared key, but | ||
| 84 | * otherwise the protocol will succeed. | ||
| 85 | */ | ||
| 86 | void JPAKE_STEP3A_init(JPAKE_STEP3A *s3a); | ||
| 87 | int JPAKE_STEP3A_generate(JPAKE_STEP3A *send, JPAKE_CTX *ctx); | ||
| 88 | int JPAKE_STEP3A_process(JPAKE_CTX *ctx, const JPAKE_STEP3A *received); | ||
| 89 | void JPAKE_STEP3A_release(JPAKE_STEP3A *s3a); | ||
| 90 | |||
| 91 | void JPAKE_STEP3B_init(JPAKE_STEP3B *s3b); | ||
| 92 | int JPAKE_STEP3B_generate(JPAKE_STEP3B *send, JPAKE_CTX *ctx); | ||
| 93 | int JPAKE_STEP3B_process(JPAKE_CTX *ctx, const JPAKE_STEP3B *received); | ||
| 94 | void JPAKE_STEP3B_release(JPAKE_STEP3B *s3b); | ||
| 95 | |||
| 96 | /* | ||
| 97 | * the return value belongs to the library and will be released when | ||
| 98 | * ctx is released, and will change when a new handshake is performed. | ||
| 99 | */ | ||
| 100 | const BIGNUM *JPAKE_get_shared_key(JPAKE_CTX *ctx); | ||
| 101 | |||
| 102 | /* BEGIN ERROR CODES */ | ||
| 103 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 104 | * made after this point may be overwritten when the script is next run. | ||
| 105 | */ | ||
| 106 | void ERR_load_JPAKE_strings(void); | ||
| 107 | |||
| 108 | /* Error codes for the JPAKE functions. */ | ||
| 109 | |||
| 110 | /* Function codes. */ | ||
| 111 | #define JPAKE_F_JPAKE_STEP1_PROCESS 101 | ||
| 112 | #define JPAKE_F_JPAKE_STEP2_PROCESS 102 | ||
| 113 | #define JPAKE_F_JPAKE_STEP3A_PROCESS 103 | ||
| 114 | #define JPAKE_F_JPAKE_STEP3B_PROCESS 104 | ||
| 115 | #define JPAKE_F_VERIFY_ZKP 100 | ||
| 116 | |||
| 117 | /* Reason codes. */ | ||
| 118 | #define JPAKE_R_G_TO_THE_X4_IS_ONE 105 | ||
| 119 | #define JPAKE_R_HASH_OF_HASH_OF_KEY_MISMATCH 106 | ||
| 120 | #define JPAKE_R_HASH_OF_KEY_MISMATCH 107 | ||
| 121 | #define JPAKE_R_VERIFY_B_FAILED 102 | ||
| 122 | #define JPAKE_R_VERIFY_X3_FAILED 103 | ||
| 123 | #define JPAKE_R_VERIFY_X4_FAILED 104 | ||
| 124 | #define JPAKE_R_ZKP_VERIFY_FAILED 100 | ||
| 125 | |||
| 126 | #ifdef __cplusplus | ||
| 127 | } | ||
| 128 | #endif | ||
| 129 | #endif | ||
diff --git a/src/lib/libcrypto/evp/evp_cnf.c b/src/lib/libcrypto/jpake/jpake_err.c index 2e4db30235..1b95067967 100644 --- a/src/lib/libcrypto/evp/evp_cnf.c +++ b/src/lib/libcrypto/jpake/jpake_err.c | |||
| @@ -1,9 +1,6 @@ | |||
| 1 | /* evp_cnf.c */ | 1 | /* crypto/jpake/jpake_err.c */ |
| 2 | /* Written by Stephen Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 2007. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | 2 | /* ==================================================================== |
| 6 | * Copyright (c) 2007 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. |
| 7 | * | 4 | * |
| 8 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| @@ -25,7 +22,7 @@ | |||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
| 26 | * endorse or promote products derived from this software without | 23 | * endorse or promote products derived from this software without |
| 27 | * prior written permission. For written permission, please contact | 24 | * prior written permission. For written permission, please contact |
| 28 | * licensing@OpenSSL.org. | 25 | * openssl-core@OpenSSL.org. |
| 29 | * | 26 | * |
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | 27 | * 5. Products derived from this software may not be called "OpenSSL" |
| 31 | * nor may "OpenSSL" appear in their names without prior written | 28 | * nor may "OpenSSL" appear in their names without prior written |
| @@ -56,70 +53,53 @@ | |||
| 56 | * | 53 | * |
| 57 | */ | 54 | */ |
| 58 | 55 | ||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 59 | #include <stdio.h> | 61 | #include <stdio.h> |
| 60 | #include <ctype.h> | 62 | #include <openssl/err.h> |
| 61 | #include <openssl/crypto.h> | 63 | #include <openssl/jpake.h> |
| 62 | #include "cryptlib.h" | ||
| 63 | #include <openssl/conf.h> | ||
| 64 | #include <openssl/dso.h> | ||
| 65 | #include <openssl/x509.h> | ||
| 66 | #include <openssl/x509v3.h> | ||
| 67 | #ifdef OPENSSL_FIPS | ||
| 68 | #include <openssl/fips.h> | ||
| 69 | #endif | ||
| 70 | 64 | ||
| 65 | /* BEGIN ERROR CODES */ | ||
| 66 | #ifndef OPENSSL_NO_ERR | ||
| 71 | 67 | ||
| 72 | /* Algorithm configuration module. */ | 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_JPAKE,func,0) |
| 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_JPAKE,0,reason) | ||
| 73 | 70 | ||
| 74 | static int alg_module_init(CONF_IMODULE *md, const CONF *cnf) | 71 | static ERR_STRING_DATA JPAKE_str_functs[]= |
| 75 | { | 72 | { |
| 76 | int i; | 73 | {ERR_FUNC(JPAKE_F_JPAKE_STEP1_PROCESS), "JPAKE_STEP1_process"}, |
| 77 | const char *oid_section; | 74 | {ERR_FUNC(JPAKE_F_JPAKE_STEP2_PROCESS), "JPAKE_STEP2_process"}, |
| 78 | STACK_OF(CONF_VALUE) *sktmp; | 75 | {ERR_FUNC(JPAKE_F_JPAKE_STEP3A_PROCESS), "JPAKE_STEP3A_process"}, |
| 79 | CONF_VALUE *oval; | 76 | {ERR_FUNC(JPAKE_F_JPAKE_STEP3B_PROCESS), "JPAKE_STEP3B_process"}, |
| 80 | oid_section = CONF_imodule_get_value(md); | 77 | {ERR_FUNC(JPAKE_F_VERIFY_ZKP), "VERIFY_ZKP"}, |
| 81 | if(!(sktmp = NCONF_get_section(cnf, oid_section))) | 78 | {0,NULL} |
| 82 | { | 79 | }; |
| 83 | EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_ERROR_LOADING_SECTION); | 80 | |
| 84 | return 0; | 81 | static ERR_STRING_DATA JPAKE_str_reasons[]= |
| 85 | } | 82 | { |
| 86 | for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) | 83 | {ERR_REASON(JPAKE_R_G_TO_THE_X4_IS_ONE) ,"g to the x4 is one"}, |
| 87 | { | 84 | {ERR_REASON(JPAKE_R_HASH_OF_HASH_OF_KEY_MISMATCH),"hash of hash of key mismatch"}, |
| 88 | oval = sk_CONF_VALUE_value(sktmp, i); | 85 | {ERR_REASON(JPAKE_R_HASH_OF_KEY_MISMATCH),"hash of key mismatch"}, |
| 89 | if (!strcmp(oval->name, "fips_mode")) | 86 | {ERR_REASON(JPAKE_R_VERIFY_B_FAILED) ,"verify b failed"}, |
| 90 | { | 87 | {ERR_REASON(JPAKE_R_VERIFY_X3_FAILED) ,"verify x3 failed"}, |
| 91 | int m; | 88 | {ERR_REASON(JPAKE_R_VERIFY_X4_FAILED) ,"verify x4 failed"}, |
| 92 | if (!X509V3_get_value_bool(oval, &m)) | 89 | {ERR_REASON(JPAKE_R_ZKP_VERIFY_FAILED) ,"zkp verify failed"}, |
| 93 | { | 90 | {0,NULL} |
| 94 | EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_INVALID_FIPS_MODE); | 91 | }; |
| 95 | return 0; | 92 | |
| 96 | } | ||
| 97 | if (m > 0) | ||
| 98 | { | ||
| 99 | #ifdef OPENSSL_FIPS | ||
| 100 | if (!FIPS_mode() && !FIPS_mode_set(1)) | ||
| 101 | { | ||
| 102 | EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_ERROR_SETTING_FIPS_MODE); | ||
| 103 | return 0; | ||
| 104 | } | ||
| 105 | #else | ||
| 106 | EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_FIPS_MODE_NOT_SUPPORTED); | ||
| 107 | return 0; | ||
| 108 | #endif | 93 | #endif |
| 109 | } | ||
| 110 | } | ||
| 111 | else | ||
| 112 | { | ||
| 113 | EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_UNKNOWN_OPTION); | ||
| 114 | ERR_add_error_data(4, "name=", oval->name, | ||
| 115 | ", value=", oval->value); | ||
| 116 | } | ||
| 117 | |||
| 118 | } | ||
| 119 | return 1; | ||
| 120 | } | ||
| 121 | 94 | ||
| 122 | void EVP_add_alg_module(void) | 95 | void ERR_load_JPAKE_strings(void) |
| 123 | { | 96 | { |
| 124 | CONF_module_add("alg_section", alg_module_init, 0); | 97 | #ifndef OPENSSL_NO_ERR |
| 98 | |||
| 99 | if (ERR_func_error_string(JPAKE_str_functs[0].error) == NULL) | ||
| 100 | { | ||
| 101 | ERR_load_strings(0,JPAKE_str_functs); | ||
| 102 | ERR_load_strings(0,JPAKE_str_reasons); | ||
| 103 | } | ||
| 104 | #endif | ||
| 125 | } | 105 | } |
diff --git a/src/lib/libcrypto/jpake/jpaketest.c b/src/lib/libcrypto/jpake/jpaketest.c new file mode 100644 index 0000000000..eaba75ed8a --- /dev/null +++ b/src/lib/libcrypto/jpake/jpaketest.c | |||
| @@ -0,0 +1,192 @@ | |||
| 1 | #include <openssl/opensslconf.h> | ||
| 2 | |||
| 3 | #ifdef OPENSSL_NO_JPAKE | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | |||
| 7 | int main(int argc, char *argv[]) | ||
| 8 | { | ||
| 9 | printf("No J-PAKE support\n"); | ||
| 10 | return(0); | ||
| 11 | } | ||
| 12 | |||
| 13 | #else | ||
| 14 | |||
| 15 | #include <openssl/jpake.h> | ||
| 16 | #include <openssl/err.h> | ||
| 17 | |||
| 18 | static void showbn(const char *name, const BIGNUM *bn) | ||
| 19 | { | ||
| 20 | fputs(name, stdout); | ||
| 21 | fputs(" = ", stdout); | ||
| 22 | BN_print_fp(stdout, bn); | ||
| 23 | putc('\n', stdout); | ||
| 24 | } | ||
| 25 | |||
| 26 | static int run_jpake(JPAKE_CTX *alice, JPAKE_CTX *bob) | ||
| 27 | { | ||
| 28 | JPAKE_STEP1 alice_s1; | ||
| 29 | JPAKE_STEP1 bob_s1; | ||
| 30 | JPAKE_STEP2 alice_s2; | ||
| 31 | JPAKE_STEP2 bob_s2; | ||
| 32 | JPAKE_STEP3A alice_s3a; | ||
| 33 | JPAKE_STEP3B bob_s3b; | ||
| 34 | |||
| 35 | /* Alice -> Bob: step 1 */ | ||
| 36 | puts("A->B s1"); | ||
| 37 | JPAKE_STEP1_init(&alice_s1); | ||
| 38 | JPAKE_STEP1_generate(&alice_s1, alice); | ||
| 39 | if(!JPAKE_STEP1_process(bob, &alice_s1)) | ||
| 40 | { | ||
| 41 | printf("Bob fails to process Alice's step 1\n"); | ||
| 42 | ERR_print_errors_fp(stdout); | ||
| 43 | return 1; | ||
| 44 | } | ||
| 45 | JPAKE_STEP1_release(&alice_s1); | ||
| 46 | |||
| 47 | /* Bob -> Alice: step 1 */ | ||
| 48 | puts("B->A s1"); | ||
| 49 | JPAKE_STEP1_init(&bob_s1); | ||
| 50 | JPAKE_STEP1_generate(&bob_s1, bob); | ||
| 51 | if(!JPAKE_STEP1_process(alice, &bob_s1)) | ||
| 52 | { | ||
| 53 | printf("Alice fails to process Bob's step 1\n"); | ||
| 54 | ERR_print_errors_fp(stdout); | ||
| 55 | return 2; | ||
| 56 | } | ||
| 57 | JPAKE_STEP1_release(&bob_s1); | ||
| 58 | |||
| 59 | /* Alice -> Bob: step 2 */ | ||
| 60 | puts("A->B s2"); | ||
| 61 | JPAKE_STEP2_init(&alice_s2); | ||
| 62 | JPAKE_STEP2_generate(&alice_s2, alice); | ||
| 63 | if(!JPAKE_STEP2_process(bob, &alice_s2)) | ||
| 64 | { | ||
| 65 | printf("Bob fails to process Alice's step 2\n"); | ||
| 66 | ERR_print_errors_fp(stdout); | ||
| 67 | return 3; | ||
| 68 | } | ||
| 69 | JPAKE_STEP2_release(&alice_s2); | ||
| 70 | |||
| 71 | /* Bob -> Alice: step 2 */ | ||
| 72 | puts("B->A s2"); | ||
| 73 | JPAKE_STEP2_init(&bob_s2); | ||
| 74 | JPAKE_STEP2_generate(&bob_s2, bob); | ||
| 75 | if(!JPAKE_STEP2_process(alice, &bob_s2)) | ||
| 76 | { | ||
| 77 | printf("Alice fails to process Bob's step 2\n"); | ||
| 78 | ERR_print_errors_fp(stdout); | ||
| 79 | return 4; | ||
| 80 | } | ||
| 81 | JPAKE_STEP2_release(&bob_s2); | ||
| 82 | |||
| 83 | showbn("Alice's key", JPAKE_get_shared_key(alice)); | ||
| 84 | showbn("Bob's key ", JPAKE_get_shared_key(bob)); | ||
| 85 | |||
| 86 | /* Alice -> Bob: step 3a */ | ||
| 87 | puts("A->B s3a"); | ||
| 88 | JPAKE_STEP3A_init(&alice_s3a); | ||
| 89 | JPAKE_STEP3A_generate(&alice_s3a, alice); | ||
| 90 | if(!JPAKE_STEP3A_process(bob, &alice_s3a)) | ||
| 91 | { | ||
| 92 | printf("Bob fails to process Alice's step 3a\n"); | ||
| 93 | ERR_print_errors_fp(stdout); | ||
| 94 | return 5; | ||
| 95 | } | ||
| 96 | JPAKE_STEP3A_release(&alice_s3a); | ||
| 97 | |||
| 98 | /* Bob -> Alice: step 3b */ | ||
| 99 | puts("B->A s3b"); | ||
| 100 | JPAKE_STEP3B_init(&bob_s3b); | ||
| 101 | JPAKE_STEP3B_generate(&bob_s3b, bob); | ||
| 102 | if(!JPAKE_STEP3B_process(alice, &bob_s3b)) | ||
| 103 | { | ||
| 104 | printf("Alice fails to process Bob's step 3b\n"); | ||
| 105 | ERR_print_errors_fp(stdout); | ||
| 106 | return 6; | ||
| 107 | } | ||
| 108 | JPAKE_STEP3B_release(&bob_s3b); | ||
| 109 | |||
| 110 | return 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | int main(int argc, char **argv) | ||
| 114 | { | ||
| 115 | JPAKE_CTX *alice; | ||
| 116 | JPAKE_CTX *bob; | ||
| 117 | BIGNUM *p = NULL; | ||
| 118 | BIGNUM *g = NULL; | ||
| 119 | BIGNUM *q = NULL; | ||
| 120 | BIGNUM *secret = BN_new(); | ||
| 121 | BIO *bio_err; | ||
| 122 | |||
| 123 | bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); | ||
| 124 | |||
| 125 | CRYPTO_malloc_debug_init(); | ||
| 126 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | ||
| 127 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
| 128 | |||
| 129 | ERR_load_crypto_strings(); | ||
| 130 | |||
| 131 | /* | ||
| 132 | BN_hex2bn(&p, "fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7"); | ||
| 133 | BN_hex2bn(&g, "f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a"); | ||
| 134 | BN_hex2bn(&q, "9760508f15230bccb292b982a2eb840bf0581cf5"); | ||
| 135 | */ | ||
| 136 | /* | ||
| 137 | p = BN_new(); | ||
| 138 | BN_generate_prime(p, 1024, 1, NULL, NULL, NULL, NULL); | ||
| 139 | */ | ||
| 140 | /* Use a safe prime for p (that we found earlier) */ | ||
| 141 | BN_hex2bn(&p, "F9E5B365665EA7A05A9C534502780FEE6F1AB5BD4F49947FD036DBD7E905269AF46EF28B0FC07487EE4F5D20FB3C0AF8E700F3A2FA3414970CBED44FEDFF80CE78D800F184BB82435D137AADA2C6C16523247930A63B85661D1FC817A51ACD96168E95898A1F83A79FFB529368AA7833ABD1B0C3AEDDB14D2E1A2F71D99F763F"); | ||
| 142 | showbn("p", p); | ||
| 143 | g = BN_new(); | ||
| 144 | BN_set_word(g, 2); | ||
| 145 | showbn("g", g); | ||
| 146 | q = BN_new(); | ||
| 147 | BN_rshift1(q, p); | ||
| 148 | showbn("q", q); | ||
| 149 | |||
| 150 | BN_rand(secret, 32, -1, 0); | ||
| 151 | |||
| 152 | /* A normal run, expect this to work... */ | ||
| 153 | alice = JPAKE_CTX_new("Alice", "Bob", p, g, q, secret); | ||
| 154 | bob = JPAKE_CTX_new("Bob", "Alice", p, g, q, secret); | ||
| 155 | |||
| 156 | if(run_jpake(alice, bob) != 0) | ||
| 157 | { | ||
| 158 | fprintf(stderr, "Plain JPAKE run failed\n"); | ||
| 159 | return 1; | ||
| 160 | } | ||
| 161 | |||
| 162 | JPAKE_CTX_free(bob); | ||
| 163 | JPAKE_CTX_free(alice); | ||
| 164 | |||
| 165 | /* Now give Alice and Bob different secrets */ | ||
| 166 | alice = JPAKE_CTX_new("Alice", "Bob", p, g, q, secret); | ||
| 167 | BN_add_word(secret, 1); | ||
| 168 | bob = JPAKE_CTX_new("Bob", "Alice", p, g, q, secret); | ||
| 169 | |||
| 170 | if(run_jpake(alice, bob) != 5) | ||
| 171 | { | ||
| 172 | fprintf(stderr, "Mismatched secret JPAKE run failed\n"); | ||
| 173 | return 1; | ||
| 174 | } | ||
| 175 | |||
| 176 | JPAKE_CTX_free(bob); | ||
| 177 | JPAKE_CTX_free(alice); | ||
| 178 | |||
| 179 | BN_free(secret); | ||
| 180 | BN_free(q); | ||
| 181 | BN_free(g); | ||
| 182 | BN_free(p); | ||
| 183 | |||
| 184 | CRYPTO_cleanup_all_ex_data(); | ||
| 185 | ERR_remove_thread_state(NULL); | ||
| 186 | ERR_free_strings(); | ||
| 187 | CRYPTO_mem_leaks(bio_err); | ||
| 188 | |||
| 189 | return 0; | ||
| 190 | } | ||
| 191 | |||
| 192 | #endif | ||
diff --git a/src/lib/libcrypto/md5/asm/md5-sparcv9.S b/src/lib/libcrypto/md5/asm/md5-sparcv9.S deleted file mode 100644 index db45aa4c97..0000000000 --- a/src/lib/libcrypto/md5/asm/md5-sparcv9.S +++ /dev/null | |||
| @@ -1,1031 +0,0 @@ | |||
| 1 | .ident "md5-sparcv9.S, Version 1.0" | ||
| 2 | .ident "SPARC V9 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>" | ||
| 3 | .file "md5-sparcv9.S" | ||
| 4 | |||
| 5 | /* | ||
| 6 | * ==================================================================== | ||
| 7 | * Copyright (c) 1999 Andy Polyakov <appro@fy.chalmers.se>. | ||
| 8 | * | ||
| 9 | * Rights for redistribution and usage in source and binary forms are | ||
| 10 | * granted as long as above copyright notices are retained. Warranty | ||
| 11 | * of any kind is (of course:-) disclaimed. | ||
| 12 | * ==================================================================== | ||
| 13 | */ | ||
| 14 | |||
| 15 | /* | ||
| 16 | * This is my modest contribution to OpenSSL project (see | ||
| 17 | * http://www.openssl.org/ for more information about it) and is an | ||
| 18 | * assembler implementation of MD5 block hash function. I've hand-coded | ||
| 19 | * this for the sole reason to reach UltraSPARC-specific "load in | ||
| 20 | * little-endian byte order" instruction. This gives up to 15% | ||
| 21 | * performance improvement for cases when input message is aligned at | ||
| 22 | * 32 bits boundary. The module was tested under both 32 *and* 64 bit | ||
| 23 | * kernels. For updates see http://fy.chalmers.se/~appro/hpe/. | ||
| 24 | * | ||
| 25 | * To compile with SC4.x/SC5.x: | ||
| 26 | * | ||
| 27 | * cc -xarch=v[9|8plus] -DOPENSSL_SYSNAME_ULTRASPARC -DMD5_BLOCK_DATA_ORDER \ | ||
| 28 | * -c md5-sparcv9.S | ||
| 29 | * | ||
| 30 | * and with gcc: | ||
| 31 | * | ||
| 32 | * gcc -mcpu=ultrasparc -DOPENSSL_SYSNAME_ULTRASPARC -DMD5_BLOCK_DATA_ORDER \ | ||
| 33 | * -c md5-sparcv9.S | ||
| 34 | * | ||
| 35 | * or if above fails (it does if you have gas): | ||
| 36 | * | ||
| 37 | * gcc -E -DOPENSSL_SYSNAMEULTRASPARC -DMD5_BLOCK_DATA_ORDER md5_block.sparc.S | \ | ||
| 38 | * as -xarch=v8plus /dev/fd/0 -o md5-sparcv9.o | ||
| 39 | */ | ||
| 40 | |||
| 41 | #include <openssl/e_os2.h> | ||
| 42 | |||
| 43 | #define A %o0 | ||
| 44 | #define B %o1 | ||
| 45 | #define C %o2 | ||
| 46 | #define D %o3 | ||
| 47 | #define T1 %o4 | ||
| 48 | #define T2 %o5 | ||
| 49 | |||
| 50 | #define R0 %l0 | ||
| 51 | #define R1 %l1 | ||
| 52 | #define R2 %l2 | ||
| 53 | #define R3 %l3 | ||
| 54 | #define R4 %l4 | ||
| 55 | #define R5 %l5 | ||
| 56 | #define R6 %l6 | ||
| 57 | #define R7 %l7 | ||
| 58 | #define R8 %i3 | ||
| 59 | #define R9 %i4 | ||
| 60 | #define R10 %i5 | ||
| 61 | #define R11 %g1 | ||
| 62 | #define R12 %g2 | ||
| 63 | #define R13 %g3 | ||
| 64 | #define RX %g4 | ||
| 65 | |||
| 66 | #define Aptr %i0+0 | ||
| 67 | #define Bptr %i0+4 | ||
| 68 | #define Cptr %i0+8 | ||
| 69 | #define Dptr %i0+12 | ||
| 70 | |||
| 71 | #define Aval R5 /* those not used at the end of the last round */ | ||
| 72 | #define Bval R6 | ||
| 73 | #define Cval R7 | ||
| 74 | #define Dval R8 | ||
| 75 | |||
| 76 | #if defined(MD5_BLOCK_DATA_ORDER) | ||
| 77 | # if defined(OPENSSL_SYSNAME_ULTRASPARC) | ||
| 78 | # define LOAD lda | ||
| 79 | # define X(i) [%i1+i*4]%asi | ||
| 80 | # define md5_block md5_block_asm_data_order_aligned | ||
| 81 | # define ASI_PRIMARY_LITTLE 0x88 | ||
| 82 | # else | ||
| 83 | # error "MD5_BLOCK_DATA_ORDER is supported only on UltraSPARC!" | ||
| 84 | # endif | ||
| 85 | #else | ||
| 86 | # define LOAD ld | ||
| 87 | # define X(i) [%i1+i*4] | ||
| 88 | # define md5_block md5_block_asm_host_order | ||
| 89 | #endif | ||
| 90 | |||
| 91 | .section ".text",#alloc,#execinstr | ||
| 92 | |||
| 93 | #if defined(__SUNPRO_C) && defined(__sparcv9) | ||
| 94 | /* They've said -xarch=v9 at command line */ | ||
| 95 | .register %g2,#scratch | ||
| 96 | .register %g3,#scratch | ||
| 97 | # define FRAME -192 | ||
| 98 | #elif defined(__GNUC__) && defined(__arch64__) | ||
| 99 | /* They've said -m64 at command line */ | ||
| 100 | .register %g2,#scratch | ||
| 101 | .register %g3,#scratch | ||
| 102 | # define FRAME -192 | ||
| 103 | #else | ||
| 104 | # define FRAME -96 | ||
| 105 | #endif | ||
| 106 | |||
| 107 | .align 32 | ||
| 108 | |||
| 109 | .global md5_block | ||
| 110 | md5_block: | ||
| 111 | save %sp,FRAME,%sp | ||
| 112 | |||
| 113 | ld [Dptr],D | ||
| 114 | ld [Cptr],C | ||
| 115 | ld [Bptr],B | ||
| 116 | ld [Aptr],A | ||
| 117 | #ifdef ASI_PRIMARY_LITTLE | ||
| 118 | rd %asi,%o7 ! How dare I? Well, I just do:-) | ||
| 119 | wr %g0,ASI_PRIMARY_LITTLE,%asi | ||
| 120 | #endif | ||
| 121 | LOAD X(0),R0 | ||
| 122 | |||
| 123 | .Lmd5_block_loop: | ||
| 124 | |||
| 125 | !!!!!!!!Round 0 | ||
| 126 | |||
| 127 | xor C,D,T1 | ||
| 128 | sethi %hi(0xd76aa478),T2 | ||
| 129 | and T1,B,T1 | ||
| 130 | or T2,%lo(0xd76aa478),T2 != | ||
| 131 | xor T1,D,T1 | ||
| 132 | add T1,R0,T1 | ||
| 133 | LOAD X(1),R1 | ||
| 134 | add T1,T2,T1 != | ||
| 135 | add A,T1,A | ||
| 136 | sll A,7,T2 | ||
| 137 | srl A,32-7,A | ||
| 138 | or A,T2,A != | ||
| 139 | xor B,C,T1 | ||
| 140 | add A,B,A | ||
| 141 | |||
| 142 | sethi %hi(0xe8c7b756),T2 | ||
| 143 | and T1,A,T1 != | ||
| 144 | or T2,%lo(0xe8c7b756),T2 | ||
| 145 | xor T1,C,T1 | ||
| 146 | LOAD X(2),R2 | ||
| 147 | add T1,R1,T1 != | ||
| 148 | add T1,T2,T1 | ||
| 149 | add D,T1,D | ||
| 150 | sll D,12,T2 | ||
| 151 | srl D,32-12,D != | ||
| 152 | or D,T2,D | ||
| 153 | xor A,B,T1 | ||
| 154 | add D,A,D | ||
| 155 | |||
| 156 | sethi %hi(0x242070db),T2 != | ||
| 157 | and T1,D,T1 | ||
| 158 | or T2,%lo(0x242070db),T2 | ||
| 159 | xor T1,B,T1 | ||
| 160 | add T1,R2,T1 != | ||
| 161 | LOAD X(3),R3 | ||
| 162 | add T1,T2,T1 | ||
| 163 | add C,T1,C | ||
| 164 | sll C,17,T2 != | ||
| 165 | srl C,32-17,C | ||
| 166 | or C,T2,C | ||
| 167 | xor D,A,T1 | ||
| 168 | add C,D,C != | ||
| 169 | |||
| 170 | sethi %hi(0xc1bdceee),T2 | ||
| 171 | and T1,C,T1 | ||
| 172 | or T2,%lo(0xc1bdceee),T2 | ||
| 173 | xor T1,A,T1 != | ||
| 174 | add T1,R3,T1 | ||
| 175 | LOAD X(4),R4 | ||
| 176 | add T1,T2,T1 | ||
| 177 | add B,T1,B != | ||
| 178 | sll B,22,T2 | ||
| 179 | srl B,32-22,B | ||
| 180 | or B,T2,B | ||
| 181 | xor C,D,T1 != | ||
| 182 | add B,C,B | ||
| 183 | |||
| 184 | sethi %hi(0xf57c0faf),T2 | ||
| 185 | and T1,B,T1 | ||
| 186 | or T2,%lo(0xf57c0faf),T2 != | ||
| 187 | xor T1,D,T1 | ||
| 188 | add T1,R4,T1 | ||
| 189 | LOAD X(5),R5 | ||
| 190 | add T1,T2,T1 != | ||
| 191 | add A,T1,A | ||
| 192 | sll A,7,T2 | ||
| 193 | srl A,32-7,A | ||
| 194 | or A,T2,A != | ||
| 195 | xor B,C,T1 | ||
| 196 | add A,B,A | ||
| 197 | |||
| 198 | sethi %hi(0x4787c62a),T2 | ||
| 199 | and T1,A,T1 != | ||
| 200 | or T2,%lo(0x4787c62a),T2 | ||
| 201 | xor T1,C,T1 | ||
| 202 | LOAD X(6),R6 | ||
| 203 | add T1,R5,T1 != | ||
| 204 | add T1,T2,T1 | ||
| 205 | add D,T1,D | ||
| 206 | sll D,12,T2 | ||
| 207 | srl D,32-12,D != | ||
| 208 | or D,T2,D | ||
| 209 | xor A,B,T1 | ||
| 210 | add D,A,D | ||
| 211 | |||
| 212 | sethi %hi(0xa8304613),T2 != | ||
| 213 | and T1,D,T1 | ||
| 214 | or T2,%lo(0xa8304613),T2 | ||
| 215 | xor T1,B,T1 | ||
| 216 | add T1,R6,T1 != | ||
| 217 | LOAD X(7),R7 | ||
| 218 | add T1,T2,T1 | ||
| 219 | add C,T1,C | ||
| 220 | sll C,17,T2 != | ||
| 221 | srl C,32-17,C | ||
| 222 | or C,T2,C | ||
| 223 | xor D,A,T1 | ||
| 224 | add C,D,C != | ||
| 225 | |||
| 226 | sethi %hi(0xfd469501),T2 | ||
| 227 | and T1,C,T1 | ||
| 228 | or T2,%lo(0xfd469501),T2 | ||
| 229 | xor T1,A,T1 != | ||
| 230 | add T1,R7,T1 | ||
| 231 | LOAD X(8),R8 | ||
| 232 | add T1,T2,T1 | ||
| 233 | add B,T1,B != | ||
| 234 | sll B,22,T2 | ||
| 235 | srl B,32-22,B | ||
| 236 | or B,T2,B | ||
| 237 | xor C,D,T1 != | ||
| 238 | add B,C,B | ||
| 239 | |||
| 240 | sethi %hi(0x698098d8),T2 | ||
| 241 | and T1,B,T1 | ||
| 242 | or T2,%lo(0x698098d8),T2 != | ||
| 243 | xor T1,D,T1 | ||
| 244 | add T1,R8,T1 | ||
| 245 | LOAD X(9),R9 | ||
| 246 | add T1,T2,T1 != | ||
| 247 | add A,T1,A | ||
| 248 | sll A,7,T2 | ||
| 249 | srl A,32-7,A | ||
| 250 | or A,T2,A != | ||
| 251 | xor B,C,T1 | ||
| 252 | add A,B,A | ||
| 253 | |||
| 254 | sethi %hi(0x8b44f7af),T2 | ||
| 255 | and T1,A,T1 != | ||
| 256 | or T2,%lo(0x8b44f7af),T2 | ||
| 257 | xor T1,C,T1 | ||
| 258 | LOAD X(10),R10 | ||
| 259 | add T1,R9,T1 != | ||
| 260 | add T1,T2,T1 | ||
| 261 | add D,T1,D | ||
| 262 | sll D,12,T2 | ||
| 263 | srl D,32-12,D != | ||
| 264 | or D,T2,D | ||
| 265 | xor A,B,T1 | ||
| 266 | add D,A,D | ||
| 267 | |||
| 268 | sethi %hi(0xffff5bb1),T2 != | ||
| 269 | and T1,D,T1 | ||
| 270 | or T2,%lo(0xffff5bb1),T2 | ||
| 271 | xor T1,B,T1 | ||
| 272 | add T1,R10,T1 != | ||
| 273 | LOAD X(11),R11 | ||
| 274 | add T1,T2,T1 | ||
| 275 | add C,T1,C | ||
| 276 | sll C,17,T2 != | ||
| 277 | srl C,32-17,C | ||
| 278 | or C,T2,C | ||
| 279 | xor D,A,T1 | ||
| 280 | add C,D,C != | ||
| 281 | |||
| 282 | sethi %hi(0x895cd7be),T2 | ||
| 283 | and T1,C,T1 | ||
| 284 | or T2,%lo(0x895cd7be),T2 | ||
| 285 | xor T1,A,T1 != | ||
| 286 | add T1,R11,T1 | ||
| 287 | LOAD X(12),R12 | ||
| 288 | add T1,T2,T1 | ||
| 289 | add B,T1,B != | ||
| 290 | sll B,22,T2 | ||
| 291 | srl B,32-22,B | ||
| 292 | or B,T2,B | ||
| 293 | xor C,D,T1 != | ||
| 294 | add B,C,B | ||
| 295 | |||
| 296 | sethi %hi(0x6b901122),T2 | ||
| 297 | and T1,B,T1 | ||
| 298 | or T2,%lo(0x6b901122),T2 != | ||
| 299 | xor T1,D,T1 | ||
| 300 | add T1,R12,T1 | ||
| 301 | LOAD X(13),R13 | ||
| 302 | add T1,T2,T1 != | ||
| 303 | add A,T1,A | ||
| 304 | sll A,7,T2 | ||
| 305 | srl A,32-7,A | ||
| 306 | or A,T2,A != | ||
| 307 | xor B,C,T1 | ||
| 308 | add A,B,A | ||
| 309 | |||
| 310 | sethi %hi(0xfd987193),T2 | ||
| 311 | and T1,A,T1 != | ||
| 312 | or T2,%lo(0xfd987193),T2 | ||
| 313 | xor T1,C,T1 | ||
| 314 | LOAD X(14),RX | ||
| 315 | add T1,R13,T1 != | ||
| 316 | add T1,T2,T1 | ||
| 317 | add D,T1,D | ||
| 318 | sll D,12,T2 | ||
| 319 | srl D,32-12,D != | ||
| 320 | or D,T2,D | ||
| 321 | xor A,B,T1 | ||
| 322 | add D,A,D | ||
| 323 | |||
| 324 | sethi %hi(0xa679438e),T2 != | ||
| 325 | and T1,D,T1 | ||
| 326 | or T2,%lo(0xa679438e),T2 | ||
| 327 | xor T1,B,T1 | ||
| 328 | add T1,RX,T1 != | ||
| 329 | LOAD X(15),RX | ||
| 330 | add T1,T2,T1 | ||
| 331 | add C,T1,C | ||
| 332 | sll C,17,T2 != | ||
| 333 | srl C,32-17,C | ||
| 334 | or C,T2,C | ||
| 335 | xor D,A,T1 | ||
| 336 | add C,D,C != | ||
| 337 | |||
| 338 | sethi %hi(0x49b40821),T2 | ||
| 339 | and T1,C,T1 | ||
| 340 | or T2,%lo(0x49b40821),T2 | ||
| 341 | xor T1,A,T1 != | ||
| 342 | add T1,RX,T1 | ||
| 343 | !pre-LOADed X(1),R1 | ||
| 344 | add T1,T2,T1 | ||
| 345 | add B,T1,B | ||
| 346 | sll B,22,T2 != | ||
| 347 | srl B,32-22,B | ||
| 348 | or B,T2,B | ||
| 349 | add B,C,B | ||
| 350 | |||
| 351 | !!!!!!!!Round 1 | ||
| 352 | |||
| 353 | xor B,C,T1 != | ||
| 354 | sethi %hi(0xf61e2562),T2 | ||
| 355 | and T1,D,T1 | ||
| 356 | or T2,%lo(0xf61e2562),T2 | ||
| 357 | xor T1,C,T1 != | ||
| 358 | add T1,R1,T1 | ||
| 359 | !pre-LOADed X(6),R6 | ||
| 360 | add T1,T2,T1 | ||
| 361 | add A,T1,A | ||
| 362 | sll A,5,T2 != | ||
| 363 | srl A,32-5,A | ||
| 364 | or A,T2,A | ||
| 365 | add A,B,A | ||
| 366 | |||
| 367 | xor A,B,T1 != | ||
| 368 | sethi %hi(0xc040b340),T2 | ||
| 369 | and T1,C,T1 | ||
| 370 | or T2,%lo(0xc040b340),T2 | ||
| 371 | xor T1,B,T1 != | ||
| 372 | add T1,R6,T1 | ||
| 373 | !pre-LOADed X(11),R11 | ||
| 374 | add T1,T2,T1 | ||
| 375 | add D,T1,D | ||
| 376 | sll D,9,T2 != | ||
| 377 | srl D,32-9,D | ||
| 378 | or D,T2,D | ||
| 379 | add D,A,D | ||
| 380 | |||
| 381 | xor D,A,T1 != | ||
| 382 | sethi %hi(0x265e5a51),T2 | ||
| 383 | and T1,B,T1 | ||
| 384 | or T2,%lo(0x265e5a51),T2 | ||
| 385 | xor T1,A,T1 != | ||
| 386 | add T1,R11,T1 | ||
| 387 | !pre-LOADed X(0),R0 | ||
| 388 | add T1,T2,T1 | ||
| 389 | add C,T1,C | ||
| 390 | sll C,14,T2 != | ||
| 391 | srl C,32-14,C | ||
| 392 | or C,T2,C | ||
| 393 | add C,D,C | ||
| 394 | |||
| 395 | xor C,D,T1 != | ||
| 396 | sethi %hi(0xe9b6c7aa),T2 | ||
| 397 | and T1,A,T1 | ||
| 398 | or T2,%lo(0xe9b6c7aa),T2 | ||
| 399 | xor T1,D,T1 != | ||
| 400 | add T1,R0,T1 | ||
| 401 | !pre-LOADed X(5),R5 | ||
| 402 | add T1,T2,T1 | ||
| 403 | add B,T1,B | ||
| 404 | sll B,20,T2 != | ||
| 405 | srl B,32-20,B | ||
| 406 | or B,T2,B | ||
| 407 | add B,C,B | ||
| 408 | |||
| 409 | xor B,C,T1 != | ||
| 410 | sethi %hi(0xd62f105d),T2 | ||
| 411 | and T1,D,T1 | ||
| 412 | or T2,%lo(0xd62f105d),T2 | ||
| 413 | xor T1,C,T1 != | ||
| 414 | add T1,R5,T1 | ||
| 415 | !pre-LOADed X(10),R10 | ||
| 416 | add T1,T2,T1 | ||
| 417 | add A,T1,A | ||
| 418 | sll A,5,T2 != | ||
| 419 | srl A,32-5,A | ||
| 420 | or A,T2,A | ||
| 421 | add A,B,A | ||
| 422 | |||
| 423 | xor A,B,T1 != | ||
| 424 | sethi %hi(0x02441453),T2 | ||
| 425 | and T1,C,T1 | ||
| 426 | or T2,%lo(0x02441453),T2 | ||
| 427 | xor T1,B,T1 != | ||
| 428 | add T1,R10,T1 | ||
| 429 | LOAD X(15),RX | ||
| 430 | add T1,T2,T1 | ||
| 431 | add D,T1,D != | ||
| 432 | sll D,9,T2 | ||
| 433 | srl D,32-9,D | ||
| 434 | or D,T2,D | ||
| 435 | add D,A,D != | ||
| 436 | |||
| 437 | xor D,A,T1 | ||
| 438 | sethi %hi(0xd8a1e681),T2 | ||
| 439 | and T1,B,T1 | ||
| 440 | or T2,%lo(0xd8a1e681),T2 != | ||
| 441 | xor T1,A,T1 | ||
| 442 | add T1,RX,T1 | ||
| 443 | !pre-LOADed X(4),R4 | ||
| 444 | add T1,T2,T1 | ||
| 445 | add C,T1,C != | ||
| 446 | sll C,14,T2 | ||
| 447 | srl C,32-14,C | ||
| 448 | or C,T2,C | ||
| 449 | add C,D,C != | ||
| 450 | |||
| 451 | xor C,D,T1 | ||
| 452 | sethi %hi(0xe7d3fbc8),T2 | ||
| 453 | and T1,A,T1 | ||
| 454 | or T2,%lo(0xe7d3fbc8),T2 != | ||
| 455 | xor T1,D,T1 | ||
| 456 | add T1,R4,T1 | ||
| 457 | !pre-LOADed X(9),R9 | ||
| 458 | add T1,T2,T1 | ||
| 459 | add B,T1,B != | ||
| 460 | sll B,20,T2 | ||
| 461 | srl B,32-20,B | ||
| 462 | or B,T2,B | ||
| 463 | add B,C,B != | ||
| 464 | |||
| 465 | xor B,C,T1 | ||
| 466 | sethi %hi(0x21e1cde6),T2 | ||
| 467 | and T1,D,T1 | ||
| 468 | or T2,%lo(0x21e1cde6),T2 != | ||
| 469 | xor T1,C,T1 | ||
| 470 | add T1,R9,T1 | ||
| 471 | LOAD X(14),RX | ||
| 472 | add T1,T2,T1 != | ||
| 473 | add A,T1,A | ||
| 474 | sll A,5,T2 | ||
| 475 | srl A,32-5,A | ||
| 476 | or A,T2,A != | ||
| 477 | add A,B,A | ||
| 478 | |||
| 479 | xor A,B,T1 | ||
| 480 | sethi %hi(0xc33707d6),T2 | ||
| 481 | and T1,C,T1 != | ||
| 482 | or T2,%lo(0xc33707d6),T2 | ||
| 483 | xor T1,B,T1 | ||
| 484 | add T1,RX,T1 | ||
| 485 | !pre-LOADed X(3),R3 | ||
| 486 | add T1,T2,T1 != | ||
| 487 | add D,T1,D | ||
| 488 | sll D,9,T2 | ||
| 489 | srl D,32-9,D | ||
| 490 | or D,T2,D != | ||
| 491 | add D,A,D | ||
| 492 | |||
| 493 | xor D,A,T1 | ||
| 494 | sethi %hi(0xf4d50d87),T2 | ||
| 495 | and T1,B,T1 != | ||
| 496 | or T2,%lo(0xf4d50d87),T2 | ||
| 497 | xor T1,A,T1 | ||
| 498 | add T1,R3,T1 | ||
| 499 | !pre-LOADed X(8),R8 | ||
| 500 | add T1,T2,T1 != | ||
| 501 | add C,T1,C | ||
| 502 | sll C,14,T2 | ||
| 503 | srl C,32-14,C | ||
| 504 | or C,T2,C != | ||
| 505 | add C,D,C | ||
| 506 | |||
| 507 | xor C,D,T1 | ||
| 508 | sethi %hi(0x455a14ed),T2 | ||
| 509 | and T1,A,T1 != | ||
| 510 | or T2,%lo(0x455a14ed),T2 | ||
| 511 | xor T1,D,T1 | ||
| 512 | add T1,R8,T1 | ||
| 513 | !pre-LOADed X(13),R13 | ||
| 514 | add T1,T2,T1 != | ||
| 515 | add B,T1,B | ||
| 516 | sll B,20,T2 | ||
| 517 | srl B,32-20,B | ||
| 518 | or B,T2,B != | ||
| 519 | add B,C,B | ||
| 520 | |||
| 521 | xor B,C,T1 | ||
| 522 | sethi %hi(0xa9e3e905),T2 | ||
| 523 | and T1,D,T1 != | ||
| 524 | or T2,%lo(0xa9e3e905),T2 | ||
| 525 | xor T1,C,T1 | ||
| 526 | add T1,R13,T1 | ||
| 527 | !pre-LOADed X(2),R2 | ||
| 528 | add T1,T2,T1 != | ||
| 529 | add A,T1,A | ||
| 530 | sll A,5,T2 | ||
| 531 | srl A,32-5,A | ||
| 532 | or A,T2,A != | ||
| 533 | add A,B,A | ||
| 534 | |||
| 535 | xor A,B,T1 | ||
| 536 | sethi %hi(0xfcefa3f8),T2 | ||
| 537 | and T1,C,T1 != | ||
| 538 | or T2,%lo(0xfcefa3f8),T2 | ||
| 539 | xor T1,B,T1 | ||
| 540 | add T1,R2,T1 | ||
| 541 | !pre-LOADed X(7),R7 | ||
| 542 | add T1,T2,T1 != | ||
| 543 | add D,T1,D | ||
| 544 | sll D,9,T2 | ||
| 545 | srl D,32-9,D | ||
| 546 | or D,T2,D != | ||
| 547 | add D,A,D | ||
| 548 | |||
| 549 | xor D,A,T1 | ||
| 550 | sethi %hi(0x676f02d9),T2 | ||
| 551 | and T1,B,T1 != | ||
| 552 | or T2,%lo(0x676f02d9),T2 | ||
| 553 | xor T1,A,T1 | ||
| 554 | add T1,R7,T1 | ||
| 555 | !pre-LOADed X(12),R12 | ||
| 556 | add T1,T2,T1 != | ||
| 557 | add C,T1,C | ||
| 558 | sll C,14,T2 | ||
| 559 | srl C,32-14,C | ||
| 560 | or C,T2,C != | ||
| 561 | add C,D,C | ||
| 562 | |||
| 563 | xor C,D,T1 | ||
| 564 | sethi %hi(0x8d2a4c8a),T2 | ||
| 565 | and T1,A,T1 != | ||
| 566 | or T2,%lo(0x8d2a4c8a),T2 | ||
| 567 | xor T1,D,T1 | ||
| 568 | add T1,R12,T1 | ||
| 569 | !pre-LOADed X(5),R5 | ||
| 570 | add T1,T2,T1 != | ||
| 571 | add B,T1,B | ||
| 572 | sll B,20,T2 | ||
| 573 | srl B,32-20,B | ||
| 574 | or B,T2,B != | ||
| 575 | add B,C,B | ||
| 576 | |||
| 577 | !!!!!!!!Round 2 | ||
| 578 | |||
| 579 | xor B,C,T1 | ||
| 580 | sethi %hi(0xfffa3942),T2 | ||
| 581 | xor T1,D,T1 != | ||
| 582 | or T2,%lo(0xfffa3942),T2 | ||
| 583 | add T1,R5,T1 | ||
| 584 | !pre-LOADed X(8),R8 | ||
| 585 | add T1,T2,T1 | ||
| 586 | add A,T1,A != | ||
| 587 | sll A,4,T2 | ||
| 588 | srl A,32-4,A | ||
| 589 | or A,T2,A | ||
| 590 | add A,B,A != | ||
| 591 | |||
| 592 | xor A,B,T1 | ||
| 593 | sethi %hi(0x8771f681),T2 | ||
| 594 | xor T1,C,T1 | ||
| 595 | or T2,%lo(0x8771f681),T2 != | ||
| 596 | add T1,R8,T1 | ||
| 597 | !pre-LOADed X(11),R11 | ||
| 598 | add T1,T2,T1 | ||
| 599 | add D,T1,D | ||
| 600 | sll D,11,T2 != | ||
| 601 | srl D,32-11,D | ||
| 602 | or D,T2,D | ||
| 603 | add D,A,D | ||
| 604 | |||
| 605 | xor D,A,T1 != | ||
| 606 | sethi %hi(0x6d9d6122),T2 | ||
| 607 | xor T1,B,T1 | ||
| 608 | or T2,%lo(0x6d9d6122),T2 | ||
| 609 | add T1,R11,T1 != | ||
| 610 | LOAD X(14),RX | ||
| 611 | add T1,T2,T1 | ||
| 612 | add C,T1,C | ||
| 613 | sll C,16,T2 != | ||
| 614 | srl C,32-16,C | ||
| 615 | or C,T2,C | ||
| 616 | add C,D,C | ||
| 617 | |||
| 618 | xor C,D,T1 != | ||
| 619 | sethi %hi(0xfde5380c),T2 | ||
| 620 | xor T1,A,T1 | ||
| 621 | or T2,%lo(0xfde5380c),T2 | ||
| 622 | add T1,RX,T1 != | ||
| 623 | !pre-LOADed X(1),R1 | ||
| 624 | add T1,T2,T1 | ||
| 625 | add B,T1,B | ||
| 626 | sll B,23,T2 | ||
| 627 | srl B,32-23,B != | ||
| 628 | or B,T2,B | ||
| 629 | add B,C,B | ||
| 630 | |||
| 631 | xor B,C,T1 | ||
| 632 | sethi %hi(0xa4beea44),T2 != | ||
| 633 | xor T1,D,T1 | ||
| 634 | or T2,%lo(0xa4beea44),T2 | ||
| 635 | add T1,R1,T1 | ||
| 636 | !pre-LOADed X(4),R4 | ||
| 637 | add T1,T2,T1 != | ||
| 638 | add A,T1,A | ||
| 639 | sll A,4,T2 | ||
| 640 | srl A,32-4,A | ||
| 641 | or A,T2,A != | ||
| 642 | add A,B,A | ||
| 643 | |||
| 644 | xor A,B,T1 | ||
| 645 | sethi %hi(0x4bdecfa9),T2 | ||
| 646 | xor T1,C,T1 != | ||
| 647 | or T2,%lo(0x4bdecfa9),T2 | ||
| 648 | add T1,R4,T1 | ||
| 649 | !pre-LOADed X(7),R7 | ||
| 650 | add T1,T2,T1 | ||
| 651 | add D,T1,D != | ||
| 652 | sll D,11,T2 | ||
| 653 | srl D,32-11,D | ||
| 654 | or D,T2,D | ||
| 655 | add D,A,D != | ||
| 656 | |||
| 657 | xor D,A,T1 | ||
| 658 | sethi %hi(0xf6bb4b60),T2 | ||
| 659 | xor T1,B,T1 | ||
| 660 | or T2,%lo(0xf6bb4b60),T2 != | ||
| 661 | add T1,R7,T1 | ||
| 662 | !pre-LOADed X(10),R10 | ||
| 663 | add T1,T2,T1 | ||
| 664 | add C,T1,C | ||
| 665 | sll C,16,T2 != | ||
| 666 | srl C,32-16,C | ||
| 667 | or C,T2,C | ||
| 668 | add C,D,C | ||
| 669 | |||
| 670 | xor C,D,T1 != | ||
| 671 | sethi %hi(0xbebfbc70),T2 | ||
| 672 | xor T1,A,T1 | ||
| 673 | or T2,%lo(0xbebfbc70),T2 | ||
| 674 | add T1,R10,T1 != | ||
| 675 | !pre-LOADed X(13),R13 | ||
| 676 | add T1,T2,T1 | ||
| 677 | add B,T1,B | ||
| 678 | sll B,23,T2 | ||
| 679 | srl B,32-23,B != | ||
| 680 | or B,T2,B | ||
| 681 | add B,C,B | ||
| 682 | |||
| 683 | xor B,C,T1 | ||
| 684 | sethi %hi(0x289b7ec6),T2 != | ||
| 685 | xor T1,D,T1 | ||
| 686 | or T2,%lo(0x289b7ec6),T2 | ||
| 687 | add T1,R13,T1 | ||
| 688 | !pre-LOADed X(0),R0 | ||
| 689 | add T1,T2,T1 != | ||
| 690 | add A,T1,A | ||
| 691 | sll A,4,T2 | ||
| 692 | srl A,32-4,A | ||
| 693 | or A,T2,A != | ||
| 694 | add A,B,A | ||
| 695 | |||
| 696 | xor A,B,T1 | ||
| 697 | sethi %hi(0xeaa127fa),T2 | ||
| 698 | xor T1,C,T1 != | ||
| 699 | or T2,%lo(0xeaa127fa),T2 | ||
| 700 | add T1,R0,T1 | ||
| 701 | !pre-LOADed X(3),R3 | ||
| 702 | add T1,T2,T1 | ||
| 703 | add D,T1,D != | ||
| 704 | sll D,11,T2 | ||
| 705 | srl D,32-11,D | ||
| 706 | or D,T2,D | ||
| 707 | add D,A,D != | ||
| 708 | |||
| 709 | xor D,A,T1 | ||
| 710 | sethi %hi(0xd4ef3085),T2 | ||
| 711 | xor T1,B,T1 | ||
| 712 | or T2,%lo(0xd4ef3085),T2 != | ||
| 713 | add T1,R3,T1 | ||
| 714 | !pre-LOADed X(6),R6 | ||
| 715 | add T1,T2,T1 | ||
| 716 | add C,T1,C | ||
| 717 | sll C,16,T2 != | ||
| 718 | srl C,32-16,C | ||
| 719 | or C,T2,C | ||
| 720 | add C,D,C | ||
| 721 | |||
| 722 | xor C,D,T1 != | ||
| 723 | sethi %hi(0x04881d05),T2 | ||
| 724 | xor T1,A,T1 | ||
| 725 | or T2,%lo(0x04881d05),T2 | ||
| 726 | add T1,R6,T1 != | ||
| 727 | !pre-LOADed X(9),R9 | ||
| 728 | add T1,T2,T1 | ||
| 729 | add B,T1,B | ||
| 730 | sll B,23,T2 | ||
| 731 | srl B,32-23,B != | ||
| 732 | or B,T2,B | ||
| 733 | add B,C,B | ||
| 734 | |||
| 735 | xor B,C,T1 | ||
| 736 | sethi %hi(0xd9d4d039),T2 != | ||
| 737 | xor T1,D,T1 | ||
| 738 | or T2,%lo(0xd9d4d039),T2 | ||
| 739 | add T1,R9,T1 | ||
| 740 | !pre-LOADed X(12),R12 | ||
| 741 | add T1,T2,T1 != | ||
| 742 | add A,T1,A | ||
| 743 | sll A,4,T2 | ||
| 744 | srl A,32-4,A | ||
| 745 | or A,T2,A != | ||
| 746 | add A,B,A | ||
| 747 | |||
| 748 | xor A,B,T1 | ||
| 749 | sethi %hi(0xe6db99e5),T2 | ||
| 750 | xor T1,C,T1 != | ||
| 751 | or T2,%lo(0xe6db99e5),T2 | ||
| 752 | add T1,R12,T1 | ||
| 753 | LOAD X(15),RX | ||
| 754 | add T1,T2,T1 != | ||
| 755 | add D,T1,D | ||
| 756 | sll D,11,T2 | ||
| 757 | srl D,32-11,D | ||
| 758 | or D,T2,D != | ||
| 759 | add D,A,D | ||
| 760 | |||
| 761 | xor D,A,T1 | ||
| 762 | sethi %hi(0x1fa27cf8),T2 | ||
| 763 | xor T1,B,T1 != | ||
| 764 | or T2,%lo(0x1fa27cf8),T2 | ||
| 765 | add T1,RX,T1 | ||
| 766 | !pre-LOADed X(2),R2 | ||
| 767 | add T1,T2,T1 | ||
| 768 | add C,T1,C != | ||
| 769 | sll C,16,T2 | ||
| 770 | srl C,32-16,C | ||
| 771 | or C,T2,C | ||
| 772 | add C,D,C != | ||
| 773 | |||
| 774 | xor C,D,T1 | ||
| 775 | sethi %hi(0xc4ac5665),T2 | ||
| 776 | xor T1,A,T1 | ||
| 777 | or T2,%lo(0xc4ac5665),T2 != | ||
| 778 | add T1,R2,T1 | ||
| 779 | !pre-LOADed X(0),R0 | ||
| 780 | add T1,T2,T1 | ||
| 781 | add B,T1,B | ||
| 782 | sll B,23,T2 != | ||
| 783 | srl B,32-23,B | ||
| 784 | or B,T2,B | ||
| 785 | add B,C,B | ||
| 786 | |||
| 787 | !!!!!!!!Round 3 | ||
| 788 | |||
| 789 | orn B,D,T1 != | ||
| 790 | sethi %hi(0xf4292244),T2 | ||
| 791 | xor T1,C,T1 | ||
| 792 | or T2,%lo(0xf4292244),T2 | ||
| 793 | add T1,R0,T1 != | ||
| 794 | !pre-LOADed X(7),R7 | ||
| 795 | add T1,T2,T1 | ||
| 796 | add A,T1,A | ||
| 797 | sll A,6,T2 | ||
| 798 | srl A,32-6,A != | ||
| 799 | or A,T2,A | ||
| 800 | add A,B,A | ||
| 801 | |||
| 802 | orn A,C,T1 | ||
| 803 | sethi %hi(0x432aff97),T2 != | ||
| 804 | xor T1,B,T1 | ||
| 805 | or T2,%lo(0x432aff97),T2 | ||
| 806 | LOAD X(14),RX | ||
| 807 | add T1,R7,T1 != | ||
| 808 | add T1,T2,T1 | ||
| 809 | add D,T1,D | ||
| 810 | sll D,10,T2 | ||
| 811 | srl D,32-10,D != | ||
| 812 | or D,T2,D | ||
| 813 | add D,A,D | ||
| 814 | |||
| 815 | orn D,B,T1 | ||
| 816 | sethi %hi(0xab9423a7),T2 != | ||
| 817 | xor T1,A,T1 | ||
| 818 | or T2,%lo(0xab9423a7),T2 | ||
| 819 | add T1,RX,T1 | ||
| 820 | !pre-LOADed X(5),R5 | ||
| 821 | add T1,T2,T1 != | ||
| 822 | add C,T1,C | ||
| 823 | sll C,15,T2 | ||
| 824 | srl C,32-15,C | ||
| 825 | or C,T2,C != | ||
| 826 | add C,D,C | ||
| 827 | |||
| 828 | orn C,A,T1 | ||
| 829 | sethi %hi(0xfc93a039),T2 | ||
| 830 | xor T1,D,T1 != | ||
| 831 | or T2,%lo(0xfc93a039),T2 | ||
| 832 | add T1,R5,T1 | ||
| 833 | !pre-LOADed X(12),R12 | ||
| 834 | add T1,T2,T1 | ||
| 835 | add B,T1,B != | ||
| 836 | sll B,21,T2 | ||
| 837 | srl B,32-21,B | ||
| 838 | or B,T2,B | ||
| 839 | add B,C,B != | ||
| 840 | |||
| 841 | orn B,D,T1 | ||
| 842 | sethi %hi(0x655b59c3),T2 | ||
| 843 | xor T1,C,T1 | ||
| 844 | or T2,%lo(0x655b59c3),T2 != | ||
| 845 | add T1,R12,T1 | ||
| 846 | !pre-LOADed X(3),R3 | ||
| 847 | add T1,T2,T1 | ||
| 848 | add A,T1,A | ||
| 849 | sll A,6,T2 != | ||
| 850 | srl A,32-6,A | ||
| 851 | or A,T2,A | ||
| 852 | add A,B,A | ||
| 853 | |||
| 854 | orn A,C,T1 != | ||
| 855 | sethi %hi(0x8f0ccc92),T2 | ||
| 856 | xor T1,B,T1 | ||
| 857 | or T2,%lo(0x8f0ccc92),T2 | ||
| 858 | add T1,R3,T1 != | ||
| 859 | !pre-LOADed X(10),R10 | ||
| 860 | add T1,T2,T1 | ||
| 861 | add D,T1,D | ||
| 862 | sll D,10,T2 | ||
| 863 | srl D,32-10,D != | ||
| 864 | or D,T2,D | ||
| 865 | add D,A,D | ||
| 866 | |||
| 867 | orn D,B,T1 | ||
| 868 | sethi %hi(0xffeff47d),T2 != | ||
| 869 | xor T1,A,T1 | ||
| 870 | or T2,%lo(0xffeff47d),T2 | ||
| 871 | add T1,R10,T1 | ||
| 872 | !pre-LOADed X(1),R1 | ||
| 873 | add T1,T2,T1 != | ||
| 874 | add C,T1,C | ||
| 875 | sll C,15,T2 | ||
| 876 | srl C,32-15,C | ||
| 877 | or C,T2,C != | ||
| 878 | add C,D,C | ||
| 879 | |||
| 880 | orn C,A,T1 | ||
| 881 | sethi %hi(0x85845dd1),T2 | ||
| 882 | xor T1,D,T1 != | ||
| 883 | or T2,%lo(0x85845dd1),T2 | ||
| 884 | add T1,R1,T1 | ||
| 885 | !pre-LOADed X(8),R8 | ||
| 886 | add T1,T2,T1 | ||
| 887 | add B,T1,B != | ||
| 888 | sll B,21,T2 | ||
| 889 | srl B,32-21,B | ||
| 890 | or B,T2,B | ||
| 891 | add B,C,B != | ||
| 892 | |||
| 893 | orn B,D,T1 | ||
| 894 | sethi %hi(0x6fa87e4f),T2 | ||
| 895 | xor T1,C,T1 | ||
| 896 | or T2,%lo(0x6fa87e4f),T2 != | ||
| 897 | add T1,R8,T1 | ||
| 898 | LOAD X(15),RX | ||
| 899 | add T1,T2,T1 | ||
| 900 | add A,T1,A != | ||
| 901 | sll A,6,T2 | ||
| 902 | srl A,32-6,A | ||
| 903 | or A,T2,A | ||
| 904 | add A,B,A != | ||
| 905 | |||
| 906 | orn A,C,T1 | ||
| 907 | sethi %hi(0xfe2ce6e0),T2 | ||
| 908 | xor T1,B,T1 | ||
| 909 | or T2,%lo(0xfe2ce6e0),T2 != | ||
| 910 | add T1,RX,T1 | ||
| 911 | !pre-LOADed X(6),R6 | ||
| 912 | add T1,T2,T1 | ||
| 913 | add D,T1,D | ||
| 914 | sll D,10,T2 != | ||
| 915 | srl D,32-10,D | ||
| 916 | or D,T2,D | ||
| 917 | add D,A,D | ||
| 918 | |||
| 919 | orn D,B,T1 != | ||
| 920 | sethi %hi(0xa3014314),T2 | ||
| 921 | xor T1,A,T1 | ||
| 922 | or T2,%lo(0xa3014314),T2 | ||
| 923 | add T1,R6,T1 != | ||
| 924 | !pre-LOADed X(13),R13 | ||
| 925 | add T1,T2,T1 | ||
| 926 | add C,T1,C | ||
| 927 | sll C,15,T2 | ||
| 928 | srl C,32-15,C != | ||
| 929 | or C,T2,C | ||
| 930 | add C,D,C | ||
| 931 | |||
| 932 | orn C,A,T1 | ||
| 933 | sethi %hi(0x4e0811a1),T2 != | ||
| 934 | xor T1,D,T1 | ||
| 935 | or T2,%lo(0x4e0811a1),T2 | ||
| 936 | !pre-LOADed X(4),R4 | ||
| 937 | ld [Aptr],Aval | ||
| 938 | add T1,R13,T1 != | ||
| 939 | add T1,T2,T1 | ||
| 940 | add B,T1,B | ||
| 941 | sll B,21,T2 | ||
| 942 | srl B,32-21,B != | ||
| 943 | or B,T2,B | ||
| 944 | add B,C,B | ||
| 945 | |||
| 946 | orn B,D,T1 | ||
| 947 | sethi %hi(0xf7537e82),T2 != | ||
| 948 | xor T1,C,T1 | ||
| 949 | or T2,%lo(0xf7537e82),T2 | ||
| 950 | !pre-LOADed X(11),R11 | ||
| 951 | ld [Dptr],Dval | ||
| 952 | add T1,R4,T1 != | ||
| 953 | add T1,T2,T1 | ||
| 954 | add A,T1,A | ||
| 955 | sll A,6,T2 | ||
| 956 | srl A,32-6,A != | ||
| 957 | or A,T2,A | ||
| 958 | add A,B,A | ||
| 959 | |||
| 960 | orn A,C,T1 | ||
| 961 | sethi %hi(0xbd3af235),T2 != | ||
| 962 | xor T1,B,T1 | ||
| 963 | or T2,%lo(0xbd3af235),T2 | ||
| 964 | !pre-LOADed X(2),R2 | ||
| 965 | ld [Cptr],Cval | ||
| 966 | add T1,R11,T1 != | ||
| 967 | add T1,T2,T1 | ||
| 968 | add D,T1,D | ||
| 969 | sll D,10,T2 | ||
| 970 | srl D,32-10,D != | ||
| 971 | or D,T2,D | ||
| 972 | add D,A,D | ||
| 973 | |||
| 974 | orn D,B,T1 | ||
| 975 | sethi %hi(0x2ad7d2bb),T2 != | ||
| 976 | xor T1,A,T1 | ||
| 977 | or T2,%lo(0x2ad7d2bb),T2 | ||
| 978 | !pre-LOADed X(9),R9 | ||
| 979 | ld [Bptr],Bval | ||
| 980 | add T1,R2,T1 != | ||
| 981 | add Aval,A,Aval | ||
| 982 | add T1,T2,T1 | ||
| 983 | st Aval,[Aptr] | ||
| 984 | add C,T1,C != | ||
| 985 | sll C,15,T2 | ||
| 986 | add Dval,D,Dval | ||
| 987 | srl C,32-15,C | ||
| 988 | or C,T2,C != | ||
| 989 | st Dval,[Dptr] | ||
| 990 | add C,D,C | ||
| 991 | |||
| 992 | orn C,A,T1 | ||
| 993 | sethi %hi(0xeb86d391),T2 != | ||
| 994 | xor T1,D,T1 | ||
| 995 | or T2,%lo(0xeb86d391),T2 | ||
| 996 | add T1,R9,T1 | ||
| 997 | !pre-LOADed X(0),R0 | ||
| 998 | mov Aval,A != | ||
| 999 | add T1,T2,T1 | ||
| 1000 | mov Dval,D | ||
| 1001 | add B,T1,B | ||
| 1002 | sll B,21,T2 != | ||
| 1003 | add Cval,C,Cval | ||
| 1004 | srl B,32-21,B | ||
| 1005 | st Cval,[Cptr] | ||
| 1006 | or B,T2,B != | ||
| 1007 | add B,C,B | ||
| 1008 | |||
| 1009 | deccc %i2 | ||
| 1010 | mov Cval,C | ||
| 1011 | add B,Bval,B != | ||
| 1012 | inc 64,%i1 | ||
| 1013 | nop | ||
| 1014 | st B,[Bptr] | ||
| 1015 | nop != | ||
| 1016 | |||
| 1017 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1018 | bg,a,pt %icc,.Lmd5_block_loop | ||
| 1019 | #else | ||
| 1020 | bg,a .Lmd5_block_loop | ||
| 1021 | #endif | ||
| 1022 | LOAD X(0),R0 | ||
| 1023 | |||
| 1024 | #ifdef ASI_PRIMARY_LITTLE | ||
| 1025 | wr %g0,%o7,%asi | ||
| 1026 | #endif | ||
| 1027 | ret | ||
| 1028 | restore %g0,0,%o0 | ||
| 1029 | |||
| 1030 | .type md5_block,#function | ||
| 1031 | .size md5_block,(.-md5_block) | ||
diff --git a/src/lib/libcrypto/err/err_bio.c b/src/lib/libcrypto/mdc2/mdc2_one.c index a42f804840..72647f67ed 100644 --- a/src/lib/libcrypto/err/err_bio.c +++ b/src/lib/libcrypto/mdc2/mdc2_one.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* crypto/err/err_prn.c */ | 1 | /* crypto/mdc2/mdc2_one.c */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -58,18 +58,19 @@ | |||
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include <openssl/lhash.h> | 61 | #include <openssl/mdc2.h> |
| 62 | #include <openssl/crypto.h> | ||
| 63 | #include <openssl/buffer.h> | ||
| 64 | #include <openssl/err.h> | ||
| 65 | 62 | ||
| 66 | static int print_bio(const char *str, size_t len, void *bp) | 63 | unsigned char *MDC2(const unsigned char *d, size_t n, unsigned char *md) |
| 67 | { | 64 | { |
| 68 | return BIO_write((BIO *)bp, str, len); | 65 | MDC2_CTX c; |
| 69 | } | 66 | static unsigned char m[MDC2_DIGEST_LENGTH]; |
| 70 | void ERR_print_errors(BIO *bp) | 67 | |
| 71 | { | 68 | if (md == NULL) md=m; |
| 72 | ERR_print_errors_cb(print_bio, bp); | 69 | if (!MDC2_Init(&c)) |
| 70 | return NULL; | ||
| 71 | MDC2_Update(&c,d,n); | ||
| 72 | MDC2_Final(md,&c); | ||
| 73 | OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */ | ||
| 74 | return(md); | ||
| 73 | } | 75 | } |
| 74 | 76 | ||
| 75 | |||
diff --git a/src/lib/libssl/src/fips/dsa/fips_dsa_key.c b/src/lib/libcrypto/mdc2/mdc2dgst.c index b5f8cfa1d0..4aa406edc3 100644 --- a/src/lib/libssl/src/fips/dsa/fips_dsa_key.c +++ b/src/lib/libcrypto/mdc2/mdc2dgst.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* crypto/dsa/dsa_key.c */ | 1 | /* crypto/mdc2/mdc2dgst.c */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -57,113 +57,143 @@ | |||
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include <time.h> | 60 | #include <stdlib.h> |
| 61 | #ifndef OPENSSL_NO_SHA | 61 | #include <string.h> |
| 62 | #include <openssl/bn.h> | 62 | #include <openssl/des.h> |
| 63 | #include <openssl/dsa.h> | 63 | #include <openssl/mdc2.h> |
| 64 | #include <openssl/rand.h> | 64 | |
| 65 | #include <openssl/err.h> | 65 | #undef c2l |
| 66 | #include <openssl/evp.h> | 66 | #define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ |
| 67 | #include <openssl/fips.h> | 67 | l|=((DES_LONG)(*((c)++)))<< 8L, \ |
| 68 | #include "fips_locl.h" | 68 | l|=((DES_LONG)(*((c)++)))<<16L, \ |
| 69 | 69 | l|=((DES_LONG)(*((c)++)))<<24L) | |
| 70 | #ifdef OPENSSL_FIPS | 70 | |
| 71 | 71 | #undef l2c | |
| 72 | static int fips_dsa_pairwise_fail = 0; | 72 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ |
| 73 | 73 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | |
| 74 | void FIPS_corrupt_dsa_keygen(void) | 74 | *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ |
| 75 | *((c)++)=(unsigned char)(((l)>>24L)&0xff)) | ||
| 76 | |||
| 77 | static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len); | ||
| 78 | int MDC2_Init(MDC2_CTX *c) | ||
| 75 | { | 79 | { |
| 76 | fips_dsa_pairwise_fail = 1; | 80 | c->num=0; |
| 81 | c->pad_type=1; | ||
| 82 | memset(&(c->h[0]),0x52,MDC2_BLOCK); | ||
| 83 | memset(&(c->hh[0]),0x25,MDC2_BLOCK); | ||
| 84 | return 1; | ||
| 77 | } | 85 | } |
| 78 | 86 | ||
| 79 | static int dsa_builtin_keygen(DSA *dsa); | 87 | int MDC2_Update(MDC2_CTX *c, const unsigned char *in, size_t len) |
| 80 | |||
| 81 | int fips_check_dsa(DSA *dsa) | ||
| 82 | { | 88 | { |
| 83 | EVP_PKEY pk; | 89 | size_t i,j; |
| 84 | unsigned char tbs[] = "DSA Pairwise Check Data"; | ||
| 85 | pk.type = EVP_PKEY_DSA; | ||
| 86 | pk.pkey.dsa = dsa; | ||
| 87 | 90 | ||
| 88 | if (!fips_pkey_signature_test(&pk, tbs, -1, | 91 | i=c->num; |
| 89 | NULL, 0, EVP_dss1(), 0, NULL)) | 92 | if (i != 0) |
| 90 | { | 93 | { |
| 91 | FIPSerr(FIPS_F_FIPS_CHECK_DSA,FIPS_R_PAIRWISE_TEST_FAILED); | 94 | if (i+len < MDC2_BLOCK) |
| 92 | fips_set_selftest_fail(); | 95 | { |
| 93 | return 0; | 96 | /* partial block */ |
| 97 | memcpy(&(c->data[i]),in,len); | ||
| 98 | c->num+=(int)len; | ||
| 99 | return 1; | ||
| 100 | } | ||
| 101 | else | ||
| 102 | { | ||
| 103 | /* filled one */ | ||
| 104 | j=MDC2_BLOCK-i; | ||
| 105 | memcpy(&(c->data[i]),in,j); | ||
| 106 | len-=j; | ||
| 107 | in+=j; | ||
| 108 | c->num=0; | ||
| 109 | mdc2_body(c,&(c->data[0]),MDC2_BLOCK); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | i=len&~((size_t)MDC2_BLOCK-1); | ||
| 113 | if (i > 0) mdc2_body(c,in,i); | ||
| 114 | j=len-i; | ||
| 115 | if (j > 0) | ||
| 116 | { | ||
| 117 | memcpy(&(c->data[0]),&(in[i]),j); | ||
| 118 | c->num=(int)j; | ||
| 94 | } | 119 | } |
| 95 | return 1; | 120 | return 1; |
| 96 | } | 121 | } |
| 97 | 122 | ||
| 98 | int DSA_generate_key(DSA *dsa) | 123 | static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len) |
| 99 | { | ||
| 100 | if(dsa->meth->dsa_keygen) | ||
| 101 | return dsa->meth->dsa_keygen(dsa); | ||
| 102 | return dsa_builtin_keygen(dsa); | ||
| 103 | } | ||
| 104 | |||
| 105 | static int dsa_builtin_keygen(DSA *dsa) | ||
| 106 | { | 124 | { |
| 107 | int ok=0; | 125 | register DES_LONG tin0,tin1; |
| 108 | BN_CTX *ctx=NULL; | 126 | register DES_LONG ttin0,ttin1; |
| 109 | BIGNUM *pub_key=NULL,*priv_key=NULL; | 127 | DES_LONG d[2],dd[2]; |
| 110 | 128 | DES_key_schedule k; | |
| 111 | if (FIPS_mode() && (BN_num_bits(dsa->p) < OPENSSL_DSA_FIPS_MIN_MODULUS_BITS)) | 129 | unsigned char *p; |
| 130 | size_t i; | ||
| 131 | |||
| 132 | for (i=0; i<len; i+=8) | ||
| 112 | { | 133 | { |
| 113 | DSAerr(DSA_F_DSA_BUILTIN_KEYGEN, DSA_R_KEY_SIZE_TOO_SMALL); | 134 | c2l(in,tin0); d[0]=dd[0]=tin0; |
| 114 | goto err; | 135 | c2l(in,tin1); d[1]=dd[1]=tin1; |
| 136 | c->h[0]=(c->h[0]&0x9f)|0x40; | ||
| 137 | c->hh[0]=(c->hh[0]&0x9f)|0x20; | ||
| 138 | |||
| 139 | DES_set_odd_parity(&c->h); | ||
| 140 | DES_set_key_unchecked(&c->h,&k); | ||
| 141 | DES_encrypt1(d,&k,1); | ||
| 142 | |||
| 143 | DES_set_odd_parity(&c->hh); | ||
| 144 | DES_set_key_unchecked(&c->hh,&k); | ||
| 145 | DES_encrypt1(dd,&k,1); | ||
| 146 | |||
| 147 | ttin0=tin0^dd[0]; | ||
| 148 | ttin1=tin1^dd[1]; | ||
| 149 | tin0^=d[0]; | ||
| 150 | tin1^=d[1]; | ||
| 151 | |||
| 152 | p=c->h; | ||
| 153 | l2c(tin0,p); | ||
| 154 | l2c(ttin1,p); | ||
| 155 | p=c->hh; | ||
| 156 | l2c(ttin0,p); | ||
| 157 | l2c(tin1,p); | ||
| 115 | } | 158 | } |
| 159 | } | ||
| 116 | 160 | ||
| 117 | if ((ctx=BN_CTX_new()) == NULL) goto err; | 161 | int MDC2_Final(unsigned char *md, MDC2_CTX *c) |
| 162 | { | ||
| 163 | unsigned int i; | ||
| 164 | int j; | ||
| 118 | 165 | ||
| 119 | if (dsa->priv_key == NULL) | 166 | i=c->num; |
| 167 | j=c->pad_type; | ||
| 168 | if ((i > 0) || (j == 2)) | ||
| 120 | { | 169 | { |
| 121 | if ((priv_key=BN_new()) == NULL) goto err; | 170 | if (j == 2) |
| 171 | c->data[i++]=0x80; | ||
| 172 | memset(&(c->data[i]),0,MDC2_BLOCK-i); | ||
| 173 | mdc2_body(c,c->data,MDC2_BLOCK); | ||
| 122 | } | 174 | } |
| 123 | else | 175 | memcpy(md,(char *)c->h,MDC2_BLOCK); |
| 124 | priv_key=dsa->priv_key; | 176 | memcpy(&(md[MDC2_BLOCK]),(char *)c->hh,MDC2_BLOCK); |
| 177 | return 1; | ||
| 178 | } | ||
| 125 | 179 | ||
| 126 | do | 180 | #undef TEST |
| 127 | if (!BN_rand_range(priv_key,dsa->q)) goto err; | ||
| 128 | while (BN_is_zero(priv_key)); | ||
| 129 | 181 | ||
| 130 | if (dsa->pub_key == NULL) | 182 | #ifdef TEST |
| 131 | { | 183 | main() |
| 132 | if ((pub_key=BN_new()) == NULL) goto err; | ||
| 133 | } | ||
| 134 | else | ||
| 135 | pub_key=dsa->pub_key; | ||
| 136 | |||
| 137 | { | 184 | { |
| 138 | BIGNUM local_prk; | 185 | unsigned char md[MDC2_DIGEST_LENGTH]; |
| 139 | BIGNUM *prk; | 186 | int i; |
| 140 | 187 | MDC2_CTX c; | |
| 141 | if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) | 188 | static char *text="Now is the time for all "; |
| 142 | { | 189 | |
| 143 | BN_init(&local_prk); | 190 | MDC2_Init(&c); |
| 144 | prk = &local_prk; | 191 | MDC2_Update(&c,text,strlen(text)); |
| 145 | BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME); | 192 | MDC2_Final(&(md[0]),&c); |
| 146 | } | 193 | |
| 147 | else | 194 | for (i=0; i<MDC2_DIGEST_LENGTH; i++) |
| 148 | prk = priv_key; | 195 | printf("%02X",md[i]); |
| 149 | 196 | printf("\n"); | |
| 150 | if (!BN_mod_exp(pub_key,dsa->g,prk,dsa->p,ctx)) goto err; | ||
| 151 | } | 197 | } |
| 152 | 198 | ||
| 153 | dsa->priv_key=priv_key; | ||
| 154 | dsa->pub_key=pub_key; | ||
| 155 | if (fips_dsa_pairwise_fail) | ||
| 156 | BN_add_word(dsa->pub_key, 1); | ||
| 157 | if(!fips_check_dsa(dsa)) | ||
| 158 | goto err; | ||
| 159 | ok=1; | ||
| 160 | |||
| 161 | err: | ||
| 162 | if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key); | ||
| 163 | if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key); | ||
| 164 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 165 | return(ok); | ||
| 166 | } | ||
| 167 | #endif | ||
| 168 | |||
| 169 | #endif | 199 | #endif |
diff --git a/src/lib/libcrypto/modes/Makefile b/src/lib/libcrypto/modes/Makefile new file mode 100644 index 0000000000..6c85861b6c --- /dev/null +++ b/src/lib/libcrypto/modes/Makefile | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | # | ||
| 2 | # OpenSSL/crypto/modes/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= modes | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
| 9 | CFLAG=-g | ||
| 10 | MAKEFILE= Makefile | ||
| 11 | AR= ar r | ||
| 12 | |||
| 13 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 14 | |||
| 15 | GENERAL=Makefile | ||
| 16 | TEST= | ||
| 17 | APPS= | ||
| 18 | |||
| 19 | LIB=$(TOP)/libcrypto.a | ||
| 20 | LIBSRC= cbc128.c ctr128.c cts128.c cfb128.c ofb128.c | ||
| 21 | LIBOBJ= cbc128.o ctr128.o cts128.o cfb128.o ofb128.o | ||
| 22 | |||
| 23 | SRC= $(LIBSRC) | ||
| 24 | |||
| 25 | #EXHEADER= store.h str_compat.h | ||
| 26 | EXHEADER= modes.h | ||
| 27 | HEADER= $(EXHEADER) | ||
| 28 | |||
| 29 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 30 | |||
| 31 | top: | ||
| 32 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 33 | |||
| 34 | all: lib | ||
| 35 | |||
| 36 | lib: $(LIBOBJ) | ||
| 37 | $(AR) $(LIB) $(LIBOBJ) | ||
| 38 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 39 | @touch lib | ||
| 40 | |||
| 41 | files: | ||
| 42 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 43 | |||
| 44 | links: | ||
| 45 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 46 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 47 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 48 | |||
| 49 | install: | ||
| 50 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 51 | @headerlist="$(EXHEADER)"; for i in $$headerlist; \ | ||
| 52 | do \ | ||
| 53 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 54 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 55 | done; | ||
| 56 | |||
| 57 | tags: | ||
| 58 | ctags $(SRC) | ||
| 59 | |||
| 60 | tests: | ||
| 61 | |||
| 62 | lint: | ||
| 63 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 64 | |||
| 65 | depend: | ||
| 66 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 67 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 68 | |||
| 69 | dclean: | ||
| 70 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 71 | mv -f Makefile.new $(MAKEFILE) | ||
| 72 | |||
| 73 | clean: | ||
| 74 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 75 | |||
| 76 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 77 | |||
| 78 | cbc128.o: cbc128.c modes.h | ||
| 79 | cfb128.o: cfb128.c modes.h | ||
| 80 | ctr128.o: ctr128.c modes.h | ||
| 81 | cts128.o: cts128.c modes.h | ||
| 82 | ofb128.o: modes.h ofb128.c | ||
diff --git a/src/lib/libcrypto/o_dir.c b/src/lib/libcrypto/o_dir.c new file mode 100644 index 0000000000..42891ea459 --- /dev/null +++ b/src/lib/libcrypto/o_dir.c | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | /* crypto/o_dir.c -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | ||
| 3 | * project 2004. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * openssl-core@openssl.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <e_os.h> | ||
| 61 | |||
| 62 | /* The routines really come from the Levitte Programming, so to make | ||
| 63 | life simple, let's just use the raw files and hack the symbols to | ||
| 64 | fit our namespace. */ | ||
| 65 | #define LP_DIR_CTX OPENSSL_DIR_CTX | ||
| 66 | #define LP_dir_context_st OPENSSL_dir_context_st | ||
| 67 | #define LP_find_file OPENSSL_DIR_read | ||
| 68 | #define LP_find_file_end OPENSSL_DIR_end | ||
| 69 | |||
| 70 | #include "o_dir.h" | ||
| 71 | |||
| 72 | #define LPDIR_H | ||
| 73 | #if defined OPENSSL_SYS_UNIX || defined DJGPP | ||
| 74 | #include "LPdir_unix.c" | ||
| 75 | #elif defined OPENSSL_SYS_VMS | ||
| 76 | #include "LPdir_vms.c" | ||
| 77 | #elif defined OPENSSL_SYS_WIN32 | ||
| 78 | #include "LPdir_win32.c" | ||
| 79 | #elif defined OPENSSL_SYS_WINCE | ||
| 80 | #include "LPdir_wince.c" | ||
| 81 | #else | ||
| 82 | #include "LPdir_nyi.c" | ||
| 83 | #endif | ||
diff --git a/src/lib/libcrypto/o_dir.h b/src/lib/libcrypto/o_dir.h new file mode 100644 index 0000000000..4b725c0312 --- /dev/null +++ b/src/lib/libcrypto/o_dir.h | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | /* crypto/o_dir.h -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* Copied from Richard Levitte's (richard@levitte.org) LP library. All | ||
| 3 | * symbol names have been changed, with permission from the author. | ||
| 4 | */ | ||
| 5 | |||
| 6 | /* $LP: LPlib/source/LPdir.h,v 1.1 2004/06/14 08:56:04 _cvs_levitte Exp $ */ | ||
| 7 | /* | ||
| 8 | * Copyright (c) 2004, Richard Levitte <richard@levitte.org> | ||
| 9 | * All rights reserved. | ||
| 10 | * | ||
| 11 | * Redistribution and use in source and binary forms, with or without | ||
| 12 | * modification, are permitted provided that the following conditions | ||
| 13 | * are met: | ||
| 14 | * 1. Redistributions of source code must retain the above copyright | ||
| 15 | * notice, this list of conditions and the following disclaimer. | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in the | ||
| 18 | * documentation and/or other materials provided with the distribution. | ||
| 19 | * | ||
| 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | * SUCH DAMAGE. | ||
| 31 | */ | ||
| 32 | |||
| 33 | |||
| 34 | #ifndef O_DIR_H | ||
| 35 | #define O_DIR_H | ||
| 36 | |||
| 37 | #ifdef __cplusplus | ||
| 38 | extern "C" { | ||
| 39 | #endif | ||
| 40 | |||
| 41 | typedef struct OPENSSL_dir_context_st OPENSSL_DIR_CTX; | ||
| 42 | |||
| 43 | /* returns NULL on error or end-of-directory. | ||
| 44 | If it is end-of-directory, errno will be zero */ | ||
| 45 | const char *OPENSSL_DIR_read(OPENSSL_DIR_CTX **ctx, const char *directory); | ||
| 46 | /* returns 1 on success, 0 on error */ | ||
| 47 | int OPENSSL_DIR_end(OPENSSL_DIR_CTX **ctx); | ||
| 48 | |||
| 49 | #ifdef __cplusplus | ||
| 50 | } | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #endif /* LPDIR_H */ | ||
diff --git a/src/lib/libcrypto/o_dir_test.c b/src/lib/libcrypto/o_dir_test.c new file mode 100644 index 0000000000..3d75ecb005 --- /dev/null +++ b/src/lib/libcrypto/o_dir_test.c | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | /* crypto/o_dir.h -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* Copied from Richard Levitte's (richard@levitte.org) LP library. All | ||
| 3 | * symbol names have been changed, with permission from the author. | ||
| 4 | */ | ||
| 5 | |||
| 6 | /* $LP: LPlib/test/test_dir.c,v 1.1 2004/06/16 22:59:47 _cvs_levitte Exp $ */ | ||
| 7 | /* | ||
| 8 | * Copyright (c) 2004, Richard Levitte <richard@levitte.org> | ||
| 9 | * All rights reserved. | ||
| 10 | * | ||
| 11 | * Redistribution and use in source and binary forms, with or without | ||
| 12 | * modification, are permitted provided that the following conditions | ||
| 13 | * are met: | ||
| 14 | * 1. Redistributions of source code must retain the above copyright | ||
| 15 | * notice, this list of conditions and the following disclaimer. | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in the | ||
| 18 | * documentation and/or other materials provided with the distribution. | ||
| 19 | * | ||
| 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | * SUCH DAMAGE. | ||
| 31 | */ | ||
| 32 | |||
| 33 | #include <stddef.h> | ||
| 34 | #include <stdlib.h> | ||
| 35 | #include <stdio.h> | ||
| 36 | #include <errno.h> | ||
| 37 | #include "e_os2.h" | ||
| 38 | #include "o_dir.h" | ||
| 39 | |||
| 40 | #if defined OPENSSL_SYS_UNIX || defined OPENSSL_SYS_WIN32 || defined OPENSSL_SYS_WINCE | ||
| 41 | #define CURRDIR "." | ||
| 42 | #elif defined OPENSSL_SYS_VMS | ||
| 43 | #define CURRDIR "SYS$DISK:[]" | ||
| 44 | #else | ||
| 45 | #error "No supported platform defined!" | ||
| 46 | #endif | ||
| 47 | |||
| 48 | int main() | ||
| 49 | { | ||
| 50 | OPENSSL_DIR_CTX *ctx = NULL; | ||
| 51 | const char *result; | ||
| 52 | |||
| 53 | while((result = OPENSSL_DIR_read(&ctx, CURRDIR)) != NULL) | ||
| 54 | { | ||
| 55 | printf("%s\n", result); | ||
| 56 | } | ||
| 57 | |||
| 58 | if (errno) | ||
| 59 | { | ||
| 60 | perror("test_dir"); | ||
| 61 | exit(1); | ||
| 62 | } | ||
| 63 | |||
| 64 | if (!OPENSSL_DIR_end(&ctx)) | ||
| 65 | { | ||
| 66 | perror("test_dir"); | ||
| 67 | exit(2); | ||
| 68 | } | ||
| 69 | exit(0); | ||
| 70 | } | ||
diff --git a/src/lib/libcrypto/perlasm/alpha.pl b/src/lib/libcrypto/perlasm/alpha.pl deleted file mode 100644 index 3dac571743..0000000000 --- a/src/lib/libcrypto/perlasm/alpha.pl +++ /dev/null | |||
| @@ -1,434 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | package alpha; | ||
| 4 | use Carp qw(croak cluck); | ||
| 5 | |||
| 6 | $label="100"; | ||
| 7 | |||
| 8 | $n_debug=0; | ||
| 9 | $smear_regs=1; | ||
| 10 | $reg_alloc=1; | ||
| 11 | |||
| 12 | $align="3"; | ||
| 13 | $com_start="#"; | ||
| 14 | |||
| 15 | sub main'asm_init_output { @out=(); } | ||
| 16 | sub main'asm_get_output { return(@out); } | ||
| 17 | sub main'get_labels { return(@labels); } | ||
| 18 | sub main'external_label { push(@labels,@_); } | ||
| 19 | |||
| 20 | # General registers | ||
| 21 | |||
| 22 | %regs=( 'r0', '$0', | ||
| 23 | 'r1', '$1', | ||
| 24 | 'r2', '$2', | ||
| 25 | 'r3', '$3', | ||
| 26 | 'r4', '$4', | ||
| 27 | 'r5', '$5', | ||
| 28 | 'r6', '$6', | ||
| 29 | 'r7', '$7', | ||
| 30 | 'r8', '$8', | ||
| 31 | 'r9', '$22', | ||
| 32 | 'r10', '$23', | ||
| 33 | 'r11', '$24', | ||
| 34 | 'r12', '$25', | ||
| 35 | 'r13', '$27', | ||
| 36 | 'r14', '$28', | ||
| 37 | 'r15', '$21', # argc == 5 | ||
| 38 | 'r16', '$20', # argc == 4 | ||
| 39 | 'r17', '$19', # argc == 3 | ||
| 40 | 'r18', '$18', # argc == 2 | ||
| 41 | 'r19', '$17', # argc == 1 | ||
| 42 | 'r20', '$16', # argc == 0 | ||
| 43 | 'r21', '$9', # save 0 | ||
| 44 | 'r22', '$10', # save 1 | ||
| 45 | 'r23', '$11', # save 2 | ||
| 46 | 'r24', '$12', # save 3 | ||
| 47 | 'r25', '$13', # save 4 | ||
| 48 | 'r26', '$14', # save 5 | ||
| 49 | |||
| 50 | 'a0', '$16', | ||
| 51 | 'a1', '$17', | ||
| 52 | 'a2', '$18', | ||
| 53 | 'a3', '$19', | ||
| 54 | 'a4', '$20', | ||
| 55 | 'a5', '$21', | ||
| 56 | |||
| 57 | 's0', '$9', | ||
| 58 | 's1', '$10', | ||
| 59 | 's2', '$11', | ||
| 60 | 's3', '$12', | ||
| 61 | 's4', '$13', | ||
| 62 | 's5', '$14', | ||
| 63 | 'zero', '$31', | ||
| 64 | 'sp', '$30', | ||
| 65 | ); | ||
| 66 | |||
| 67 | $main'reg_s0="r21"; | ||
| 68 | $main'reg_s1="r22"; | ||
| 69 | $main'reg_s2="r23"; | ||
| 70 | $main'reg_s3="r24"; | ||
| 71 | $main'reg_s4="r25"; | ||
| 72 | $main'reg_s5="r26"; | ||
| 73 | |||
| 74 | @reg=( '$0', '$1' ,'$2' ,'$3' ,'$4' ,'$5' ,'$6' ,'$7' ,'$8', | ||
| 75 | '$22','$23','$24','$25','$20','$21','$27','$28'); | ||
| 76 | |||
| 77 | |||
| 78 | sub main'sub { &out3("subq",@_); } | ||
| 79 | sub main'add { &out3("addq",@_); } | ||
| 80 | sub main'mov { &out3("bis",$_[0],$_[0],$_[1]); } | ||
| 81 | sub main'or { &out3("bis",@_); } | ||
| 82 | sub main'bis { &out3("bis",@_); } | ||
| 83 | sub main'br { &out1("br",@_); } | ||
| 84 | sub main'ld { &out2("ldq",@_); } | ||
| 85 | sub main'st { &out2("stq",@_); } | ||
| 86 | sub main'cmpult { &out3("cmpult",@_); } | ||
| 87 | sub main'cmplt { &out3("cmplt",@_); } | ||
| 88 | sub main'bgt { &out2("bgt",@_); } | ||
| 89 | sub main'ble { &out2("ble",@_); } | ||
| 90 | sub main'blt { &out2("blt",@_); } | ||
| 91 | sub main'mul { &out3("mulq",@_); } | ||
| 92 | sub main'muh { &out3("umulh",@_); } | ||
| 93 | |||
| 94 | $main'QWS=8; | ||
| 95 | |||
| 96 | sub main'asm_add | ||
| 97 | { | ||
| 98 | push(@out,@_); | ||
| 99 | } | ||
| 100 | |||
| 101 | sub main'asm_finish | ||
| 102 | { | ||
| 103 | &main'file_end(); | ||
| 104 | print &main'asm_get_output(); | ||
| 105 | } | ||
| 106 | |||
| 107 | sub main'asm_init | ||
| 108 | { | ||
| 109 | ($type,$fn)=@_; | ||
| 110 | $filename=$fn; | ||
| 111 | |||
| 112 | &main'asm_init_output(); | ||
| 113 | &main'comment("Don't even think of reading this code"); | ||
| 114 | &main'comment("It was automatically generated by $filename"); | ||
| 115 | &main'comment("Which is a perl program used to generate the alpha assember."); | ||
| 116 | &main'comment("eric <eay\@cryptsoft.com>"); | ||
| 117 | &main'comment(""); | ||
| 118 | |||
| 119 | $filename =~ s/\.pl$//; | ||
| 120 | &main'file($filename); | ||
| 121 | } | ||
| 122 | |||
| 123 | sub conv | ||
| 124 | { | ||
| 125 | local($r)=@_; | ||
| 126 | local($v); | ||
| 127 | |||
| 128 | return($regs{$r}) if defined($regs{$r}); | ||
| 129 | return($r); | ||
| 130 | } | ||
| 131 | |||
| 132 | sub main'QWPw | ||
| 133 | { | ||
| 134 | local($off,$reg)=@_; | ||
| 135 | |||
| 136 | return(&main'QWP($off*8,$reg)); | ||
| 137 | } | ||
| 138 | |||
| 139 | sub main'QWP | ||
| 140 | { | ||
| 141 | local($off,$reg)=@_; | ||
| 142 | |||
| 143 | $ret="$off(".&conv($reg).")"; | ||
| 144 | return($ret); | ||
| 145 | } | ||
| 146 | |||
| 147 | sub out3 | ||
| 148 | { | ||
| 149 | local($name,$p1,$p2,$p3)=@_; | ||
| 150 | |||
| 151 | $p1=&conv($p1); | ||
| 152 | $p2=&conv($p2); | ||
| 153 | $p3=&conv($p3); | ||
| 154 | push(@out,"\t$name\t"); | ||
| 155 | $l=length($p1)+1; | ||
| 156 | push(@out,$p1.","); | ||
| 157 | $ll=3-($l+9)/8; | ||
| 158 | $tmp1=sprintf("\t" x $ll); | ||
| 159 | push(@out,$tmp1); | ||
| 160 | |||
| 161 | $l=length($p2)+1; | ||
| 162 | push(@out,$p2.","); | ||
| 163 | $ll=3-($l+9)/8; | ||
| 164 | $tmp1=sprintf("\t" x $ll); | ||
| 165 | push(@out,$tmp1); | ||
| 166 | |||
| 167 | push(@out,&conv($p3)."\n"); | ||
| 168 | } | ||
| 169 | |||
| 170 | sub out2 | ||
| 171 | { | ||
| 172 | local($name,$p1,$p2,$p3)=@_; | ||
| 173 | |||
| 174 | $p1=&conv($p1); | ||
| 175 | $p2=&conv($p2); | ||
| 176 | push(@out,"\t$name\t"); | ||
| 177 | $l=length($p1)+1; | ||
| 178 | push(@out,$p1.","); | ||
| 179 | $ll=3-($l+9)/8; | ||
| 180 | $tmp1=sprintf("\t" x $ll); | ||
| 181 | push(@out,$tmp1); | ||
| 182 | |||
| 183 | push(@out,&conv($p2)."\n"); | ||
| 184 | } | ||
| 185 | |||
| 186 | sub out1 | ||
| 187 | { | ||
| 188 | local($name,$p1)=@_; | ||
| 189 | |||
| 190 | $p1=&conv($p1); | ||
| 191 | push(@out,"\t$name\t".$p1."\n"); | ||
| 192 | } | ||
| 193 | |||
| 194 | sub out0 | ||
| 195 | { | ||
| 196 | push(@out,"\t$_[0]\n"); | ||
| 197 | } | ||
| 198 | |||
| 199 | sub main'file | ||
| 200 | { | ||
| 201 | local($file)=@_; | ||
| 202 | |||
| 203 | local($tmp)=<<"EOF"; | ||
| 204 | # DEC Alpha assember | ||
| 205 | # Generated from perl scripts contains in SSLeay | ||
| 206 | .file 1 "$file.s" | ||
| 207 | .set noat | ||
| 208 | EOF | ||
| 209 | push(@out,$tmp); | ||
| 210 | } | ||
| 211 | |||
| 212 | sub main'function_begin | ||
| 213 | { | ||
| 214 | local($func)=@_; | ||
| 215 | |||
| 216 | print STDERR "$func\n"; | ||
| 217 | local($tmp)=<<"EOF"; | ||
| 218 | .text | ||
| 219 | .align $align | ||
| 220 | .globl $func | ||
| 221 | .ent $func | ||
| 222 | ${func}: | ||
| 223 | ${func}..ng: | ||
| 224 | .frame \$30,0,\$26,0 | ||
| 225 | .prologue 0 | ||
| 226 | EOF | ||
| 227 | push(@out,$tmp); | ||
| 228 | $stack=0; | ||
| 229 | } | ||
| 230 | |||
| 231 | sub main'function_end | ||
| 232 | { | ||
| 233 | local($func)=@_; | ||
| 234 | |||
| 235 | local($tmp)=<<"EOF"; | ||
| 236 | ret \$31,(\$26),1 | ||
| 237 | .end $func | ||
| 238 | EOF | ||
| 239 | push(@out,$tmp); | ||
| 240 | $stack=0; | ||
| 241 | %label=(); | ||
| 242 | } | ||
| 243 | |||
| 244 | sub main'function_end_A | ||
| 245 | { | ||
| 246 | local($func)=@_; | ||
| 247 | |||
| 248 | local($tmp)=<<"EOF"; | ||
| 249 | ret \$31,(\$26),1 | ||
| 250 | EOF | ||
| 251 | push(@out,$tmp); | ||
| 252 | } | ||
| 253 | |||
| 254 | sub main'function_end_B | ||
| 255 | { | ||
| 256 | local($func)=@_; | ||
| 257 | |||
| 258 | $func=$under.$func; | ||
| 259 | |||
| 260 | push(@out,"\t.end $func\n"); | ||
| 261 | $stack=0; | ||
| 262 | %label=(); | ||
| 263 | } | ||
| 264 | |||
| 265 | sub main'wparam | ||
| 266 | { | ||
| 267 | local($num)=@_; | ||
| 268 | |||
| 269 | if ($num < 6) | ||
| 270 | { | ||
| 271 | $num=20-$num; | ||
| 272 | return("r$num"); | ||
| 273 | } | ||
| 274 | else | ||
| 275 | { return(&main'QWP($stack+$num*8,"sp")); } | ||
| 276 | } | ||
| 277 | |||
| 278 | sub main'stack_push | ||
| 279 | { | ||
| 280 | local($num)=@_; | ||
| 281 | $stack+=$num*8; | ||
| 282 | &main'sub("sp",$num*8,"sp"); | ||
| 283 | } | ||
| 284 | |||
| 285 | sub main'stack_pop | ||
| 286 | { | ||
| 287 | local($num)=@_; | ||
| 288 | $stack-=$num*8; | ||
| 289 | &main'add("sp",$num*8,"sp"); | ||
| 290 | } | ||
| 291 | |||
| 292 | sub main'swtmp | ||
| 293 | { | ||
| 294 | return(&main'QWP(($_[0])*8,"sp")); | ||
| 295 | } | ||
| 296 | |||
| 297 | # Should use swtmp, which is above sp. Linix can trash the stack above esp | ||
| 298 | #sub main'wtmp | ||
| 299 | # { | ||
| 300 | # local($num)=@_; | ||
| 301 | # | ||
| 302 | # return(&main'QWP(-($num+1)*4,"esp","",0)); | ||
| 303 | # } | ||
| 304 | |||
| 305 | sub main'comment | ||
| 306 | { | ||
| 307 | foreach (@_) | ||
| 308 | { | ||
| 309 | if (/^\s*$/) | ||
| 310 | { push(@out,"\n"); } | ||
| 311 | else | ||
| 312 | { push(@out,"\t$com_start $_ $com_end\n"); } | ||
| 313 | } | ||
| 314 | } | ||
| 315 | |||
| 316 | sub main'label | ||
| 317 | { | ||
| 318 | if (!defined($label{$_[0]})) | ||
| 319 | { | ||
| 320 | $label{$_[0]}=$label; | ||
| 321 | $label++; | ||
| 322 | } | ||
| 323 | return('$'.$label{$_[0]}); | ||
| 324 | } | ||
| 325 | |||
| 326 | sub main'set_label | ||
| 327 | { | ||
| 328 | if (!defined($label{$_[0]})) | ||
| 329 | { | ||
| 330 | $label{$_[0]}=$label; | ||
| 331 | $label++; | ||
| 332 | } | ||
| 333 | # push(@out,".align $align\n") if ($_[1] != 0); | ||
| 334 | push(@out,'$'."$label{$_[0]}:\n"); | ||
| 335 | } | ||
| 336 | |||
| 337 | sub main'file_end | ||
| 338 | { | ||
| 339 | } | ||
| 340 | |||
| 341 | sub main'data_word | ||
| 342 | { | ||
| 343 | push(@out,"\t.long $_[0]\n"); | ||
| 344 | } | ||
| 345 | |||
| 346 | @pool_free=(); | ||
| 347 | @pool_taken=(); | ||
| 348 | $curr_num=0; | ||
| 349 | $max=0; | ||
| 350 | |||
| 351 | sub main'init_pool | ||
| 352 | { | ||
| 353 | local($args)=@_; | ||
| 354 | local($i); | ||
| 355 | |||
| 356 | @pool_free=(); | ||
| 357 | for ($i=(14+(6-$args)); $i >= 0; $i--) | ||
| 358 | { | ||
| 359 | push(@pool_free,"r$i"); | ||
| 360 | } | ||
| 361 | print STDERR "START :register pool:@pool_free\n"; | ||
| 362 | $curr_num=$max=0; | ||
| 363 | } | ||
| 364 | |||
| 365 | sub main'fin_pool | ||
| 366 | { | ||
| 367 | printf STDERR "END %2d:register pool:@pool_free\n",$max; | ||
| 368 | } | ||
| 369 | |||
| 370 | sub main'GR | ||
| 371 | { | ||
| 372 | local($r)=@_; | ||
| 373 | local($i,@n,$_); | ||
| 374 | |||
| 375 | foreach (@pool_free) | ||
| 376 | { | ||
| 377 | if ($r ne $_) | ||
| 378 | { push(@n,$_); } | ||
| 379 | else | ||
| 380 | { | ||
| 381 | $curr_num++; | ||
| 382 | $max=$curr_num if ($curr_num > $max); | ||
| 383 | } | ||
| 384 | } | ||
| 385 | @pool_free=@n; | ||
| 386 | print STDERR "GR:@pool_free\n" if $reg_alloc; | ||
| 387 | return(@_); | ||
| 388 | } | ||
| 389 | |||
| 390 | sub main'NR | ||
| 391 | { | ||
| 392 | local($num)=@_; | ||
| 393 | local(@ret); | ||
| 394 | |||
| 395 | $num=1 if $num == 0; | ||
| 396 | ($#pool_free >= ($num-1)) || croak "out of registers: want $num, have @pool_free"; | ||
| 397 | while ($num > 0) | ||
| 398 | { | ||
| 399 | push(@ret,pop @pool_free); | ||
| 400 | $curr_num++; | ||
| 401 | $max=$curr_num if ($curr_num > $max); | ||
| 402 | $num-- | ||
| 403 | } | ||
| 404 | print STDERR "nr @ret\n" if $n_debug; | ||
| 405 | print STDERR "NR:@pool_free\n" if $reg_alloc; | ||
| 406 | return(@ret); | ||
| 407 | |||
| 408 | } | ||
| 409 | |||
| 410 | sub main'FR | ||
| 411 | { | ||
| 412 | local(@r)=@_; | ||
| 413 | local(@a,$v,$w); | ||
| 414 | |||
| 415 | print STDERR "fr @r\n" if $n_debug; | ||
| 416 | # cluck "fr @r"; | ||
| 417 | for $w (@pool_free) | ||
| 418 | { | ||
| 419 | foreach $v (@r) | ||
| 420 | { | ||
| 421 | croak "double register free of $v (@pool_free)" if $w eq $v; | ||
| 422 | } | ||
| 423 | } | ||
| 424 | foreach $v (@r) | ||
| 425 | { | ||
| 426 | croak "bad argument to FR" if ($v !~ /^r\d+$/); | ||
| 427 | if ($smear_regs) | ||
| 428 | { unshift(@pool_free,$v); } | ||
| 429 | else { push(@pool_free,$v); } | ||
| 430 | $curr_num--; | ||
| 431 | } | ||
| 432 | print STDERR "FR:@pool_free\n" if $reg_alloc; | ||
| 433 | } | ||
| 434 | 1; | ||
diff --git a/src/lib/libcrypto/perlasm/x86masm.pl b/src/lib/libcrypto/perlasm/x86masm.pl new file mode 100644 index 0000000000..3d50e4a786 --- /dev/null +++ b/src/lib/libcrypto/perlasm/x86masm.pl | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | package x86masm; | ||
| 4 | |||
| 5 | *out=\@::out; | ||
| 6 | |||
| 7 | $::lbdecor="\$L"; # local label decoration | ||
| 8 | $nmdecor="_"; # external name decoration | ||
| 9 | |||
| 10 | $initseg=""; | ||
| 11 | $segment=""; | ||
| 12 | |||
| 13 | sub ::generic | ||
| 14 | { my ($opcode,@arg)=@_; | ||
| 15 | |||
| 16 | # fix hexadecimal constants | ||
| 17 | for (@arg) { s/0x([0-9a-f]+)/0$1h/oi; } | ||
| 18 | |||
| 19 | if ($opcode !~ /movq/) | ||
| 20 | { # fix xmm references | ||
| 21 | $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[1]=~/\bxmm[0-7]\b/i); | ||
| 22 | $arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i); | ||
| 23 | } | ||
| 24 | |||
| 25 | &::emit($opcode,@arg); | ||
| 26 | 1; | ||
| 27 | } | ||
| 28 | # | ||
| 29 | # opcodes not covered by ::generic above, mostly inconsistent namings... | ||
| 30 | # | ||
| 31 | sub ::call { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); } | ||
| 32 | sub ::call_ptr { &::emit("call",@_); } | ||
| 33 | sub ::jmp_ptr { &::emit("jmp",@_); } | ||
| 34 | |||
| 35 | sub get_mem | ||
| 36 | { my($size,$addr,$reg1,$reg2,$idx)=@_; | ||
| 37 | my($post,$ret); | ||
| 38 | |||
| 39 | $ret .= "$size PTR " if ($size ne ""); | ||
| 40 | |||
| 41 | $addr =~ s/^\s+//; | ||
| 42 | # prepend global references with optional underscore | ||
| 43 | $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige; | ||
| 44 | # put address arithmetic expression in parenthesis | ||
| 45 | $addr="($addr)" if ($addr =~ /^.+[\-\+].+$/); | ||
| 46 | |||
| 47 | if (($addr ne "") && ($addr ne 0)) | ||
| 48 | { if ($addr !~ /^-/) { $ret .= "$addr"; } | ||
| 49 | else { $post=$addr; } | ||
| 50 | } | ||
| 51 | $ret .= "["; | ||
| 52 | |||
| 53 | if ($reg2 ne "") | ||
| 54 | { $idx!=0 or $idx=1; | ||
| 55 | $ret .= "$reg2*$idx"; | ||
| 56 | $ret .= "+$reg1" if ($reg1 ne ""); | ||
| 57 | } | ||
| 58 | else | ||
| 59 | { $ret .= "$reg1"; } | ||
| 60 | |||
| 61 | $ret .= "$post]"; | ||
| 62 | $ret =~ s/\+\]/]/; # in case $addr was the only argument | ||
| 63 | $ret =~ s/\[\s*\]//; | ||
| 64 | |||
| 65 | $ret; | ||
| 66 | } | ||
| 67 | sub ::BP { &get_mem("BYTE",@_); } | ||
| 68 | sub ::DWP { &get_mem("DWORD",@_); } | ||
| 69 | sub ::QWP { &get_mem("QWORD",@_); } | ||
| 70 | sub ::BC { "@_"; } | ||
| 71 | sub ::DWC { "@_"; } | ||
| 72 | |||
| 73 | sub ::file | ||
| 74 | { my $tmp=<<___; | ||
| 75 | TITLE $_[0].asm | ||
| 76 | IF \@Version LT 800 | ||
| 77 | ECHO MASM version 8.00 or later is strongly recommended. | ||
| 78 | ENDIF | ||
| 79 | .486 | ||
| 80 | .MODEL FLAT | ||
| 81 | OPTION DOTNAME | ||
| 82 | IF \@Version LT 800 | ||
| 83 | .text\$ SEGMENT PAGE 'CODE' | ||
| 84 | ELSE | ||
| 85 | .text\$ SEGMENT ALIGN(64) 'CODE' | ||
| 86 | ENDIF | ||
| 87 | ___ | ||
| 88 | push(@out,$tmp); | ||
| 89 | $segment = ".text\$"; | ||
| 90 | } | ||
| 91 | |||
| 92 | sub ::function_begin_B | ||
| 93 | { my $func=shift; | ||
| 94 | my $global=($func !~ /^_/); | ||
| 95 | my $begin="${::lbdecor}_${func}_begin"; | ||
| 96 | |||
| 97 | &::LABEL($func,$global?"$begin":"$nmdecor$func"); | ||
| 98 | $func="ALIGN\t16\n".$nmdecor.$func."\tPROC"; | ||
| 99 | |||
| 100 | if ($global) { $func.=" PUBLIC\n${begin}::\n"; } | ||
| 101 | else { $func.=" PRIVATE\n"; } | ||
| 102 | push(@out,$func); | ||
| 103 | $::stack=4; | ||
| 104 | } | ||
| 105 | sub ::function_end_B | ||
| 106 | { my $func=shift; | ||
| 107 | |||
| 108 | push(@out,"$nmdecor$func ENDP\n"); | ||
| 109 | $::stack=0; | ||
| 110 | &::wipe_labels(); | ||
| 111 | } | ||
| 112 | |||
| 113 | sub ::file_end | ||
| 114 | { my $xmmheader=<<___; | ||
| 115 | .686 | ||
| 116 | .XMM | ||
| 117 | IF \@Version LT 800 | ||
| 118 | XMMWORD STRUCT 16 | ||
| 119 | DQ 2 dup (?) | ||
| 120 | XMMWORD ENDS | ||
| 121 | ENDIF | ||
| 122 | ___ | ||
| 123 | if (grep {/\b[x]?mm[0-7]\b/i} @out) { | ||
| 124 | grep {s/\.[3-7]86/$xmmheader/} @out; | ||
| 125 | } | ||
| 126 | |||
| 127 | push(@out,"$segment ENDS\n"); | ||
| 128 | |||
| 129 | if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) | ||
| 130 | { my $comm=<<___; | ||
| 131 | .bss SEGMENT 'BSS' | ||
| 132 | COMM ${nmdecor}OPENSSL_ia32cap_P:DWORD | ||
| 133 | .bss ENDS | ||
| 134 | ___ | ||
| 135 | # comment out OPENSSL_ia32cap_P declarations | ||
| 136 | grep {s/(^EXTERN\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out; | ||
| 137 | push (@out,$comm); | ||
| 138 | } | ||
| 139 | push (@out,$initseg) if ($initseg); | ||
| 140 | push (@out,"END\n"); | ||
| 141 | } | ||
| 142 | |||
| 143 | sub ::comment { foreach (@_) { push(@out,"\t; $_\n"); } } | ||
| 144 | |||
| 145 | *::set_label_B = sub | ||
| 146 | { my $l=shift; push(@out,$l.($l=~/^\Q${::lbdecor}\E[0-9]{3}/?":\n":"::\n")); }; | ||
| 147 | |||
| 148 | sub ::external_label | ||
| 149 | { foreach(@_) | ||
| 150 | { push(@out, "EXTERN\t".&::LABEL($_,$nmdecor.$_).":NEAR\n"); } | ||
| 151 | } | ||
| 152 | |||
| 153 | sub ::public_label | ||
| 154 | { push(@out,"PUBLIC\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); } | ||
| 155 | |||
| 156 | sub ::data_byte | ||
| 157 | { push(@out,("DB\t").join(',',@_)."\n"); } | ||
| 158 | |||
| 159 | sub ::data_word | ||
| 160 | { push(@out,("DD\t").join(',',@_)."\n"); } | ||
| 161 | |||
| 162 | sub ::align | ||
| 163 | { push(@out,"ALIGN\t$_[0]\n"); } | ||
| 164 | |||
| 165 | sub ::picmeup | ||
| 166 | { my($dst,$sym)=@_; | ||
| 167 | &::lea($dst,&::DWP($sym)); | ||
| 168 | } | ||
| 169 | |||
| 170 | sub ::initseg | ||
| 171 | { my $f=$nmdecor.shift; | ||
| 172 | |||
| 173 | $initseg.=<<___; | ||
| 174 | .CRT\$XCU SEGMENT DWORD PUBLIC 'DATA' | ||
| 175 | EXTERN $f:NEAR | ||
| 176 | DD $f | ||
| 177 | .CRT\$XCU ENDS | ||
| 178 | ___ | ||
| 179 | } | ||
| 180 | |||
| 181 | sub ::dataseg | ||
| 182 | { push(@out,"$segment\tENDS\n_DATA\tSEGMENT\n"); $segment="_DATA"; } | ||
| 183 | |||
| 184 | 1; | ||
diff --git a/src/lib/libcrypto/perlasm/x86ms.pl b/src/lib/libcrypto/perlasm/x86ms.pl deleted file mode 100644 index a0be2934c2..0000000000 --- a/src/lib/libcrypto/perlasm/x86ms.pl +++ /dev/null | |||
| @@ -1,472 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | package x86ms; | ||
| 4 | |||
| 5 | $label="L000"; | ||
| 6 | |||
| 7 | %lb=( 'eax', 'al', | ||
| 8 | 'ebx', 'bl', | ||
| 9 | 'ecx', 'cl', | ||
| 10 | 'edx', 'dl', | ||
| 11 | 'ax', 'al', | ||
| 12 | 'bx', 'bl', | ||
| 13 | 'cx', 'cl', | ||
| 14 | 'dx', 'dl', | ||
| 15 | ); | ||
| 16 | |||
| 17 | %hb=( 'eax', 'ah', | ||
| 18 | 'ebx', 'bh', | ||
| 19 | 'ecx', 'ch', | ||
| 20 | 'edx', 'dh', | ||
| 21 | 'ax', 'ah', | ||
| 22 | 'bx', 'bh', | ||
| 23 | 'cx', 'ch', | ||
| 24 | 'dx', 'dh', | ||
| 25 | ); | ||
| 26 | |||
| 27 | sub main'asm_init_output { @out=(); } | ||
| 28 | sub main'asm_get_output { return(@out); } | ||
| 29 | sub main'get_labels { return(@labels); } | ||
| 30 | sub main'external_label | ||
| 31 | { | ||
| 32 | push(@labels,@_); | ||
| 33 | foreach (@_) { | ||
| 34 | push(@out, "EXTRN\t_$_:DWORD\n"); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | sub main'LB | ||
| 39 | { | ||
| 40 | (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n"; | ||
| 41 | return($lb{$_[0]}); | ||
| 42 | } | ||
| 43 | |||
| 44 | sub main'HB | ||
| 45 | { | ||
| 46 | (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n"; | ||
| 47 | return($hb{$_[0]}); | ||
| 48 | } | ||
| 49 | |||
| 50 | sub main'BP | ||
| 51 | { | ||
| 52 | &get_mem("BYTE",@_); | ||
| 53 | } | ||
| 54 | |||
| 55 | sub main'DWP | ||
| 56 | { | ||
| 57 | &get_mem("DWORD",@_); | ||
| 58 | } | ||
| 59 | |||
| 60 | sub main'QWP | ||
| 61 | { | ||
| 62 | &get_mem("QWORD",@_); | ||
| 63 | } | ||
| 64 | |||
| 65 | sub main'BC | ||
| 66 | { | ||
| 67 | return @_; | ||
| 68 | } | ||
| 69 | |||
| 70 | sub main'DWC | ||
| 71 | { | ||
| 72 | return @_; | ||
| 73 | } | ||
| 74 | |||
| 75 | sub main'stack_push | ||
| 76 | { | ||
| 77 | local($num)=@_; | ||
| 78 | $stack+=$num*4; | ||
| 79 | &main'sub("esp",$num*4); | ||
| 80 | } | ||
| 81 | |||
| 82 | sub main'stack_pop | ||
| 83 | { | ||
| 84 | local($num)=@_; | ||
| 85 | $stack-=$num*4; | ||
| 86 | &main'add("esp",$num*4); | ||
| 87 | } | ||
| 88 | |||
| 89 | sub get_mem | ||
| 90 | { | ||
| 91 | local($size,$addr,$reg1,$reg2,$idx)=@_; | ||
| 92 | local($t,$post); | ||
| 93 | local($ret)="$size PTR "; | ||
| 94 | |||
| 95 | $addr =~ s/^\s+//; | ||
| 96 | if ($addr =~ /^(.+)\+(.+)$/) | ||
| 97 | { | ||
| 98 | $reg2=&conv($1); | ||
| 99 | $addr="_$2"; | ||
| 100 | } | ||
| 101 | elsif ($addr =~ /^[_a-z][_a-z0-9]*$/i) | ||
| 102 | { | ||
| 103 | $addr="_$addr"; | ||
| 104 | } | ||
| 105 | |||
| 106 | if ($addr =~ /^.+\-.+$/) { $addr="($addr)"; } | ||
| 107 | |||
| 108 | $reg1="$regs{$reg1}" if defined($regs{$reg1}); | ||
| 109 | $reg2="$regs{$reg2}" if defined($regs{$reg2}); | ||
| 110 | if (($addr ne "") && ($addr ne 0)) | ||
| 111 | { | ||
| 112 | if ($addr !~ /^-/) | ||
| 113 | { $ret.=$addr; } | ||
| 114 | else { $post=$addr; } | ||
| 115 | } | ||
| 116 | if ($reg2 ne "") | ||
| 117 | { | ||
| 118 | $t=""; | ||
| 119 | $t="*$idx" if ($idx != 0); | ||
| 120 | $reg1="+".$reg1 if ("$reg1$post" ne ""); | ||
| 121 | $ret.="[$reg2$t$reg1$post]"; | ||
| 122 | } | ||
| 123 | else | ||
| 124 | { | ||
| 125 | $ret.="[$reg1$post]" | ||
| 126 | } | ||
| 127 | $ret =~ s/\[\]//; # in case $addr was the only argument | ||
| 128 | return($ret); | ||
| 129 | } | ||
| 130 | |||
| 131 | sub main'mov { &out2("mov",@_); } | ||
| 132 | sub main'movb { &out2("mov",@_); } | ||
| 133 | sub main'and { &out2("and",@_); } | ||
| 134 | sub main'or { &out2("or",@_); } | ||
| 135 | sub main'shl { &out2("shl",@_); } | ||
| 136 | sub main'shr { &out2("shr",@_); } | ||
| 137 | sub main'xor { &out2("xor",@_); } | ||
| 138 | sub main'xorb { &out2("xor",@_); } | ||
| 139 | sub main'add { &out2("add",@_); } | ||
| 140 | sub main'adc { &out2("adc",@_); } | ||
| 141 | sub main'sub { &out2("sub",@_); } | ||
| 142 | sub main'sbb { &out2("sbb",@_); } | ||
| 143 | sub main'rotl { &out2("rol",@_); } | ||
| 144 | sub main'rotr { &out2("ror",@_); } | ||
| 145 | sub main'exch { &out2("xchg",@_); } | ||
| 146 | sub main'cmp { &out2("cmp",@_); } | ||
| 147 | sub main'lea { &out2("lea",@_); } | ||
| 148 | sub main'mul { &out1("mul",@_); } | ||
| 149 | sub main'imul { &out2("imul",@_); } | ||
| 150 | sub main'div { &out1("div",@_); } | ||
| 151 | sub main'dec { &out1("dec",@_); } | ||
| 152 | sub main'inc { &out1("inc",@_); } | ||
| 153 | sub main'jmp { &out1("jmp",@_); } | ||
| 154 | sub main'jmp_ptr { &out1p("jmp",@_); } | ||
| 155 | sub main'je { &out1("je",@_); } | ||
| 156 | sub main'jle { &out1("jle",@_); } | ||
| 157 | sub main'jz { &out1("jz",@_); } | ||
| 158 | sub main'jge { &out1("jge",@_); } | ||
| 159 | sub main'jl { &out1("jl",@_); } | ||
| 160 | sub main'ja { &out1("ja",@_); } | ||
| 161 | sub main'jae { &out1("jae",@_); } | ||
| 162 | sub main'jb { &out1("jb",@_); } | ||
| 163 | sub main'jbe { &out1("jbe",@_); } | ||
| 164 | sub main'jc { &out1("jc",@_); } | ||
| 165 | sub main'jnc { &out1("jnc",@_); } | ||
| 166 | sub main'jnz { &out1("jnz",@_); } | ||
| 167 | sub main'jne { &out1("jne",@_); } | ||
| 168 | sub main'jno { &out1("jno",@_); } | ||
| 169 | sub main'push { &out1("push",@_); $stack+=4; } | ||
| 170 | sub main'pop { &out1("pop",@_); $stack-=4; } | ||
| 171 | sub main'pushf { &out0("pushfd"); $stack+=4; } | ||
| 172 | sub main'popf { &out0("popfd"); $stack-=4; } | ||
| 173 | sub main'bswap { &out1("bswap",@_); &using486(); } | ||
| 174 | sub main'not { &out1("not",@_); } | ||
| 175 | sub main'call { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); } | ||
| 176 | sub main'call_ptr { &out1p("call",@_); } | ||
| 177 | sub main'ret { &out0("ret"); } | ||
| 178 | sub main'nop { &out0("nop"); } | ||
| 179 | sub main'test { &out2("test",@_); } | ||
| 180 | sub main'bt { &out2("bt",@_); } | ||
| 181 | sub main'leave { &out0("leave"); } | ||
| 182 | sub main'cpuid { &out0("DW\t0A20Fh"); } | ||
| 183 | sub main'rdtsc { &out0("DW\t0310Fh"); } | ||
| 184 | sub main'halt { &out0("hlt"); } | ||
| 185 | sub main'movz { &out2("movzx",@_); } | ||
| 186 | sub main'neg { &out1("neg",@_); } | ||
| 187 | sub main'cld { &out0("cld"); } | ||
| 188 | |||
| 189 | # SSE2 | ||
| 190 | sub main'emms { &out0("emms"); } | ||
| 191 | sub main'movd { &out2("movd",@_); } | ||
| 192 | sub main'movq { &out2("movq",@_); } | ||
| 193 | sub main'movdqu { &out2("movdqu",@_); } | ||
| 194 | sub main'movdqa { &out2("movdqa",@_); } | ||
| 195 | sub main'movdq2q{ &out2("movdq2q",@_); } | ||
| 196 | sub main'movq2dq{ &out2("movq2dq",@_); } | ||
| 197 | sub main'paddq { &out2("paddq",@_); } | ||
| 198 | sub main'pmuludq{ &out2("pmuludq",@_); } | ||
| 199 | sub main'psrlq { &out2("psrlq",@_); } | ||
| 200 | sub main'psllq { &out2("psllq",@_); } | ||
| 201 | sub main'pxor { &out2("pxor",@_); } | ||
| 202 | sub main'por { &out2("por",@_); } | ||
| 203 | sub main'pand { &out2("pand",@_); } | ||
| 204 | |||
| 205 | sub out2 | ||
| 206 | { | ||
| 207 | local($name,$p1,$p2)=@_; | ||
| 208 | local($l,$t,$line); | ||
| 209 | |||
| 210 | $line="\t$name\t"; | ||
| 211 | $t=&conv($p1).","; | ||
| 212 | $l=length($t); | ||
| 213 | $line.="$t"; | ||
| 214 | $l=4-($l+9)/8; | ||
| 215 | $line.="\t" x $l; | ||
| 216 | $line.=&conv($p2); | ||
| 217 | if ($line=~/\bxmm[0-7]\b/i) { $line=~s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i; } | ||
| 218 | push(@out,$line."\n"); | ||
| 219 | } | ||
| 220 | |||
| 221 | sub out0 | ||
| 222 | { | ||
| 223 | local($name)=@_; | ||
| 224 | |||
| 225 | push(@out,"\t$name\n"); | ||
| 226 | } | ||
| 227 | |||
| 228 | sub out1 | ||
| 229 | { | ||
| 230 | local($name,$p1)=@_; | ||
| 231 | local($l,$t); | ||
| 232 | |||
| 233 | push(@out,"\t$name\t".&conv($p1)."\n"); | ||
| 234 | } | ||
| 235 | |||
| 236 | sub conv | ||
| 237 | { | ||
| 238 | local($p)=@_; | ||
| 239 | |||
| 240 | $p =~ s/0x([0-9A-Fa-f]+)/0$1h/; | ||
| 241 | return $p; | ||
| 242 | } | ||
| 243 | |||
| 244 | sub using486 | ||
| 245 | { | ||
| 246 | return if $using486; | ||
| 247 | $using486++; | ||
| 248 | grep(s/\.386/\.486/,@out); | ||
| 249 | } | ||
| 250 | |||
| 251 | sub main'file | ||
| 252 | { | ||
| 253 | local($file)=@_; | ||
| 254 | |||
| 255 | local($tmp)=<<"EOF"; | ||
| 256 | TITLE $file.asm | ||
| 257 | .386 | ||
| 258 | .model FLAT | ||
| 259 | _TEXT\$ SEGMENT PAGE 'CODE' | ||
| 260 | |||
| 261 | EOF | ||
| 262 | push(@out,$tmp); | ||
| 263 | } | ||
| 264 | |||
| 265 | sub main'function_begin | ||
| 266 | { | ||
| 267 | local($func,$extra)=@_; | ||
| 268 | |||
| 269 | push(@labels,$func); | ||
| 270 | |||
| 271 | local($tmp)=<<"EOF"; | ||
| 272 | PUBLIC _$func | ||
| 273 | $extra | ||
| 274 | _$func PROC NEAR | ||
| 275 | push ebp | ||
| 276 | push ebx | ||
| 277 | push esi | ||
| 278 | push edi | ||
| 279 | EOF | ||
| 280 | push(@out,$tmp); | ||
| 281 | $stack=20; | ||
| 282 | } | ||
| 283 | |||
| 284 | sub main'function_begin_B | ||
| 285 | { | ||
| 286 | local($func,$extra)=@_; | ||
| 287 | |||
| 288 | local($tmp)=<<"EOF"; | ||
| 289 | PUBLIC _$func | ||
| 290 | $extra | ||
| 291 | _$func PROC NEAR | ||
| 292 | EOF | ||
| 293 | push(@out,$tmp); | ||
| 294 | $stack=4; | ||
| 295 | } | ||
| 296 | |||
| 297 | sub main'function_end | ||
| 298 | { | ||
| 299 | local($func)=@_; | ||
| 300 | |||
| 301 | local($tmp)=<<"EOF"; | ||
| 302 | pop edi | ||
| 303 | pop esi | ||
| 304 | pop ebx | ||
| 305 | pop ebp | ||
| 306 | ret | ||
| 307 | _$func ENDP | ||
| 308 | EOF | ||
| 309 | push(@out,$tmp); | ||
| 310 | $stack=0; | ||
| 311 | %label=(); | ||
| 312 | } | ||
| 313 | |||
| 314 | sub main'function_end_B | ||
| 315 | { | ||
| 316 | local($func)=@_; | ||
| 317 | |||
| 318 | local($tmp)=<<"EOF"; | ||
| 319 | _$func ENDP | ||
| 320 | EOF | ||
| 321 | push(@out,$tmp); | ||
| 322 | $stack=0; | ||
| 323 | %label=(); | ||
| 324 | } | ||
| 325 | |||
| 326 | sub main'function_end_A | ||
| 327 | { | ||
| 328 | local($func)=@_; | ||
| 329 | |||
| 330 | local($tmp)=<<"EOF"; | ||
| 331 | pop edi | ||
| 332 | pop esi | ||
| 333 | pop ebx | ||
| 334 | pop ebp | ||
| 335 | ret | ||
| 336 | EOF | ||
| 337 | push(@out,$tmp); | ||
| 338 | } | ||
| 339 | |||
| 340 | sub main'file_end | ||
| 341 | { | ||
| 342 | # try to detect if SSE2 or MMX extensions were used... | ||
| 343 | my $xmmheader=<<___; | ||
| 344 | .686 | ||
| 345 | .XMM | ||
| 346 | IF \@Version LT 800 | ||
| 347 | XMMWORD STRUCT 16 | ||
| 348 | DQ 2 dup (?) | ||
| 349 | XMMWORD ENDS | ||
| 350 | ENDIF | ||
| 351 | ___ | ||
| 352 | if (grep {/\b[x]?mm[0-7]\b/i} @out) { | ||
| 353 | grep {s/\.[3-7]86/$xmmheader/} @out; | ||
| 354 | } | ||
| 355 | push(@out,"_TEXT\$ ENDS\n"); | ||
| 356 | push(@out,"END\n"); | ||
| 357 | } | ||
| 358 | |||
| 359 | sub main'wparam | ||
| 360 | { | ||
| 361 | local($num)=@_; | ||
| 362 | |||
| 363 | return(&main'DWP($stack+$num*4,"esp","",0)); | ||
| 364 | } | ||
| 365 | |||
| 366 | sub main'swtmp | ||
| 367 | { | ||
| 368 | return(&main'DWP($_[0]*4,"esp","",0)); | ||
| 369 | } | ||
| 370 | |||
| 371 | # Should use swtmp, which is above esp. Linix can trash the stack above esp | ||
| 372 | #sub main'wtmp | ||
| 373 | # { | ||
| 374 | # local($num)=@_; | ||
| 375 | # | ||
| 376 | # return(&main'DWP(-(($num+1)*4),"esp","",0)); | ||
| 377 | # } | ||
| 378 | |||
| 379 | sub main'comment | ||
| 380 | { | ||
| 381 | foreach (@_) | ||
| 382 | { | ||
| 383 | push(@out,"\t; $_\n"); | ||
| 384 | } | ||
| 385 | } | ||
| 386 | |||
| 387 | sub main'public_label | ||
| 388 | { | ||
| 389 | $label{$_[0]}="_$_[0]" if (!defined($label{$_[0]})); | ||
| 390 | push(@out,"PUBLIC\t$label{$_[0]}\n"); | ||
| 391 | } | ||
| 392 | |||
| 393 | sub main'label | ||
| 394 | { | ||
| 395 | if (!defined($label{$_[0]})) | ||
| 396 | { | ||
| 397 | $label{$_[0]}="\$${label}${_[0]}"; | ||
| 398 | $label++; | ||
| 399 | } | ||
| 400 | return($label{$_[0]}); | ||
| 401 | } | ||
| 402 | |||
| 403 | sub main'set_label | ||
| 404 | { | ||
| 405 | if (!defined($label{$_[0]})) | ||
| 406 | { | ||
| 407 | $label{$_[0]}="\$${label}${_[0]}"; | ||
| 408 | $label++; | ||
| 409 | } | ||
| 410 | if ($_[1]!=0 && $_[1]>1) | ||
| 411 | { | ||
| 412 | main'align($_[1]); | ||
| 413 | } | ||
| 414 | if((defined $_[2]) && ($_[2] == 1)) | ||
| 415 | { | ||
| 416 | push(@out,"$label{$_[0]}::\n"); | ||
| 417 | } | ||
| 418 | elsif ($label{$_[0]} !~ /^\$/) | ||
| 419 | { | ||
| 420 | push(@out,"$label{$_[0]}\tLABEL PTR\n"); | ||
| 421 | } | ||
| 422 | else | ||
| 423 | { | ||
| 424 | push(@out,"$label{$_[0]}:\n"); | ||
| 425 | } | ||
| 426 | } | ||
| 427 | |||
| 428 | sub main'data_byte | ||
| 429 | { | ||
| 430 | push(@out,"\tDB\t".join(',',@_)."\n"); | ||
| 431 | } | ||
| 432 | |||
| 433 | sub main'data_word | ||
| 434 | { | ||
| 435 | push(@out,"\tDD\t".join(',',@_)."\n"); | ||
| 436 | } | ||
| 437 | |||
| 438 | sub main'align | ||
| 439 | { | ||
| 440 | push(@out,"\tALIGN\t$_[0]\n"); | ||
| 441 | } | ||
| 442 | |||
| 443 | sub out1p | ||
| 444 | { | ||
| 445 | local($name,$p1)=@_; | ||
| 446 | local($l,$t); | ||
| 447 | |||
| 448 | push(@out,"\t$name\t".&conv($p1)."\n"); | ||
| 449 | } | ||
| 450 | |||
| 451 | sub main'picmeup | ||
| 452 | { | ||
| 453 | local($dst,$sym)=@_; | ||
| 454 | &main'lea($dst,&main'DWP($sym)); | ||
| 455 | } | ||
| 456 | |||
| 457 | sub main'blindpop { &out1("pop",@_); } | ||
| 458 | |||
| 459 | sub main'initseg | ||
| 460 | { | ||
| 461 | local($f)=@_; | ||
| 462 | local($tmp)=<<___; | ||
| 463 | OPTION DOTNAME | ||
| 464 | .CRT\$XCU SEGMENT DWORD PUBLIC 'DATA' | ||
| 465 | EXTRN _$f:NEAR | ||
| 466 | DD _$f | ||
| 467 | .CRT\$XCU ENDS | ||
| 468 | ___ | ||
| 469 | push(@out,$tmp); | ||
| 470 | } | ||
| 471 | |||
| 472 | 1; | ||
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl deleted file mode 100644 index a4c947165e..0000000000 --- a/src/lib/libcrypto/perlasm/x86unix.pl +++ /dev/null | |||
| @@ -1,725 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | package x86unix; # GAS actually... | ||
| 4 | |||
| 5 | $label="L000"; | ||
| 6 | $const=""; | ||
| 7 | $constl=0; | ||
| 8 | |||
| 9 | $align=($main'aout)?"4":"16"; | ||
| 10 | $under=($main'aout or $main'coff)?"_":""; | ||
| 11 | $dot=($main'aout)?"":"."; | ||
| 12 | $com_start="#" if ($main'aout or $main'coff); | ||
| 13 | |||
| 14 | sub main'asm_init_output { @out=(); } | ||
| 15 | sub main'asm_get_output { return(@out); } | ||
| 16 | sub main'get_labels { return(@labels); } | ||
| 17 | sub main'external_label { push(@labels,@_); } | ||
| 18 | |||
| 19 | if ($main'cpp) | ||
| 20 | { | ||
| 21 | $align="ALIGN"; | ||
| 22 | $under=""; | ||
| 23 | $com_start='/*'; | ||
| 24 | $com_end='*/'; | ||
| 25 | } | ||
| 26 | |||
| 27 | %lb=( 'eax', '%al', | ||
| 28 | 'ebx', '%bl', | ||
| 29 | 'ecx', '%cl', | ||
| 30 | 'edx', '%dl', | ||
| 31 | 'ax', '%al', | ||
| 32 | 'bx', '%bl', | ||
| 33 | 'cx', '%cl', | ||
| 34 | 'dx', '%dl', | ||
| 35 | ); | ||
| 36 | |||
| 37 | %hb=( 'eax', '%ah', | ||
| 38 | 'ebx', '%bh', | ||
| 39 | 'ecx', '%ch', | ||
| 40 | 'edx', '%dh', | ||
| 41 | 'ax', '%ah', | ||
| 42 | 'bx', '%bh', | ||
| 43 | 'cx', '%ch', | ||
| 44 | 'dx', '%dh', | ||
| 45 | ); | ||
| 46 | |||
| 47 | %regs=( 'eax', '%eax', | ||
| 48 | 'ebx', '%ebx', | ||
| 49 | 'ecx', '%ecx', | ||
| 50 | 'edx', '%edx', | ||
| 51 | 'esi', '%esi', | ||
| 52 | 'edi', '%edi', | ||
| 53 | 'ebp', '%ebp', | ||
| 54 | 'esp', '%esp', | ||
| 55 | |||
| 56 | 'mm0', '%mm0', | ||
| 57 | 'mm1', '%mm1', | ||
| 58 | 'mm2', '%mm2', | ||
| 59 | 'mm3', '%mm3', | ||
| 60 | 'mm4', '%mm4', | ||
| 61 | 'mm5', '%mm5', | ||
| 62 | 'mm6', '%mm6', | ||
| 63 | 'mm7', '%mm7', | ||
| 64 | |||
| 65 | 'xmm0', '%xmm0', | ||
| 66 | 'xmm1', '%xmm1', | ||
| 67 | 'xmm2', '%xmm2', | ||
| 68 | 'xmm3', '%xmm3', | ||
| 69 | 'xmm4', '%xmm4', | ||
| 70 | 'xmm5', '%xmm5', | ||
| 71 | 'xmm6', '%xmm6', | ||
| 72 | 'xmm7', '%xmm7', | ||
| 73 | ); | ||
| 74 | |||
| 75 | %reg_val=( | ||
| 76 | 'eax', 0x00, | ||
| 77 | 'ebx', 0x03, | ||
| 78 | 'ecx', 0x01, | ||
| 79 | 'edx', 0x02, | ||
| 80 | 'esi', 0x06, | ||
| 81 | 'edi', 0x07, | ||
| 82 | 'ebp', 0x05, | ||
| 83 | 'esp', 0x04, | ||
| 84 | ); | ||
| 85 | |||
| 86 | sub main'LB | ||
| 87 | { | ||
| 88 | (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n"; | ||
| 89 | return($lb{$_[0]}); | ||
| 90 | } | ||
| 91 | |||
| 92 | sub main'HB | ||
| 93 | { | ||
| 94 | (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n"; | ||
| 95 | return($hb{$_[0]}); | ||
| 96 | } | ||
| 97 | |||
| 98 | sub main'DWP | ||
| 99 | { | ||
| 100 | local($addr,$reg1,$reg2,$idx)=@_; | ||
| 101 | |||
| 102 | $ret=""; | ||
| 103 | $addr =~ s/(^|[+ \t])([A-Za-z_]+[A-Za-z0-9_]+)($|[+ \t])/$1$under$2$3/; | ||
| 104 | $reg1="$regs{$reg1}" if defined($regs{$reg1}); | ||
| 105 | $reg2="$regs{$reg2}" if defined($regs{$reg2}); | ||
| 106 | $ret.=$addr if ($addr ne "") && ($addr ne 0); | ||
| 107 | if ($reg2 ne "") | ||
| 108 | { | ||
| 109 | if($idx ne "" && $idx != 0) | ||
| 110 | { $ret.="($reg1,$reg2,$idx)"; } | ||
| 111 | else | ||
| 112 | { $ret.="($reg1,$reg2)"; } | ||
| 113 | } | ||
| 114 | elsif ($reg1 ne "") | ||
| 115 | { $ret.="($reg1)" } | ||
| 116 | return($ret); | ||
| 117 | } | ||
| 118 | |||
| 119 | sub main'QWP | ||
| 120 | { | ||
| 121 | return(&main'DWP(@_)); | ||
| 122 | } | ||
| 123 | |||
| 124 | sub main'BP | ||
| 125 | { | ||
| 126 | return(&main'DWP(@_)); | ||
| 127 | } | ||
| 128 | |||
| 129 | sub main'BC | ||
| 130 | { | ||
| 131 | return @_; | ||
| 132 | } | ||
| 133 | |||
| 134 | sub main'DWC | ||
| 135 | { | ||
| 136 | return @_; | ||
| 137 | } | ||
| 138 | |||
| 139 | #sub main'BP | ||
| 140 | # { | ||
| 141 | # local($addr,$reg1,$reg2,$idx)=@_; | ||
| 142 | # | ||
| 143 | # $ret=""; | ||
| 144 | # | ||
| 145 | # $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/; | ||
| 146 | # $reg1="$regs{$reg1}" if defined($regs{$reg1}); | ||
| 147 | # $reg2="$regs{$reg2}" if defined($regs{$reg2}); | ||
| 148 | # $ret.=$addr if ($addr ne "") && ($addr ne 0); | ||
| 149 | # if ($reg2 ne "") | ||
| 150 | # { $ret.="($reg1,$reg2,$idx)"; } | ||
| 151 | # else | ||
| 152 | # { $ret.="($reg1)" } | ||
| 153 | # return($ret); | ||
| 154 | # } | ||
| 155 | |||
| 156 | sub main'mov { &out2("movl",@_); } | ||
| 157 | sub main'movb { &out2("movb",@_); } | ||
| 158 | sub main'and { &out2("andl",@_); } | ||
| 159 | sub main'or { &out2("orl",@_); } | ||
| 160 | sub main'shl { &out2("sall",@_); } | ||
| 161 | sub main'shr { &out2("shrl",@_); } | ||
| 162 | sub main'xor { &out2("xorl",@_); } | ||
| 163 | sub main'xorb { &out2("xorb",@_); } | ||
| 164 | sub main'add { &out2($_[0]=~/%[a-d][lh]/?"addb":"addl",@_); } | ||
| 165 | sub main'adc { &out2("adcl",@_); } | ||
| 166 | sub main'sub { &out2("subl",@_); } | ||
| 167 | sub main'sbb { &out2("sbbl",@_); } | ||
| 168 | sub main'rotl { &out2("roll",@_); } | ||
| 169 | sub main'rotr { &out2("rorl",@_); } | ||
| 170 | sub main'exch { &out2($_[0]=~/%[a-d][lh]/?"xchgb":"xchgl",@_); } | ||
| 171 | sub main'cmp { &out2("cmpl",@_); } | ||
| 172 | sub main'lea { &out2("leal",@_); } | ||
| 173 | sub main'mul { &out1("mull",@_); } | ||
| 174 | sub main'imul { &out2("imull",@_); } | ||
| 175 | sub main'div { &out1("divl",@_); } | ||
| 176 | sub main'jmp { &out1("jmp",@_); } | ||
| 177 | sub main'jmp_ptr { &out1p("jmp",@_); } | ||
| 178 | sub main'je { &out1("je",@_); } | ||
| 179 | sub main'jle { &out1("jle",@_); } | ||
| 180 | sub main'jne { &out1("jne",@_); } | ||
| 181 | sub main'jnz { &out1("jnz",@_); } | ||
| 182 | sub main'jz { &out1("jz",@_); } | ||
| 183 | sub main'jge { &out1("jge",@_); } | ||
| 184 | sub main'jl { &out1("jl",@_); } | ||
| 185 | sub main'ja { &out1("ja",@_); } | ||
| 186 | sub main'jae { &out1("jae",@_); } | ||
| 187 | sub main'jb { &out1("jb",@_); } | ||
| 188 | sub main'jbe { &out1("jbe",@_); } | ||
| 189 | sub main'jc { &out1("jc",@_); } | ||
| 190 | sub main'jnc { &out1("jnc",@_); } | ||
| 191 | sub main'jno { &out1("jno",@_); } | ||
| 192 | sub main'dec { &out1("decl",@_); } | ||
| 193 | sub main'inc { &out1($_[0]=~/%[a-d][hl]/?"incb":"incl",@_); } | ||
| 194 | sub main'push { &out1("pushl",@_); $stack+=4; } | ||
| 195 | sub main'pop { &out1("popl",@_); $stack-=4; } | ||
| 196 | sub main'pushf { &out0("pushfl"); $stack+=4; } | ||
| 197 | sub main'popf { &out0("popfl"); $stack-=4; } | ||
| 198 | sub main'not { &out1("notl",@_); } | ||
| 199 | sub main'call { my $pre=$under; | ||
| 200 | foreach $i (%label) | ||
| 201 | { if ($label{$i} eq $_[0]) { $pre=''; last; } } | ||
| 202 | &out1("call",$pre.$_[0]); | ||
| 203 | } | ||
| 204 | sub main'call_ptr { &out1p("call",@_); } | ||
| 205 | sub main'ret { &out0("ret"); } | ||
| 206 | sub main'nop { &out0("nop"); } | ||
| 207 | sub main'test { &out2("testl",@_); } | ||
| 208 | sub main'bt { &out2("btl",@_); } | ||
| 209 | sub main'leave { &out0("leave"); } | ||
| 210 | sub main'cpuid { &out0(".byte\t0x0f,0xa2"); } | ||
| 211 | sub main'rdtsc { &out0(".byte\t0x0f,0x31"); } | ||
| 212 | sub main'halt { &out0("hlt"); } | ||
| 213 | sub main'movz { &out2("movzbl",@_); } | ||
| 214 | sub main'neg { &out1("negl",@_); } | ||
| 215 | sub main'cld { &out0("cld"); } | ||
| 216 | |||
| 217 | # SSE2 | ||
| 218 | sub main'emms { &out0("emms"); } | ||
| 219 | sub main'movd { &out2("movd",@_); } | ||
| 220 | sub main'movdqu { &out2("movdqu",@_); } | ||
| 221 | sub main'movdqa { &out2("movdqa",@_); } | ||
| 222 | sub main'movdq2q{ &out2("movdq2q",@_); } | ||
| 223 | sub main'movq2dq{ &out2("movq2dq",@_); } | ||
| 224 | sub main'paddq { &out2("paddq",@_); } | ||
| 225 | sub main'pmuludq{ &out2("pmuludq",@_); } | ||
| 226 | sub main'psrlq { &out2("psrlq",@_); } | ||
| 227 | sub main'psllq { &out2("psllq",@_); } | ||
| 228 | sub main'pxor { &out2("pxor",@_); } | ||
| 229 | sub main'por { &out2("por",@_); } | ||
| 230 | sub main'pand { &out2("pand",@_); } | ||
| 231 | sub main'movq { | ||
| 232 | local($p1,$p2,$optimize)=@_; | ||
| 233 | if ($optimize && $p1=~/^mm[0-7]$/ && $p2=~/^mm[0-7]$/) | ||
| 234 | # movq between mmx registers can sink Intel CPUs | ||
| 235 | { push(@out,"\tpshufw\t\$0xe4,%$p2,%$p1\n"); } | ||
| 236 | else { &out2("movq",@_); } | ||
| 237 | } | ||
| 238 | |||
| 239 | # The bswapl instruction is new for the 486. Emulate if i386. | ||
| 240 | sub main'bswap | ||
| 241 | { | ||
| 242 | if ($main'i386) | ||
| 243 | { | ||
| 244 | &main'comment("bswapl @_"); | ||
| 245 | &main'exch(main'HB(@_),main'LB(@_)); | ||
| 246 | &main'rotr(@_,16); | ||
| 247 | &main'exch(main'HB(@_),main'LB(@_)); | ||
| 248 | } | ||
| 249 | else | ||
| 250 | { | ||
| 251 | &out1("bswapl",@_); | ||
| 252 | } | ||
| 253 | } | ||
| 254 | |||
| 255 | sub out2 | ||
| 256 | { | ||
| 257 | local($name,$p1,$p2)=@_; | ||
| 258 | local($l,$ll,$t); | ||
| 259 | local(%special)=( "roll",0xD1C0,"rorl",0xD1C8, | ||
| 260 | "rcll",0xD1D0,"rcrl",0xD1D8, | ||
| 261 | "shll",0xD1E0,"shrl",0xD1E8, | ||
| 262 | "sarl",0xD1F8); | ||
| 263 | |||
| 264 | if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1)) | ||
| 265 | { | ||
| 266 | $op=$special{$name}|$reg_val{$p1}; | ||
| 267 | $tmp1=sprintf(".byte %d\n",($op>>8)&0xff); | ||
| 268 | $tmp2=sprintf(".byte %d\t",$op &0xff); | ||
| 269 | push(@out,$tmp1); | ||
| 270 | push(@out,$tmp2); | ||
| 271 | |||
| 272 | $p2=&conv($p2); | ||
| 273 | $p1=&conv($p1); | ||
| 274 | &main'comment("$name $p2 $p1"); | ||
| 275 | return; | ||
| 276 | } | ||
| 277 | |||
| 278 | push(@out,"\t$name\t"); | ||
| 279 | $t=&conv($p2).","; | ||
| 280 | $l=length($t); | ||
| 281 | push(@out,$t); | ||
| 282 | $ll=4-($l+9)/8; | ||
| 283 | $tmp1=sprintf("\t" x $ll); | ||
| 284 | push(@out,$tmp1); | ||
| 285 | push(@out,&conv($p1)."\n"); | ||
| 286 | } | ||
| 287 | |||
| 288 | sub out1 | ||
| 289 | { | ||
| 290 | local($name,$p1)=@_; | ||
| 291 | local($l,$t); | ||
| 292 | local(%special)=("bswapl",0x0FC8); | ||
| 293 | |||
| 294 | if ((defined($special{$name})) && defined($regs{$p1})) | ||
| 295 | { | ||
| 296 | $op=$special{$name}|$reg_val{$p1}; | ||
| 297 | $tmp1=sprintf(".byte %d\n",($op>>8)&0xff); | ||
| 298 | $tmp2=sprintf(".byte %d\t",$op &0xff); | ||
| 299 | push(@out,$tmp1); | ||
| 300 | push(@out,$tmp2); | ||
| 301 | |||
| 302 | $p2=&conv($p2); | ||
| 303 | $p1=&conv($p1); | ||
| 304 | &main'comment("$name $p2 $p1"); | ||
| 305 | return; | ||
| 306 | } | ||
| 307 | |||
| 308 | push(@out,"\t$name\t".&conv($p1)."\n"); | ||
| 309 | } | ||
| 310 | |||
| 311 | sub out1p | ||
| 312 | { | ||
| 313 | local($name,$p1)=@_; | ||
| 314 | local($l,$t); | ||
| 315 | |||
| 316 | push(@out,"\t$name\t*".&conv($p1)."\n"); | ||
| 317 | } | ||
| 318 | |||
| 319 | sub out0 | ||
| 320 | { | ||
| 321 | push(@out,"\t$_[0]\n"); | ||
| 322 | } | ||
| 323 | |||
| 324 | sub conv | ||
| 325 | { | ||
| 326 | local($p)=@_; | ||
| 327 | |||
| 328 | # $p =~ s/0x([0-9A-Fa-f]+)/0$1h/; | ||
| 329 | |||
| 330 | $p=$regs{$p} if (defined($regs{$p})); | ||
| 331 | |||
| 332 | $p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/; | ||
| 333 | $p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/; | ||
| 334 | return $p; | ||
| 335 | } | ||
| 336 | |||
| 337 | sub main'file | ||
| 338 | { | ||
| 339 | local($file)=@_; | ||
| 340 | |||
| 341 | local($tmp)=<<"EOF"; | ||
| 342 | .file "$file.s" | ||
| 343 | EOF | ||
| 344 | push(@out,$tmp); | ||
| 345 | } | ||
| 346 | |||
| 347 | sub main'function_begin | ||
| 348 | { | ||
| 349 | local($func)=@_; | ||
| 350 | |||
| 351 | &main'external_label($func); | ||
| 352 | $func=$under.$func; | ||
| 353 | |||
| 354 | local($tmp)=<<"EOF"; | ||
| 355 | .text | ||
| 356 | .globl $func | ||
| 357 | EOF | ||
| 358 | push(@out,$tmp); | ||
| 359 | if ($main'cpp) | ||
| 360 | { $tmp=push(@out,"TYPE($func,\@function)\n"); } | ||
| 361 | elsif ($main'coff) | ||
| 362 | { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } | ||
| 363 | elsif ($main'aout and !$main'pic) | ||
| 364 | { } | ||
| 365 | else { $tmp=push(@out,".type\t$func,\@function\n"); } | ||
| 366 | push(@out,".align\t$align\n"); | ||
| 367 | push(@out,"$func:\n"); | ||
| 368 | $tmp=<<"EOF"; | ||
| 369 | pushl %ebp | ||
| 370 | pushl %ebx | ||
| 371 | pushl %esi | ||
| 372 | pushl %edi | ||
| 373 | |||
| 374 | EOF | ||
| 375 | push(@out,$tmp); | ||
| 376 | $stack=20; | ||
| 377 | } | ||
| 378 | |||
| 379 | sub main'function_begin_B | ||
| 380 | { | ||
| 381 | local($func,$extra)=@_; | ||
| 382 | |||
| 383 | &main'external_label($func); | ||
| 384 | $func=$under.$func; | ||
| 385 | |||
| 386 | local($tmp)=<<"EOF"; | ||
| 387 | .text | ||
| 388 | .globl $func | ||
| 389 | EOF | ||
| 390 | push(@out,$tmp); | ||
| 391 | if ($main'cpp) | ||
| 392 | { push(@out,"TYPE($func,\@function)\n"); } | ||
| 393 | elsif ($main'coff) | ||
| 394 | { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } | ||
| 395 | elsif ($main'aout and !$main'pic) | ||
| 396 | { } | ||
| 397 | else { push(@out,".type $func,\@function\n"); } | ||
| 398 | push(@out,".align\t$align\n"); | ||
| 399 | push(@out,"$func:\n"); | ||
| 400 | $stack=4; | ||
| 401 | } | ||
| 402 | |||
| 403 | sub main'function_end | ||
| 404 | { | ||
| 405 | local($func)=@_; | ||
| 406 | |||
| 407 | $func=$under.$func; | ||
| 408 | |||
| 409 | local($tmp)=<<"EOF"; | ||
| 410 | popl %edi | ||
| 411 | popl %esi | ||
| 412 | popl %ebx | ||
| 413 | popl %ebp | ||
| 414 | ret | ||
| 415 | ${dot}L_${func}_end: | ||
| 416 | EOF | ||
| 417 | push(@out,$tmp); | ||
| 418 | |||
| 419 | if ($main'cpp) | ||
| 420 | { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); } | ||
| 421 | elsif ($main'coff or $main'aout) | ||
| 422 | { } | ||
| 423 | else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); } | ||
| 424 | push(@out,".ident \"$func\"\n"); | ||
| 425 | $stack=0; | ||
| 426 | %label=(); | ||
| 427 | } | ||
| 428 | |||
| 429 | sub main'function_end_A | ||
| 430 | { | ||
| 431 | local($func)=@_; | ||
| 432 | |||
| 433 | local($tmp)=<<"EOF"; | ||
| 434 | popl %edi | ||
| 435 | popl %esi | ||
| 436 | popl %ebx | ||
| 437 | popl %ebp | ||
| 438 | ret | ||
| 439 | EOF | ||
| 440 | push(@out,$tmp); | ||
| 441 | } | ||
| 442 | |||
| 443 | sub main'function_end_B | ||
| 444 | { | ||
| 445 | local($func)=@_; | ||
| 446 | |||
| 447 | $func=$under.$func; | ||
| 448 | |||
| 449 | push(@out,"${dot}L_${func}_end:\n"); | ||
| 450 | if ($main'cpp) | ||
| 451 | { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); } | ||
| 452 | elsif ($main'coff or $main'aout) | ||
| 453 | { } | ||
| 454 | else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); } | ||
| 455 | push(@out,".ident \"$func\"\n"); | ||
| 456 | $stack=0; | ||
| 457 | %label=(); | ||
| 458 | } | ||
| 459 | |||
| 460 | sub main'wparam | ||
| 461 | { | ||
| 462 | local($num)=@_; | ||
| 463 | |||
| 464 | return(&main'DWP($stack+$num*4,"esp","",0)); | ||
| 465 | } | ||
| 466 | |||
| 467 | sub main'stack_push | ||
| 468 | { | ||
| 469 | local($num)=@_; | ||
| 470 | $stack+=$num*4; | ||
| 471 | &main'sub("esp",$num*4); | ||
| 472 | } | ||
| 473 | |||
| 474 | sub main'stack_pop | ||
| 475 | { | ||
| 476 | local($num)=@_; | ||
| 477 | $stack-=$num*4; | ||
| 478 | &main'add("esp",$num*4); | ||
| 479 | } | ||
| 480 | |||
| 481 | sub main'swtmp | ||
| 482 | { | ||
| 483 | return(&main'DWP($_[0]*4,"esp","",0)); | ||
| 484 | } | ||
| 485 | |||
| 486 | # Should use swtmp, which is above esp. Linix can trash the stack above esp | ||
| 487 | #sub main'wtmp | ||
| 488 | # { | ||
| 489 | # local($num)=@_; | ||
| 490 | # | ||
| 491 | # return(&main'DWP(-($num+1)*4,"esp","",0)); | ||
| 492 | # } | ||
| 493 | |||
| 494 | sub main'comment | ||
| 495 | { | ||
| 496 | if (!defined($com_start) or $main'elf) | ||
| 497 | { # Regarding $main'elf above... | ||
| 498 | # GNU and SVR4 as'es use different comment delimiters, | ||
| 499 | push(@out,"\n"); # so we just skip ELF comments... | ||
| 500 | return; | ||
| 501 | } | ||
| 502 | foreach (@_) | ||
| 503 | { | ||
| 504 | if (/^\s*$/) | ||
| 505 | { push(@out,"\n"); } | ||
| 506 | else | ||
| 507 | { push(@out,"\t$com_start $_ $com_end\n"); } | ||
| 508 | } | ||
| 509 | } | ||
| 510 | |||
| 511 | sub main'public_label | ||
| 512 | { | ||
| 513 | $label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]})); | ||
| 514 | push(@out,".globl\t$label{$_[0]}\n"); | ||
| 515 | } | ||
| 516 | |||
| 517 | sub main'label | ||
| 518 | { | ||
| 519 | if (!defined($label{$_[0]})) | ||
| 520 | { | ||
| 521 | $label{$_[0]}="${dot}${label}${_[0]}"; | ||
| 522 | $label++; | ||
| 523 | } | ||
| 524 | return($label{$_[0]}); | ||
| 525 | } | ||
| 526 | |||
| 527 | sub main'set_label | ||
| 528 | { | ||
| 529 | if (!defined($label{$_[0]})) | ||
| 530 | { | ||
| 531 | $label{$_[0]}="${dot}${label}${_[0]}"; | ||
| 532 | $label++; | ||
| 533 | } | ||
| 534 | if ($_[1]!=0) | ||
| 535 | { | ||
| 536 | if ($_[1]>1) { main'align($_[1]); } | ||
| 537 | else { push(@out,".align $align\n"); } | ||
| 538 | } | ||
| 539 | push(@out,"$label{$_[0]}:\n"); | ||
| 540 | } | ||
| 541 | |||
| 542 | sub main'file_end | ||
| 543 | { | ||
| 544 | # try to detect if SSE2 or MMX extensions were used on ELF platform... | ||
| 545 | if ($main'elf && grep {/\b%[x]*mm[0-7]\b|OPENSSL_ia32cap_P\b/i} @out) { | ||
| 546 | local($tmp); | ||
| 547 | |||
| 548 | push (@out,"\n.section\t.bss\n"); | ||
| 549 | push (@out,".comm\t${under}OPENSSL_ia32cap_P,4,4\n"); | ||
| 550 | |||
| 551 | return; | ||
| 552 | } | ||
| 553 | |||
| 554 | if ($const ne "") | ||
| 555 | { | ||
| 556 | push(@out,".section .rodata\n"); | ||
| 557 | push(@out,$const); | ||
| 558 | $const=""; | ||
| 559 | } | ||
| 560 | } | ||
| 561 | |||
| 562 | sub main'data_byte | ||
| 563 | { | ||
| 564 | push(@out,"\t.byte\t".join(',',@_)."\n"); | ||
| 565 | } | ||
| 566 | |||
| 567 | sub main'data_word | ||
| 568 | { | ||
| 569 | push(@out,"\t.long\t".join(',',@_)."\n"); | ||
| 570 | } | ||
| 571 | |||
| 572 | sub main'align | ||
| 573 | { | ||
| 574 | my $val=$_[0],$p2,$i; | ||
| 575 | if ($main'aout) { | ||
| 576 | for ($p2=0;$val!=0;$val>>=1) { $p2++; } | ||
| 577 | $val=$p2-1; | ||
| 578 | $val.=",0x90"; | ||
| 579 | } | ||
| 580 | push(@out,".align\t$val\n"); | ||
| 581 | } | ||
| 582 | |||
| 583 | # debug output functions: puts, putx, printf | ||
| 584 | |||
| 585 | sub main'puts | ||
| 586 | { | ||
| 587 | &pushvars(); | ||
| 588 | &main'push('$Lstring' . ++$constl); | ||
| 589 | &main'call('puts'); | ||
| 590 | $stack-=4; | ||
| 591 | &main'add("esp",4); | ||
| 592 | &popvars(); | ||
| 593 | |||
| 594 | $const .= "Lstring$constl:\n\t.string \"@_[0]\"\n"; | ||
| 595 | } | ||
| 596 | |||
| 597 | sub main'putx | ||
| 598 | { | ||
| 599 | &pushvars(); | ||
| 600 | &main'push($_[0]); | ||
| 601 | &main'push('$Lstring' . ++$constl); | ||
| 602 | &main'call('printf'); | ||
| 603 | &main'add("esp",8); | ||
| 604 | $stack-=8; | ||
| 605 | &popvars(); | ||
| 606 | |||
| 607 | $const .= "Lstring$constl:\n\t.string \"\%X\"\n"; | ||
| 608 | } | ||
| 609 | |||
| 610 | sub main'printf | ||
| 611 | { | ||
| 612 | $ostack = $stack; | ||
| 613 | &pushvars(); | ||
| 614 | for ($i = @_ - 1; $i >= 0; $i--) | ||
| 615 | { | ||
| 616 | if ($i == 0) # change this to support %s format strings | ||
| 617 | { | ||
| 618 | &main'push('$Lstring' . ++$constl); | ||
| 619 | $const .= "Lstring$constl:\n\t.string \"@_[$i]\"\n"; | ||
| 620 | } | ||
| 621 | else | ||
| 622 | { | ||
| 623 | if ($_[$i] =~ /([0-9]*)\(%esp\)/) | ||
| 624 | { | ||
| 625 | &main'push(($1 + $stack - $ostack) . '(%esp)'); | ||
| 626 | } | ||
| 627 | else | ||
| 628 | { | ||
| 629 | &main'push($_[$i]); | ||
| 630 | } | ||
| 631 | } | ||
| 632 | } | ||
| 633 | &main'call('printf'); | ||
| 634 | $stack-=4*@_; | ||
| 635 | &main'add("esp",4*@_); | ||
| 636 | &popvars(); | ||
| 637 | } | ||
| 638 | |||
| 639 | sub pushvars | ||
| 640 | { | ||
| 641 | &main'pushf(); | ||
| 642 | &main'push("edx"); | ||
| 643 | &main'push("ecx"); | ||
| 644 | &main'push("eax"); | ||
| 645 | } | ||
| 646 | |||
| 647 | sub popvars | ||
| 648 | { | ||
| 649 | &main'pop("eax"); | ||
| 650 | &main'pop("ecx"); | ||
| 651 | &main'pop("edx"); | ||
| 652 | &main'popf(); | ||
| 653 | } | ||
| 654 | |||
| 655 | sub main'picmeup | ||
| 656 | { | ||
| 657 | local($dst,$sym)=@_; | ||
| 658 | if ($main'cpp) | ||
| 659 | { | ||
| 660 | local($tmp)=<<___; | ||
| 661 | #if (defined(ELF) || defined(SOL)) && defined(PIC) | ||
| 662 | call 1f | ||
| 663 | 1: popl $regs{$dst} | ||
| 664 | addl \$_GLOBAL_OFFSET_TABLE_+[.-1b],$regs{$dst} | ||
| 665 | movl $sym\@GOT($regs{$dst}),$regs{$dst} | ||
| 666 | #else | ||
| 667 | leal $sym,$regs{$dst} | ||
| 668 | #endif | ||
| 669 | ___ | ||
| 670 | push(@out,$tmp); | ||
| 671 | } | ||
| 672 | elsif ($main'pic && ($main'elf || $main'aout)) | ||
| 673 | { | ||
| 674 | &main'call(&main'label("PIC_me_up")); | ||
| 675 | &main'set_label("PIC_me_up"); | ||
| 676 | &main'blindpop($dst); | ||
| 677 | &main'add($dst,"\$${under}_GLOBAL_OFFSET_TABLE_+[.-". | ||
| 678 | &main'label("PIC_me_up") . "]"); | ||
| 679 | &main'mov($dst,&main'DWP($under.$sym."\@GOT",$dst)); | ||
| 680 | } | ||
| 681 | else | ||
| 682 | { | ||
| 683 | &main'lea($dst,&main'DWP($sym)); | ||
| 684 | } | ||
| 685 | } | ||
| 686 | |||
| 687 | sub main'blindpop { &out1("popl",@_); } | ||
| 688 | |||
| 689 | sub main'initseg | ||
| 690 | { | ||
| 691 | local($f)=@_; | ||
| 692 | local($tmp); | ||
| 693 | if ($main'elf) | ||
| 694 | { | ||
| 695 | $tmp=<<___; | ||
| 696 | .section .init | ||
| 697 | call $under$f | ||
| 698 | jmp .Linitalign | ||
| 699 | .align $align | ||
| 700 | .Linitalign: | ||
| 701 | ___ | ||
| 702 | } | ||
| 703 | elsif ($main'coff) | ||
| 704 | { | ||
| 705 | $tmp=<<___; # applies to both Cygwin and Mingw | ||
| 706 | .section .ctors | ||
| 707 | .long $under$f | ||
| 708 | ___ | ||
| 709 | } | ||
| 710 | elsif ($main'aout) | ||
| 711 | { | ||
| 712 | local($ctor)="${under}_GLOBAL_\$I\$$f"; | ||
| 713 | $tmp=".text\n"; | ||
| 714 | $tmp.=".type $ctor,\@function\n" if ($main'pic); | ||
| 715 | $tmp.=<<___; # OpenBSD way... | ||
| 716 | .globl $ctor | ||
| 717 | .align 2 | ||
| 718 | $ctor: | ||
| 719 | jmp $under$f | ||
| 720 | ___ | ||
| 721 | } | ||
| 722 | push(@out,$tmp) if ($tmp); | ||
| 723 | } | ||
| 724 | |||
| 725 | 1; | ||
diff --git a/src/lib/libcrypto/pqueue/Makefile b/src/lib/libcrypto/pqueue/Makefile new file mode 100644 index 0000000000..fb36a0c876 --- /dev/null +++ b/src/lib/libcrypto/pqueue/Makefile | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | # | ||
| 2 | # OpenSSL/crypto/pqueue/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= pqueue | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | INCLUDES= | ||
| 9 | CFLAG=-g | ||
| 10 | MAKEFILE= Makefile | ||
| 11 | AR= ar r | ||
| 12 | |||
| 13 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 14 | |||
| 15 | GENERAL=Makefile | ||
| 16 | TEST= | ||
| 17 | APPS= | ||
| 18 | |||
| 19 | LIB=$(TOP)/libcrypto.a | ||
| 20 | LIBSRC=pqueue.c | ||
| 21 | LIBOBJ=pqueue.o | ||
| 22 | |||
| 23 | SRC= $(LIBSRC) | ||
| 24 | |||
| 25 | EXHEADER= pqueue.h | ||
| 26 | HEADER= $(EXHEADER) | ||
| 27 | |||
| 28 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 29 | |||
| 30 | top: | ||
| 31 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 32 | |||
| 33 | all: lib | ||
| 34 | |||
| 35 | lib: $(LIBOBJ) | ||
| 36 | $(AR) $(LIB) $(LIBOBJ) | ||
| 37 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 38 | @touch lib | ||
| 39 | |||
| 40 | files: | ||
| 41 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 42 | |||
| 43 | links: | ||
| 44 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 45 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 46 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 47 | |||
| 48 | install: | ||
| 49 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 50 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 51 | do \ | ||
| 52 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 53 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 54 | done; | ||
| 55 | |||
| 56 | tags: | ||
| 57 | ctags $(SRC) | ||
| 58 | |||
| 59 | tests: | ||
| 60 | |||
| 61 | lint: | ||
| 62 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 63 | |||
| 64 | depend: | ||
| 65 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 66 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 67 | |||
| 68 | dclean: | ||
| 69 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 70 | mv -f Makefile.new $(MAKEFILE) | ||
| 71 | |||
| 72 | clean: | ||
| 73 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 74 | |||
| 75 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 76 | |||
| 77 | pqueue.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 78 | pqueue.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 79 | pqueue.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 80 | pqueue.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 81 | pqueue.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 82 | pqueue.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 83 | pqueue.o: ../../include/openssl/symhacks.h ../cryptlib.h pqueue.c pqueue.h | ||
diff --git a/src/lib/libcrypto/pqueue/pq_compat.h b/src/lib/libcrypto/pqueue/pq_compat.h deleted file mode 100644 index 7b2c32725c..0000000000 --- a/src/lib/libcrypto/pqueue/pq_compat.h +++ /dev/null | |||
| @@ -1,152 +0,0 @@ | |||
| 1 | /* crypto/pqueue/pqueue_compat.h */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | |||
| 60 | #ifndef HEADER_PQ_COMPAT_H | ||
| 61 | #define HEADER_PQ_COMPAT_H | ||
| 62 | |||
| 63 | #include <openssl/opensslconf.h> | ||
| 64 | #include <openssl/bn.h> | ||
| 65 | |||
| 66 | /* | ||
| 67 | * The purpose of this header file is for supporting 64-bit integer | ||
| 68 | * manipulation on 32-bit (and lower) machines. Currently the only | ||
| 69 | * such environment is VMS, Utrix and those with smaller default integer | ||
| 70 | * sizes than 32 bits. For all such environment, we fall back to using | ||
| 71 | * BIGNUM. We may need to fine tune the conditions for systems that | ||
| 72 | * are incorrectly configured. | ||
| 73 | * | ||
| 74 | * The only clients of this code are (1) pqueue for priority, and | ||
| 75 | * (2) DTLS, for sequence number manipulation. | ||
| 76 | */ | ||
| 77 | |||
| 78 | #if (defined(THIRTY_TWO_BIT) && !defined(BN_LLONG)) || defined(SIXTEEN_BIT) || defined(EIGHT_BIT) | ||
| 79 | |||
| 80 | #define PQ_64BIT_IS_INTEGER 0 | ||
| 81 | #define PQ_64BIT_IS_BIGNUM 1 | ||
| 82 | |||
| 83 | #define PQ_64BIT BIGNUM | ||
| 84 | #define PQ_64BIT_CTX BN_CTX | ||
| 85 | |||
| 86 | #define pq_64bit_init(x) BN_init(x) | ||
| 87 | #define pq_64bit_free(x) BN_free(x) | ||
| 88 | |||
| 89 | #define pq_64bit_ctx_new(ctx) BN_CTX_new() | ||
| 90 | #define pq_64bit_ctx_free(x) BN_CTX_free(x) | ||
| 91 | |||
| 92 | #define pq_64bit_assign(x, y) BN_copy(x, y) | ||
| 93 | #define pq_64bit_assign_word(x, y) BN_set_word(x, y) | ||
| 94 | #define pq_64bit_gt(x, y) BN_ucmp(x, y) >= 1 ? 1 : 0 | ||
| 95 | #define pq_64bit_eq(x, y) BN_ucmp(x, y) == 0 ? 1 : 0 | ||
| 96 | #define pq_64bit_add_word(x, w) BN_add_word(x, w) | ||
| 97 | #define pq_64bit_sub(r, x, y) BN_sub(r, x, y) | ||
| 98 | #define pq_64bit_sub_word(x, w) BN_sub_word(x, w) | ||
| 99 | #define pq_64bit_mod(r, x, n, ctx) BN_mod(r, x, n, ctx) | ||
| 100 | |||
| 101 | #define pq_64bit_bin2num(bn, bytes, len) BN_bin2bn(bytes, len, bn) | ||
| 102 | #define pq_64bit_num2bin(bn, bytes) BN_bn2bin(bn, bytes) | ||
| 103 | #define pq_64bit_get_word(x) BN_get_word(x) | ||
| 104 | #define pq_64bit_is_bit_set(x, offset) BN_is_bit_set(x, offset) | ||
| 105 | #define pq_64bit_lshift(r, x, shift) BN_lshift(r, x, shift) | ||
| 106 | #define pq_64bit_set_bit(x, num) BN_set_bit(x, num) | ||
| 107 | #define pq_64bit_get_length(x) BN_num_bits((x)) | ||
| 108 | |||
| 109 | #else | ||
| 110 | |||
| 111 | #define PQ_64BIT_IS_INTEGER 1 | ||
| 112 | #define PQ_64BIT_IS_BIGNUM 0 | ||
| 113 | |||
| 114 | #if defined(SIXTY_FOUR_BIT) | ||
| 115 | #define PQ_64BIT BN_ULONG | ||
| 116 | #define PQ_64BIT_PRINT "%lld" | ||
| 117 | #elif defined(SIXTY_FOUR_BIT_LONG) | ||
| 118 | #define PQ_64BIT BN_ULONG | ||
| 119 | #define PQ_64BIT_PRINT "%ld" | ||
| 120 | #elif defined(THIRTY_TWO_BIT) | ||
| 121 | #define PQ_64BIT BN_ULLONG | ||
| 122 | #define PQ_64BIT_PRINT "%lld" | ||
| 123 | #endif | ||
| 124 | |||
| 125 | #define PQ_64BIT_CTX void | ||
| 126 | |||
| 127 | #define pq_64bit_init(x) | ||
| 128 | #define pq_64bit_free(x) | ||
| 129 | #define pq_64bit_ctx_new(ctx) (ctx) | ||
| 130 | #define pq_64bit_ctx_free(x) | ||
| 131 | |||
| 132 | #define pq_64bit_assign(x, y) (*(x) = *(y)) | ||
| 133 | #define pq_64bit_assign_word(x, y) (*(x) = y) | ||
| 134 | #define pq_64bit_gt(x, y) (*(x) > *(y)) | ||
| 135 | #define pq_64bit_eq(x, y) (*(x) == *(y)) | ||
| 136 | #define pq_64bit_add_word(x, w) (*(x) = (*(x) + (w))) | ||
| 137 | #define pq_64bit_sub(r, x, y) (*(r) = (*(x) - *(y))) | ||
| 138 | #define pq_64bit_sub_word(x, w) (*(x) = (*(x) - (w))) | ||
| 139 | #define pq_64bit_mod(r, x, n, ctx) | ||
| 140 | |||
| 141 | #define pq_64bit_bin2num(num, bytes, len) bytes_to_long_long(bytes, num) | ||
| 142 | #define pq_64bit_num2bin(num, bytes) long_long_to_bytes(num, bytes) | ||
| 143 | #define pq_64bit_get_word(x) *(x) | ||
| 144 | #define pq_64bit_lshift(r, x, shift) (*(r) = (*(x) << (shift))) | ||
| 145 | #define pq_64bit_set_bit(x, num) do { \ | ||
| 146 | PQ_64BIT mask = 1; \ | ||
| 147 | mask = mask << (num); \ | ||
| 148 | *(x) |= mask; \ | ||
| 149 | } while(0) | ||
| 150 | #endif /* OPENSSL_SYS_VMS */ | ||
| 151 | |||
| 152 | #endif | ||
diff --git a/src/lib/libcrypto/pqueue/pq_test.c b/src/lib/libcrypto/pqueue/pq_test.c new file mode 100644 index 0000000000..8d496dfc65 --- /dev/null +++ b/src/lib/libcrypto/pqueue/pq_test.c | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | /* crypto/pqueue/pq_test.c */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | |||
| 60 | #include "pqueue.h" | ||
| 61 | |||
| 62 | int | ||
| 63 | main(void) | ||
| 64 | { | ||
| 65 | pitem *item; | ||
| 66 | pqueue pq; | ||
| 67 | |||
| 68 | pq = pqueue_new(); | ||
| 69 | |||
| 70 | item = pitem_new(3, NULL); | ||
| 71 | pqueue_insert(pq, item); | ||
| 72 | |||
| 73 | item = pitem_new(1, NULL); | ||
| 74 | pqueue_insert(pq, item); | ||
| 75 | |||
| 76 | item = pitem_new(2, NULL); | ||
| 77 | pqueue_insert(pq, item); | ||
| 78 | |||
| 79 | item = pqueue_find(pq, 1); | ||
| 80 | fprintf(stderr, "found %ld\n", item->priority); | ||
| 81 | |||
| 82 | item = pqueue_find(pq, 2); | ||
| 83 | fprintf(stderr, "found %ld\n", item->priority); | ||
| 84 | |||
| 85 | item = pqueue_find(pq, 3); | ||
| 86 | fprintf(stderr, "found %ld\n", item ? item->priority: 0); | ||
| 87 | |||
| 88 | pqueue_print(pq); | ||
| 89 | |||
| 90 | for(item = pqueue_pop(pq); item != NULL; item = pqueue_pop(pq)) | ||
| 91 | pitem_free(item); | ||
| 92 | |||
| 93 | pqueue_free(pq); | ||
| 94 | return 0; | ||
| 95 | } | ||
diff --git a/src/lib/libcrypto/pqueue/pqueue.c b/src/lib/libcrypto/pqueue/pqueue.c new file mode 100644 index 0000000000..99a6fb874d --- /dev/null +++ b/src/lib/libcrypto/pqueue/pqueue.c | |||
| @@ -0,0 +1,253 @@ | |||
| 1 | /* crypto/pqueue/pqueue.c */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | |||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/bn.h> | ||
| 62 | #include "pqueue.h" | ||
| 63 | |||
| 64 | typedef struct _pqueue | ||
| 65 | { | ||
| 66 | pitem *items; | ||
| 67 | int count; | ||
| 68 | } pqueue_s; | ||
| 69 | |||
| 70 | pitem * | ||
| 71 | pitem_new(unsigned char *prio64be, void *data) | ||
| 72 | { | ||
| 73 | pitem *item = (pitem *) OPENSSL_malloc(sizeof(pitem)); | ||
| 74 | if (item == NULL) return NULL; | ||
| 75 | |||
| 76 | memcpy(item->priority,prio64be,sizeof(item->priority)); | ||
| 77 | |||
| 78 | item->data = data; | ||
| 79 | item->next = NULL; | ||
| 80 | |||
| 81 | return item; | ||
| 82 | } | ||
| 83 | |||
| 84 | void | ||
| 85 | pitem_free(pitem *item) | ||
| 86 | { | ||
| 87 | if (item == NULL) return; | ||
| 88 | |||
| 89 | OPENSSL_free(item); | ||
| 90 | } | ||
| 91 | |||
| 92 | pqueue_s * | ||
| 93 | pqueue_new() | ||
| 94 | { | ||
| 95 | pqueue_s *pq = (pqueue_s *) OPENSSL_malloc(sizeof(pqueue_s)); | ||
| 96 | if (pq == NULL) return NULL; | ||
| 97 | |||
| 98 | memset(pq, 0x00, sizeof(pqueue_s)); | ||
| 99 | return pq; | ||
| 100 | } | ||
| 101 | |||
| 102 | void | ||
| 103 | pqueue_free(pqueue_s *pq) | ||
| 104 | { | ||
| 105 | if (pq == NULL) return; | ||
| 106 | |||
| 107 | OPENSSL_free(pq); | ||
| 108 | } | ||
| 109 | |||
| 110 | pitem * | ||
| 111 | pqueue_insert(pqueue_s *pq, pitem *item) | ||
| 112 | { | ||
| 113 | pitem *curr, *next; | ||
| 114 | |||
| 115 | if (pq->items == NULL) | ||
| 116 | { | ||
| 117 | pq->items = item; | ||
| 118 | return item; | ||
| 119 | } | ||
| 120 | |||
| 121 | for(curr = NULL, next = pq->items; | ||
| 122 | next != NULL; | ||
| 123 | curr = next, next = next->next) | ||
| 124 | { | ||
| 125 | /* we can compare 64-bit value in big-endian encoding | ||
| 126 | * with memcmp:-) */ | ||
| 127 | int cmp = memcmp(next->priority, item->priority,8); | ||
| 128 | if (cmp > 0) /* next > item */ | ||
| 129 | { | ||
| 130 | item->next = next; | ||
| 131 | |||
| 132 | if (curr == NULL) | ||
| 133 | pq->items = item; | ||
| 134 | else | ||
| 135 | curr->next = item; | ||
| 136 | |||
| 137 | return item; | ||
| 138 | } | ||
| 139 | |||
| 140 | else if (cmp == 0) /* duplicates not allowed */ | ||
| 141 | return NULL; | ||
| 142 | } | ||
| 143 | |||
| 144 | item->next = NULL; | ||
| 145 | curr->next = item; | ||
| 146 | |||
| 147 | return item; | ||
| 148 | } | ||
| 149 | |||
| 150 | pitem * | ||
| 151 | pqueue_peek(pqueue_s *pq) | ||
| 152 | { | ||
| 153 | return pq->items; | ||
| 154 | } | ||
| 155 | |||
| 156 | pitem * | ||
| 157 | pqueue_pop(pqueue_s *pq) | ||
| 158 | { | ||
| 159 | pitem *item = pq->items; | ||
| 160 | |||
| 161 | if (pq->items != NULL) | ||
| 162 | pq->items = pq->items->next; | ||
| 163 | |||
| 164 | return item; | ||
| 165 | } | ||
| 166 | |||
| 167 | pitem * | ||
| 168 | pqueue_find(pqueue_s *pq, unsigned char *prio64be) | ||
| 169 | { | ||
| 170 | pitem *next, *prev = NULL; | ||
| 171 | pitem *found = NULL; | ||
| 172 | |||
| 173 | if ( pq->items == NULL) | ||
| 174 | return NULL; | ||
| 175 | |||
| 176 | for ( next = pq->items; next->next != NULL; | ||
| 177 | prev = next, next = next->next) | ||
| 178 | { | ||
| 179 | if ( memcmp(next->priority, prio64be,8) == 0) | ||
| 180 | { | ||
| 181 | found = next; | ||
| 182 | break; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | /* check the one last node */ | ||
| 187 | if ( memcmp(next->priority, prio64be,8) ==0) | ||
| 188 | found = next; | ||
| 189 | |||
| 190 | if ( ! found) | ||
| 191 | return NULL; | ||
| 192 | |||
| 193 | #if 0 /* find works in peek mode */ | ||
| 194 | if ( prev == NULL) | ||
| 195 | pq->items = next->next; | ||
| 196 | else | ||
| 197 | prev->next = next->next; | ||
| 198 | #endif | ||
| 199 | |||
| 200 | return found; | ||
| 201 | } | ||
| 202 | |||
| 203 | void | ||
| 204 | pqueue_print(pqueue_s *pq) | ||
| 205 | { | ||
| 206 | pitem *item = pq->items; | ||
| 207 | |||
| 208 | while(item != NULL) | ||
| 209 | { | ||
| 210 | printf("item\t%02x%02x%02x%02x%02x%02x%02x%02x\n", | ||
| 211 | item->priority[0],item->priority[1], | ||
| 212 | item->priority[2],item->priority[3], | ||
| 213 | item->priority[4],item->priority[5], | ||
| 214 | item->priority[6],item->priority[7]); | ||
| 215 | item = item->next; | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | pitem * | ||
| 220 | pqueue_iterator(pqueue_s *pq) | ||
| 221 | { | ||
| 222 | return pqueue_peek(pq); | ||
| 223 | } | ||
| 224 | |||
| 225 | pitem * | ||
| 226 | pqueue_next(pitem **item) | ||
| 227 | { | ||
| 228 | pitem *ret; | ||
| 229 | |||
| 230 | if ( item == NULL || *item == NULL) | ||
| 231 | return NULL; | ||
| 232 | |||
| 233 | |||
| 234 | /* *item != NULL */ | ||
| 235 | ret = *item; | ||
| 236 | *item = (*item)->next; | ||
| 237 | |||
| 238 | return ret; | ||
| 239 | } | ||
| 240 | |||
| 241 | int | ||
| 242 | pqueue_size(pqueue_s *pq) | ||
| 243 | { | ||
| 244 | pitem *item = pq->items; | ||
| 245 | int count = 0; | ||
| 246 | |||
| 247 | while(item != NULL) | ||
| 248 | { | ||
| 249 | count++; | ||
| 250 | item = item->next; | ||
| 251 | } | ||
| 252 | return count; | ||
| 253 | } | ||
diff --git a/src/lib/libcrypto/pqueue/pqueue.h b/src/lib/libcrypto/pqueue/pqueue.h new file mode 100644 index 0000000000..87fc9037c8 --- /dev/null +++ b/src/lib/libcrypto/pqueue/pqueue.h | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | /* crypto/pqueue/pqueue.h */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | |||
| 60 | #ifndef HEADER_PQUEUE_H | ||
| 61 | #define HEADER_PQUEUE_H | ||
| 62 | |||
| 63 | #include <stdio.h> | ||
| 64 | #include <stdlib.h> | ||
| 65 | #include <string.h> | ||
| 66 | |||
| 67 | typedef struct _pqueue *pqueue; | ||
| 68 | |||
| 69 | typedef struct _pitem | ||
| 70 | { | ||
| 71 | unsigned char priority[8]; /* 64-bit value in big-endian encoding */ | ||
| 72 | void *data; | ||
| 73 | struct _pitem *next; | ||
| 74 | } pitem; | ||
| 75 | |||
| 76 | typedef struct _pitem *piterator; | ||
| 77 | |||
| 78 | pitem *pitem_new(unsigned char *prio64be, void *data); | ||
| 79 | void pitem_free(pitem *item); | ||
| 80 | |||
| 81 | pqueue pqueue_new(void); | ||
| 82 | void pqueue_free(pqueue pq); | ||
| 83 | |||
| 84 | pitem *pqueue_insert(pqueue pq, pitem *item); | ||
| 85 | pitem *pqueue_peek(pqueue pq); | ||
| 86 | pitem *pqueue_pop(pqueue pq); | ||
| 87 | pitem *pqueue_find(pqueue pq, unsigned char *prio64be); | ||
| 88 | pitem *pqueue_iterator(pqueue pq); | ||
| 89 | pitem *pqueue_next(piterator *iter); | ||
| 90 | |||
| 91 | void pqueue_print(pqueue pq); | ||
| 92 | int pqueue_size(pqueue pq); | ||
| 93 | |||
| 94 | #endif /* ! HEADER_PQUEUE_H */ | ||
diff --git a/src/lib/libcrypto/rand/rand_eng.c b/src/lib/libcrypto/rand/rand_eng.c deleted file mode 100644 index 1669cef43c..0000000000 --- a/src/lib/libcrypto/rand/rand_eng.c +++ /dev/null | |||
| @@ -1,152 +0,0 @@ | |||
| 1 | /* crypto/rand/rand_lib.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <time.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "rand_lcl.h" | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | #ifdef OPENSSL_FIPS | ||
| 65 | #include <openssl/fips.h> | ||
| 66 | #include <openssl/fips_rand.h> | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #ifndef OPENSSL_NO_ENGINE | ||
| 70 | #include <openssl/engine.h> | ||
| 71 | #endif | ||
| 72 | |||
| 73 | #if defined(OPENSSL_FIPS) && !defined(OPENSSL_NO_ENGINE) | ||
| 74 | |||
| 75 | /* non-NULL if default_RAND_meth is ENGINE-provided */ | ||
| 76 | static ENGINE *funct_ref =NULL; | ||
| 77 | |||
| 78 | int eng_RAND_set_rand_method(const RAND_METHOD *meth, const RAND_METHOD **pmeth) | ||
| 79 | { | ||
| 80 | if(funct_ref) | ||
| 81 | { | ||
| 82 | ENGINE_finish(funct_ref); | ||
| 83 | funct_ref = NULL; | ||
| 84 | } | ||
| 85 | *pmeth = meth; | ||
| 86 | return 1; | ||
| 87 | } | ||
| 88 | |||
| 89 | const RAND_METHOD *eng_RAND_get_rand_method(const RAND_METHOD **pmeth) | ||
| 90 | { | ||
| 91 | if (!*pmeth) | ||
| 92 | { | ||
| 93 | ENGINE *e = ENGINE_get_default_RAND(); | ||
| 94 | if(e) | ||
| 95 | { | ||
| 96 | *pmeth = ENGINE_get_RAND(e); | ||
| 97 | if(!*pmeth) | ||
| 98 | { | ||
| 99 | ENGINE_finish(e); | ||
| 100 | e = NULL; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | if(e) | ||
| 104 | funct_ref = e; | ||
| 105 | else | ||
| 106 | if(FIPS_mode()) | ||
| 107 | *pmeth=FIPS_rand_method(); | ||
| 108 | else | ||
| 109 | *pmeth = RAND_SSLeay(); | ||
| 110 | } | ||
| 111 | |||
| 112 | if(FIPS_mode() | ||
| 113 | && *pmeth != FIPS_rand_check()) | ||
| 114 | { | ||
| 115 | RANDerr(RAND_F_ENG_RAND_GET_RAND_METHOD,RAND_R_NON_FIPS_METHOD); | ||
| 116 | return 0; | ||
| 117 | } | ||
| 118 | |||
| 119 | return *pmeth; | ||
| 120 | } | ||
| 121 | |||
| 122 | int RAND_set_rand_engine(ENGINE *engine) | ||
| 123 | { | ||
| 124 | const RAND_METHOD *tmp_meth = NULL; | ||
| 125 | if(engine) | ||
| 126 | { | ||
| 127 | if(!ENGINE_init(engine)) | ||
| 128 | return 0; | ||
| 129 | tmp_meth = ENGINE_get_RAND(engine); | ||
| 130 | if(!tmp_meth) | ||
| 131 | { | ||
| 132 | ENGINE_finish(engine); | ||
| 133 | return 0; | ||
| 134 | } | ||
| 135 | } | ||
| 136 | /* This function releases any prior ENGINE so call it first */ | ||
| 137 | RAND_set_rand_method(tmp_meth); | ||
| 138 | funct_ref = engine; | ||
| 139 | return 1; | ||
| 140 | } | ||
| 141 | |||
| 142 | void int_RAND_init_engine_callbacks(void) | ||
| 143 | { | ||
| 144 | static int done = 0; | ||
| 145 | if (done) | ||
| 146 | return; | ||
| 147 | int_RAND_set_callbacks(eng_RAND_set_rand_method, | ||
| 148 | eng_RAND_get_rand_method); | ||
| 149 | done = 1; | ||
| 150 | } | ||
| 151 | |||
| 152 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/evp/dig_eng.c b/src/lib/libcrypto/rand/rand_nw.c index 64cdf9366c..f177ffbe82 100644 --- a/src/lib/libssl/src/crypto/evp/dig_eng.c +++ b/src/lib/libcrypto/rand/rand_nw.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* crypto/evp/digest.c */ | 1 | /* crypto/rand/rand_nw.c */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -56,7 +56,7 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | /* ==================================================================== | 58 | /* ==================================================================== |
| 59 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | 59 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. |
| 60 | * | 60 | * |
| 61 | * Redistribution and use in source and binary forms, with or without | 61 | * Redistribution and use in source and binary forms, with or without |
| 62 | * modification, are permitted provided that the following conditions | 62 | * modification, are permitted provided that the following conditions |
| @@ -109,72 +109,75 @@ | |||
| 109 | * | 109 | * |
| 110 | */ | 110 | */ |
| 111 | 111 | ||
| 112 | #include <stdio.h> | ||
| 113 | #include "cryptlib.h" | 112 | #include "cryptlib.h" |
| 114 | #include <openssl/objects.h> | 113 | #include <openssl/rand.h> |
| 115 | #include <openssl/evp.h> | 114 | #include "rand_lcl.h" |
| 116 | #ifndef OPENSSL_NO_ENGINE | 115 | |
| 117 | #include <openssl/engine.h> | 116 | #if defined (OPENSSL_SYS_NETWARE) |
| 117 | |||
| 118 | #if defined(NETWARE_LIBC) | ||
| 119 | #include <nks/thread.h> | ||
| 120 | #else | ||
| 121 | #include <nwthread.h> | ||
| 118 | #endif | 122 | #endif |
| 119 | #include "evp_locl.h" | ||
| 120 | 123 | ||
| 121 | #ifndef OPENSSL_NO_ENGINE | 124 | extern int GetProcessSwitchCount(void); |
| 125 | #if !defined(NETWARE_LIBC) || (CURRENT_NDK_THRESHOLD < 509220000) | ||
| 126 | extern void *RunningProcess; /* declare here same as found in newer NDKs */ | ||
| 127 | extern unsigned long GetSuperHighResolutionTimer(void); | ||
| 128 | #endif | ||
| 122 | 129 | ||
| 123 | #ifdef OPENSSL_FIPS | 130 | /* the FAQ indicates we need to provide at least 20 bytes (160 bits) of seed |
| 131 | */ | ||
| 132 | int RAND_poll(void) | ||
| 133 | { | ||
| 134 | unsigned long l; | ||
| 135 | unsigned long tsc; | ||
| 136 | int i; | ||
| 124 | 137 | ||
| 125 | static int do_evp_md_engine_full(EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl) | 138 | /* There are several options to gather miscellaneous data |
| 126 | { | 139 | * but for now we will loop checking the time stamp counter (rdtsc) and |
| 127 | if (*ptype) | 140 | * the SuperHighResolutionTimer. Each iteration will collect 8 bytes |
| 128 | { | 141 | * of data but it is treated as only 1 byte of entropy. The call to |
| 129 | /* Ensure an ENGINE left lying around from last time is cleared | 142 | * ThreadSwitchWithDelay() will introduce additional variability into |
| 130 | * (the previous check attempted to avoid this if the same | 143 | * the data returned by rdtsc. |
| 131 | * ENGINE and EVP_MD could be used). */ | 144 | * |
| 132 | if(ctx->engine) | 145 | * Applications can agument the seed material by adding additional |
| 133 | ENGINE_finish(ctx->engine); | 146 | * stuff with RAND_add() and should probably do so. |
| 134 | if(impl) | 147 | */ |
| 135 | { | 148 | l = GetProcessSwitchCount(); |
| 136 | if (!ENGINE_init(impl)) | 149 | RAND_add(&l,sizeof(l),1); |
| 137 | { | 150 | |
| 138 | EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_INITIALIZATION_ERROR); | 151 | /* need to cast the void* to unsigned long here */ |
| 139 | return 0; | 152 | l = (unsigned long)RunningProcess; |
| 140 | } | 153 | RAND_add(&l,sizeof(l),1); |
| 141 | } | ||
| 142 | else | ||
| 143 | /* Ask if an ENGINE is reserved for this job */ | ||
| 144 | impl = ENGINE_get_digest_engine((*ptype)->type); | ||
| 145 | if(impl) | ||
| 146 | { | ||
| 147 | /* There's an ENGINE for this job ... (apparently) */ | ||
| 148 | const EVP_MD *d = ENGINE_get_digest(impl, (*ptype)->type); | ||
| 149 | if(!d) | ||
| 150 | { | ||
| 151 | /* Same comment from evp_enc.c */ | ||
| 152 | EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_INITIALIZATION_ERROR); | ||
| 153 | return 0; | ||
| 154 | } | ||
| 155 | /* We'll use the ENGINE's private digest definition */ | ||
| 156 | *ptype = d; | ||
| 157 | /* Store the ENGINE functional reference so we know | ||
| 158 | * 'type' came from an ENGINE and we need to release | ||
| 159 | * it when done. */ | ||
| 160 | ctx->engine = impl; | ||
| 161 | } | ||
| 162 | else | ||
| 163 | ctx->engine = NULL; | ||
| 164 | } | ||
| 165 | else | ||
| 166 | if(!ctx->digest) | ||
| 167 | { | ||
| 168 | EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_NO_DIGEST_SET); | ||
| 169 | return 0; | ||
| 170 | } | ||
| 171 | return 1; | ||
| 172 | } | ||
| 173 | 154 | ||
| 174 | void int_EVP_MD_init_engine_callbacks(void) | 155 | for( i=2; i<ENTROPY_NEEDED; i++) |
| 175 | { | 156 | { |
| 176 | int_EVP_MD_set_engine_callbacks( | 157 | #ifdef __MWERKS__ |
| 177 | ENGINE_init, ENGINE_finish, do_evp_md_engine_full); | 158 | asm |
| 178 | } | 159 | { |
| 179 | #endif | 160 | rdtsc |
| 161 | mov tsc, eax | ||
| 162 | } | ||
| 163 | #else | ||
| 164 | asm volatile("rdtsc":"=A" (tsc)); | ||
| 180 | #endif | 165 | #endif |
| 166 | |||
| 167 | RAND_add(&tsc, sizeof(tsc), 1); | ||
| 168 | |||
| 169 | l = GetSuperHighResolutionTimer(); | ||
| 170 | RAND_add(&l, sizeof(l), 0); | ||
| 171 | |||
| 172 | # if defined(NETWARE_LIBC) | ||
| 173 | NXThreadYield(); | ||
| 174 | # else /* NETWARE_CLIB */ | ||
| 175 | ThreadSwitchWithDelay(); | ||
| 176 | # endif | ||
| 177 | } | ||
| 178 | |||
| 179 | return 1; | ||
| 180 | } | ||
| 181 | |||
| 182 | #endif | ||
| 183 | |||
diff --git a/src/lib/libcrypto/rc4/asm/rc4-ia64.S b/src/lib/libcrypto/rc4/asm/rc4-ia64.S deleted file mode 100644 index 8210c47d04..0000000000 --- a/src/lib/libcrypto/rc4/asm/rc4-ia64.S +++ /dev/null | |||
| @@ -1,159 +0,0 @@ | |||
| 1 | // ==================================================================== | ||
| 2 | // Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL | ||
| 3 | // project. | ||
| 4 | // | ||
| 5 | // Rights for redistribution and usage in source and binary forms are | ||
| 6 | // granted according to the OpenSSL license. Warranty of any kind is | ||
| 7 | // disclaimed. | ||
| 8 | // ==================================================================== | ||
| 9 | |||
| 10 | .ident "rc4-ia64.S, Version 2.0" | ||
| 11 | .ident "IA-64 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>" | ||
| 12 | |||
| 13 | // What's wrong with compiler generated code? Because of the nature of | ||
| 14 | // C language, compiler doesn't [dare to] reorder load and stores. But | ||
| 15 | // being memory-bound, RC4 should benefit from reorder [on in-order- | ||
| 16 | // execution core such as IA-64]. But what can we reorder? At the very | ||
| 17 | // least we can safely reorder references to key schedule in respect | ||
| 18 | // to input and output streams. Secondly, from the first [close] glance | ||
| 19 | // it appeared that it's possible to pull up some references to | ||
| 20 | // elements of the key schedule itself. Original rationale ["prior | ||
| 21 | // loads are not safe only for "degenerated" key schedule, when some | ||
| 22 | // elements equal to the same value"] was kind of sloppy. I should have | ||
| 23 | // formulated as it really was: if we assume that pulling up reference | ||
| 24 | // to key[x+1] is not safe, then it would mean that key schedule would | ||
| 25 | // "degenerate," which is never the case. The problem is that this | ||
| 26 | // holds true in respect to references to key[x], but not to key[y]. | ||
| 27 | // Legitimate "collisions" do occur within every 256^2 bytes window. | ||
| 28 | // Fortunately there're enough free instruction slots to keep prior | ||
| 29 | // reference to key[x+1], detect "collision" and compensate for it. | ||
| 30 | // All this without sacrificing a single clock cycle:-) Throughput is | ||
| 31 | // ~210MBps on 900MHz CPU, which is is >3x faster than gcc generated | ||
| 32 | // code and +30% - if compared to HP-UX C. Unrolling loop below should | ||
| 33 | // give >30% on top of that... | ||
| 34 | |||
| 35 | .text | ||
| 36 | .explicit | ||
| 37 | |||
| 38 | #if defined(_HPUX_SOURCE) && !defined(_LP64) | ||
| 39 | # define ADDP addp4 | ||
| 40 | #else | ||
| 41 | # define ADDP add | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #ifndef SZ | ||
| 45 | #define SZ 4 // this is set to sizeof(RC4_INT) | ||
| 46 | #endif | ||
| 47 | // SZ==4 seems to be optimal. At least SZ==8 is not any faster, not for | ||
| 48 | // assembler implementation, while SZ==1 code is ~30% slower. | ||
| 49 | #if SZ==1 // RC4_INT is unsigned char | ||
| 50 | # define LDKEY ld1 | ||
| 51 | # define STKEY st1 | ||
| 52 | # define OFF 0 | ||
| 53 | #elif SZ==4 // RC4_INT is unsigned int | ||
| 54 | # define LDKEY ld4 | ||
| 55 | # define STKEY st4 | ||
| 56 | # define OFF 2 | ||
| 57 | #elif SZ==8 // RC4_INT is unsigned long | ||
| 58 | # define LDKEY ld8 | ||
| 59 | # define STKEY st8 | ||
| 60 | # define OFF 3 | ||
| 61 | #endif | ||
| 62 | |||
| 63 | out=r8; // [expanded] output pointer | ||
| 64 | inp=r9; // [expanded] output pointer | ||
| 65 | prsave=r10; | ||
| 66 | key=r28; // [expanded] pointer to RC4_KEY | ||
| 67 | ksch=r29; // (key->data+255)[&~(sizeof(key->data)-1)] | ||
| 68 | xx=r30; | ||
| 69 | yy=r31; | ||
| 70 | |||
| 71 | // void RC4(RC4_KEY *key,size_t len,const void *inp,void *out); | ||
| 72 | .global RC4# | ||
| 73 | .proc RC4# | ||
| 74 | .align 32 | ||
| 75 | .skip 16 | ||
| 76 | RC4: | ||
| 77 | .prologue | ||
| 78 | .save ar.pfs,r2 | ||
| 79 | { .mii; alloc r2=ar.pfs,4,12,0,16 | ||
| 80 | .save pr,prsave | ||
| 81 | mov prsave=pr | ||
| 82 | ADDP key=0,in0 };; | ||
| 83 | { .mib; cmp.eq p6,p0=0,in1 // len==0? | ||
| 84 | .save ar.lc,r3 | ||
| 85 | mov r3=ar.lc | ||
| 86 | (p6) br.ret.spnt.many b0 };; // emergency exit | ||
| 87 | |||
| 88 | .body | ||
| 89 | .rotr dat[4],key_x[4],tx[2],rnd[2],key_y[2],ty[1]; | ||
| 90 | |||
| 91 | { .mib; LDKEY xx=[key],SZ // load key->x | ||
| 92 | add in1=-1,in1 // adjust len for loop counter | ||
| 93 | nop.b 0 } | ||
| 94 | { .mib; ADDP inp=0,in2 | ||
| 95 | ADDP out=0,in3 | ||
| 96 | brp.loop.imp .Ltop,.Lexit-16 };; | ||
| 97 | { .mmi; LDKEY yy=[key] // load key->y | ||
| 98 | add ksch=SZ,key | ||
| 99 | mov ar.lc=in1 } | ||
| 100 | { .mmi; mov key_y[1]=r0 // guarantee inequality | ||
| 101 | // in first iteration | ||
| 102 | add xx=1,xx | ||
| 103 | mov pr.rot=1<<16 };; | ||
| 104 | { .mii; nop.m 0 | ||
| 105 | dep key_x[1]=xx,r0,OFF,8 | ||
| 106 | mov ar.ec=3 };; // note that epilogue counter | ||
| 107 | // is off by 1. I compensate | ||
| 108 | // for this at exit... | ||
| 109 | .Ltop: | ||
| 110 | // The loop is scheduled for 4*(n+2) spin-rate on Itanium 2, which | ||
| 111 | // theoretically gives asymptotic performance of clock frequency | ||
| 112 | // divided by 4 bytes per seconds, or 400MBps on 1.6GHz CPU. This is | ||
| 113 | // for sizeof(RC4_INT)==4. For smaller RC4_INT STKEY inadvertently | ||
| 114 | // splits the last bundle and you end up with 5*n spin-rate:-( | ||
| 115 | // Originally the loop was scheduled for 3*n and relied on key | ||
| 116 | // schedule to be aligned at 256*sizeof(RC4_INT) boundary. But | ||
| 117 | // *(out++)=dat, which maps to st1, had same effect [inadvertent | ||
| 118 | // bundle split] and holded the loop back. Rescheduling for 4*n | ||
| 119 | // made it possible to eliminate dependence on specific alignment | ||
| 120 | // and allow OpenSSH keep "abusing" our API. Reaching for 3*n would | ||
| 121 | // require unrolling, sticking to variable shift instruction for | ||
| 122 | // collecting output [to avoid starvation for integer shifter] and | ||
| 123 | // copying of key schedule to controlled place in stack [so that | ||
| 124 | // deposit instruction can serve as substitute for whole | ||
| 125 | // key->data+((x&255)<<log2(sizeof(key->data[0])))]... | ||
| 126 | { .mmi; (p19) st1 [out]=dat[3],1 // *(out++)=dat | ||
| 127 | (p16) add xx=1,xx // x++ | ||
| 128 | (p18) dep rnd[1]=rnd[1],r0,OFF,8 } // ((tx+ty)&255)<<OFF | ||
| 129 | { .mmi; (p16) add key_x[1]=ksch,key_x[1] // &key[xx&255] | ||
| 130 | (p17) add key_y[1]=ksch,key_y[1] };; // &key[yy&255] | ||
| 131 | { .mmi; (p16) LDKEY tx[0]=[key_x[1]] // tx=key[xx] | ||
| 132 | (p17) LDKEY ty[0]=[key_y[1]] // ty=key[yy] | ||
| 133 | (p16) dep key_x[0]=xx,r0,OFF,8 } // (xx&255)<<OFF | ||
| 134 | { .mmi; (p18) add rnd[1]=ksch,rnd[1] // &key[(tx+ty)&255] | ||
| 135 | (p16) cmp.ne.unc p20,p21=key_x[1],key_y[1] };; | ||
| 136 | { .mmi; (p18) LDKEY rnd[1]=[rnd[1]] // rnd=key[(tx+ty)&255] | ||
| 137 | (p16) ld1 dat[0]=[inp],1 } // dat=*(inp++) | ||
| 138 | .pred.rel "mutex",p20,p21 | ||
| 139 | { .mmi; (p21) add yy=yy,tx[1] // (p16) | ||
| 140 | (p20) add yy=yy,tx[0] // (p16) y+=tx | ||
| 141 | (p21) mov tx[0]=tx[1] };; // (p16) | ||
| 142 | { .mmi; (p17) STKEY [key_y[1]]=tx[1] // key[yy]=tx | ||
| 143 | (p17) STKEY [key_x[2]]=ty[0] // key[xx]=ty | ||
| 144 | (p16) dep key_y[0]=yy,r0,OFF,8 } // &key[yy&255] | ||
| 145 | { .mmb; (p17) add rnd[0]=tx[1],ty[0] // tx+=ty | ||
| 146 | (p18) xor dat[2]=dat[2],rnd[1] // dat^=rnd | ||
| 147 | br.ctop.sptk .Ltop };; | ||
| 148 | .Lexit: | ||
| 149 | { .mib; STKEY [key]=yy,-SZ // save key->y | ||
| 150 | mov pr=prsave,0x1ffff | ||
| 151 | nop.b 0 } | ||
| 152 | { .mib; st1 [out]=dat[3],1 // compensate for truncated | ||
| 153 | // epilogue counter | ||
| 154 | add xx=-1,xx | ||
| 155 | nop.b 0 };; | ||
| 156 | { .mib; STKEY [key]=xx // save key->x | ||
| 157 | mov ar.lc=r3 | ||
| 158 | br.ret.sptk.many b0 };; | ||
| 159 | .endp RC4# | ||
diff --git a/src/lib/libcrypto/rsa/rsa_eng.c b/src/lib/libcrypto/rsa/rsa_eng.c deleted file mode 100644 index 383a7045b2..0000000000 --- a/src/lib/libcrypto/rsa/rsa_eng.c +++ /dev/null | |||
| @@ -1,348 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_lib.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <openssl/crypto.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/lhash.h> | ||
| 63 | #include <openssl/bn.h> | ||
| 64 | #include <openssl/rsa.h> | ||
| 65 | #include <openssl/rand.h> | ||
| 66 | #ifndef OPENSSL_NO_ENGINE | ||
| 67 | #include <openssl/engine.h> | ||
| 68 | #endif | ||
| 69 | |||
| 70 | const char RSA_version[]="RSA" OPENSSL_VERSION_PTEXT; | ||
| 71 | |||
| 72 | static const RSA_METHOD *default_RSA_meth=NULL; | ||
| 73 | |||
| 74 | RSA *RSA_new(void) | ||
| 75 | { | ||
| 76 | RSA *r=RSA_new_method(NULL); | ||
| 77 | |||
| 78 | return r; | ||
| 79 | } | ||
| 80 | |||
| 81 | void RSA_set_default_method(const RSA_METHOD *meth) | ||
| 82 | { | ||
| 83 | #ifdef OPENSSL_FIPS | ||
| 84 | if (FIPS_mode() && !(meth->flags & RSA_FLAG_FIPS_METHOD)) | ||
| 85 | { | ||
| 86 | RSAerr(RSA_F_RSA_SET_DEFAULT_METHOD, RSA_R_NON_FIPS_METHOD); | ||
| 87 | return; | ||
| 88 | } | ||
| 89 | #endif | ||
| 90 | default_RSA_meth = meth; | ||
| 91 | } | ||
| 92 | |||
| 93 | const RSA_METHOD *RSA_get_default_method(void) | ||
| 94 | { | ||
| 95 | if (default_RSA_meth == NULL) | ||
| 96 | { | ||
| 97 | #ifdef RSA_NULL | ||
| 98 | default_RSA_meth=RSA_null_method(); | ||
| 99 | #else | ||
| 100 | #if 0 /* was: #ifdef RSAref */ | ||
| 101 | default_RSA_meth=RSA_PKCS1_RSAref(); | ||
| 102 | #else | ||
| 103 | default_RSA_meth=RSA_PKCS1_SSLeay(); | ||
| 104 | #endif | ||
| 105 | #endif | ||
| 106 | } | ||
| 107 | |||
| 108 | return default_RSA_meth; | ||
| 109 | } | ||
| 110 | |||
| 111 | const RSA_METHOD *RSA_get_method(const RSA *rsa) | ||
| 112 | { | ||
| 113 | return rsa->meth; | ||
| 114 | } | ||
| 115 | |||
| 116 | int RSA_set_method(RSA *rsa, const RSA_METHOD *meth) | ||
| 117 | { | ||
| 118 | /* NB: The caller is specifically setting a method, so it's not up to us | ||
| 119 | * to deal with which ENGINE it comes from. */ | ||
| 120 | const RSA_METHOD *mtmp; | ||
| 121 | #ifdef OPENSSL_FIPS | ||
| 122 | if (FIPS_mode() && !(meth->flags & RSA_FLAG_FIPS_METHOD)) | ||
| 123 | { | ||
| 124 | RSAerr(RSA_F_RSA_SET_METHOD, RSA_R_NON_FIPS_METHOD); | ||
| 125 | return 0; | ||
| 126 | } | ||
| 127 | #endif | ||
| 128 | mtmp = rsa->meth; | ||
| 129 | if (mtmp->finish) mtmp->finish(rsa); | ||
| 130 | #ifndef OPENSSL_NO_ENGINE | ||
| 131 | if (rsa->engine) | ||
| 132 | { | ||
| 133 | ENGINE_finish(rsa->engine); | ||
| 134 | rsa->engine = NULL; | ||
| 135 | } | ||
| 136 | #endif | ||
| 137 | rsa->meth = meth; | ||
| 138 | if (meth->init) meth->init(rsa); | ||
| 139 | return 1; | ||
| 140 | } | ||
| 141 | |||
| 142 | RSA *RSA_new_method(ENGINE *engine) | ||
| 143 | { | ||
| 144 | RSA *ret; | ||
| 145 | |||
| 146 | ret=(RSA *)OPENSSL_malloc(sizeof(RSA)); | ||
| 147 | if (ret == NULL) | ||
| 148 | { | ||
| 149 | RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE); | ||
| 150 | return NULL; | ||
| 151 | } | ||
| 152 | |||
| 153 | ret->meth = RSA_get_default_method(); | ||
| 154 | #ifndef OPENSSL_NO_ENGINE | ||
| 155 | if (engine) | ||
| 156 | { | ||
| 157 | if (!ENGINE_init(engine)) | ||
| 158 | { | ||
| 159 | RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB); | ||
| 160 | OPENSSL_free(ret); | ||
| 161 | return NULL; | ||
| 162 | } | ||
| 163 | ret->engine = engine; | ||
| 164 | } | ||
| 165 | else | ||
| 166 | ret->engine = ENGINE_get_default_RSA(); | ||
| 167 | if(ret->engine) | ||
| 168 | { | ||
| 169 | ret->meth = ENGINE_get_RSA(ret->engine); | ||
| 170 | if(!ret->meth) | ||
| 171 | { | ||
| 172 | RSAerr(RSA_F_RSA_NEW_METHOD, | ||
| 173 | ERR_R_ENGINE_LIB); | ||
| 174 | ENGINE_finish(ret->engine); | ||
| 175 | OPENSSL_free(ret); | ||
| 176 | return NULL; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | #endif | ||
| 180 | #ifdef OPENSSL_FIPS | ||
| 181 | if (FIPS_mode() && !(ret->meth->flags & RSA_FLAG_FIPS_METHOD)) | ||
| 182 | { | ||
| 183 | RSAerr(RSA_F_RSA_NEW_METHOD, RSA_R_NON_FIPS_METHOD); | ||
| 184 | #ifndef OPENSSL_NO_ENGINE | ||
| 185 | if (ret->engine) | ||
| 186 | ENGINE_finish(ret->engine); | ||
| 187 | #endif | ||
| 188 | OPENSSL_free(ret); | ||
| 189 | return NULL; | ||
| 190 | } | ||
| 191 | #endif | ||
| 192 | |||
| 193 | ret->pad=0; | ||
| 194 | ret->version=0; | ||
| 195 | ret->n=NULL; | ||
| 196 | ret->e=NULL; | ||
| 197 | ret->d=NULL; | ||
| 198 | ret->p=NULL; | ||
| 199 | ret->q=NULL; | ||
| 200 | ret->dmp1=NULL; | ||
| 201 | ret->dmq1=NULL; | ||
| 202 | ret->iqmp=NULL; | ||
| 203 | ret->references=1; | ||
| 204 | ret->_method_mod_n=NULL; | ||
| 205 | ret->_method_mod_p=NULL; | ||
| 206 | ret->_method_mod_q=NULL; | ||
| 207 | ret->blinding=NULL; | ||
| 208 | ret->mt_blinding=NULL; | ||
| 209 | ret->bignum_data=NULL; | ||
| 210 | ret->flags=ret->meth->flags; | ||
| 211 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); | ||
| 212 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) | ||
| 213 | { | ||
| 214 | #ifndef OPENSSL_NO_ENGINE | ||
| 215 | if (ret->engine) | ||
| 216 | ENGINE_finish(ret->engine); | ||
| 217 | #endif | ||
| 218 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); | ||
| 219 | OPENSSL_free(ret); | ||
| 220 | ret=NULL; | ||
| 221 | } | ||
| 222 | return(ret); | ||
| 223 | } | ||
| 224 | |||
| 225 | void RSA_free(RSA *r) | ||
| 226 | { | ||
| 227 | int i; | ||
| 228 | |||
| 229 | if (r == NULL) return; | ||
| 230 | |||
| 231 | i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA); | ||
| 232 | #ifdef REF_PRINT | ||
| 233 | REF_PRINT("RSA",r); | ||
| 234 | #endif | ||
| 235 | if (i > 0) return; | ||
| 236 | #ifdef REF_CHECK | ||
| 237 | if (i < 0) | ||
| 238 | { | ||
| 239 | fprintf(stderr,"RSA_free, bad reference count\n"); | ||
| 240 | abort(); | ||
| 241 | } | ||
| 242 | #endif | ||
| 243 | |||
| 244 | if (r->meth->finish) | ||
| 245 | r->meth->finish(r); | ||
| 246 | #ifndef OPENSSL_NO_ENGINE | ||
| 247 | if (r->engine) | ||
| 248 | ENGINE_finish(r->engine); | ||
| 249 | #endif | ||
| 250 | |||
| 251 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data); | ||
| 252 | |||
| 253 | if (r->n != NULL) BN_clear_free(r->n); | ||
| 254 | if (r->e != NULL) BN_clear_free(r->e); | ||
| 255 | if (r->d != NULL) BN_clear_free(r->d); | ||
| 256 | if (r->p != NULL) BN_clear_free(r->p); | ||
| 257 | if (r->q != NULL) BN_clear_free(r->q); | ||
| 258 | if (r->dmp1 != NULL) BN_clear_free(r->dmp1); | ||
| 259 | if (r->dmq1 != NULL) BN_clear_free(r->dmq1); | ||
| 260 | if (r->iqmp != NULL) BN_clear_free(r->iqmp); | ||
| 261 | if (r->blinding != NULL) BN_BLINDING_free(r->blinding); | ||
| 262 | if (r->mt_blinding != NULL) BN_BLINDING_free(r->mt_blinding); | ||
| 263 | if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data); | ||
| 264 | OPENSSL_free(r); | ||
| 265 | } | ||
| 266 | |||
| 267 | int RSA_up_ref(RSA *r) | ||
| 268 | { | ||
| 269 | int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA); | ||
| 270 | #ifdef REF_PRINT | ||
| 271 | REF_PRINT("RSA",r); | ||
| 272 | #endif | ||
| 273 | #ifdef REF_CHECK | ||
| 274 | if (i < 2) | ||
| 275 | { | ||
| 276 | fprintf(stderr, "RSA_up_ref, bad reference count\n"); | ||
| 277 | abort(); | ||
| 278 | } | ||
| 279 | #endif | ||
| 280 | return ((i > 1) ? 1 : 0); | ||
| 281 | } | ||
| 282 | |||
| 283 | int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 284 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
| 285 | { | ||
| 286 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, argl, argp, | ||
| 287 | new_func, dup_func, free_func); | ||
| 288 | } | ||
| 289 | |||
| 290 | int RSA_set_ex_data(RSA *r, int idx, void *arg) | ||
| 291 | { | ||
| 292 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); | ||
| 293 | } | ||
| 294 | |||
| 295 | void *RSA_get_ex_data(const RSA *r, int idx) | ||
| 296 | { | ||
| 297 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); | ||
| 298 | } | ||
| 299 | |||
| 300 | int RSA_flags(const RSA *r) | ||
| 301 | { | ||
| 302 | return((r == NULL)?0:r->meth->flags); | ||
| 303 | } | ||
| 304 | |||
| 305 | int RSA_memory_lock(RSA *r) | ||
| 306 | { | ||
| 307 | int i,j,k,off; | ||
| 308 | char *p; | ||
| 309 | BIGNUM *bn,**t[6],*b; | ||
| 310 | BN_ULONG *ul; | ||
| 311 | |||
| 312 | if (r->d == NULL) return(1); | ||
| 313 | t[0]= &r->d; | ||
| 314 | t[1]= &r->p; | ||
| 315 | t[2]= &r->q; | ||
| 316 | t[3]= &r->dmp1; | ||
| 317 | t[4]= &r->dmq1; | ||
| 318 | t[5]= &r->iqmp; | ||
| 319 | k=sizeof(BIGNUM)*6; | ||
| 320 | off=k/sizeof(BN_ULONG)+1; | ||
| 321 | j=1; | ||
| 322 | for (i=0; i<6; i++) | ||
| 323 | j+= (*t[i])->top; | ||
| 324 | if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL) | ||
| 325 | { | ||
| 326 | RSAerr(RSA_F_RSA_MEMORY_LOCK,ERR_R_MALLOC_FAILURE); | ||
| 327 | return(0); | ||
| 328 | } | ||
| 329 | bn=(BIGNUM *)p; | ||
| 330 | ul=(BN_ULONG *)&(p[off]); | ||
| 331 | for (i=0; i<6; i++) | ||
| 332 | { | ||
| 333 | b= *(t[i]); | ||
| 334 | *(t[i])= &(bn[i]); | ||
| 335 | memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM)); | ||
| 336 | bn[i].flags=BN_FLG_STATIC_DATA; | ||
| 337 | bn[i].d=ul; | ||
| 338 | memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top); | ||
| 339 | ul+=b->top; | ||
| 340 | BN_clear_free(b); | ||
| 341 | } | ||
| 342 | |||
| 343 | /* I should fix this so it can still be done */ | ||
| 344 | r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC); | ||
| 345 | |||
| 346 | r->bignum_data=p; | ||
| 347 | return(1); | ||
| 348 | } | ||
diff --git a/src/lib/libcrypto/rsa/rsa_x931g.c b/src/lib/libcrypto/rsa/rsa_x931g.c deleted file mode 100644 index bf94f8be7a..0000000000 --- a/src/lib/libcrypto/rsa/rsa_x931g.c +++ /dev/null | |||
| @@ -1,255 +0,0 @@ | |||
| 1 | /* crypto/rsa/rsa_gen.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <time.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include <openssl/bn.h> | ||
| 64 | #include <openssl/rsa.h> | ||
| 65 | |||
| 66 | #ifndef OPENSSL_FIPS | ||
| 67 | |||
| 68 | /* X9.31 RSA key derivation and generation */ | ||
| 69 | |||
| 70 | int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BIGNUM *q2, | ||
| 71 | const BIGNUM *Xp1, const BIGNUM *Xp2, const BIGNUM *Xp, | ||
| 72 | const BIGNUM *Xq1, const BIGNUM *Xq2, const BIGNUM *Xq, | ||
| 73 | const BIGNUM *e, BN_GENCB *cb) | ||
| 74 | { | ||
| 75 | BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL; | ||
| 76 | BN_CTX *ctx=NULL,*ctx2=NULL; | ||
| 77 | |||
| 78 | if (!rsa) | ||
| 79 | goto err; | ||
| 80 | |||
| 81 | ctx = BN_CTX_new(); | ||
| 82 | if (!ctx) | ||
| 83 | goto err; | ||
| 84 | BN_CTX_start(ctx); | ||
| 85 | |||
| 86 | r0 = BN_CTX_get(ctx); | ||
| 87 | r1 = BN_CTX_get(ctx); | ||
| 88 | r2 = BN_CTX_get(ctx); | ||
| 89 | r3 = BN_CTX_get(ctx); | ||
| 90 | |||
| 91 | if (r3 == NULL) | ||
| 92 | goto err; | ||
| 93 | if (!rsa->e) | ||
| 94 | { | ||
| 95 | rsa->e = BN_dup(e); | ||
| 96 | if (!rsa->e) | ||
| 97 | goto err; | ||
| 98 | } | ||
| 99 | else | ||
| 100 | e = rsa->e; | ||
| 101 | |||
| 102 | /* If not all parameters present only calculate what we can. | ||
| 103 | * This allows test programs to output selective parameters. | ||
| 104 | */ | ||
| 105 | |||
| 106 | if (Xp && !rsa->p) | ||
| 107 | { | ||
| 108 | rsa->p = BN_new(); | ||
| 109 | if (!rsa->p) | ||
| 110 | goto err; | ||
| 111 | |||
| 112 | if (!BN_X931_derive_prime_ex(rsa->p, p1, p2, | ||
| 113 | Xp, Xp1, Xp2, e, ctx, cb)) | ||
| 114 | goto err; | ||
| 115 | } | ||
| 116 | |||
| 117 | if (Xq && !rsa->q) | ||
| 118 | { | ||
| 119 | rsa->q = BN_new(); | ||
| 120 | if (!rsa->q) | ||
| 121 | goto err; | ||
| 122 | if (!BN_X931_derive_prime_ex(rsa->q, q1, q2, | ||
| 123 | Xq, Xq1, Xq2, e, ctx, cb)) | ||
| 124 | goto err; | ||
| 125 | } | ||
| 126 | |||
| 127 | if (!rsa->p || !rsa->q) | ||
| 128 | { | ||
| 129 | BN_CTX_end(ctx); | ||
| 130 | BN_CTX_free(ctx); | ||
| 131 | return 2; | ||
| 132 | } | ||
| 133 | |||
| 134 | /* Since both primes are set we can now calculate all remaining | ||
| 135 | * components. | ||
| 136 | */ | ||
| 137 | |||
| 138 | /* calculate n */ | ||
| 139 | rsa->n=BN_new(); | ||
| 140 | if (rsa->n == NULL) | ||
| 141 | goto err; | ||
| 142 | if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) | ||
| 143 | goto err; | ||
| 144 | |||
| 145 | /* calculate d */ | ||
| 146 | if (!BN_sub(r1,rsa->p,BN_value_one())) | ||
| 147 | goto err; /* p-1 */ | ||
| 148 | if (!BN_sub(r2,rsa->q,BN_value_one())) | ||
| 149 | goto err; /* q-1 */ | ||
| 150 | if (!BN_mul(r0,r1,r2,ctx)) | ||
| 151 | goto err; /* (p-1)(q-1) */ | ||
| 152 | |||
| 153 | if (!BN_gcd(r3, r1, r2, ctx)) | ||
| 154 | goto err; | ||
| 155 | |||
| 156 | if (!BN_div(r0, NULL, r0, r3, ctx)) | ||
| 157 | goto err; /* LCM((p-1)(q-1)) */ | ||
| 158 | |||
| 159 | ctx2 = BN_CTX_new(); | ||
| 160 | if (!ctx2) | ||
| 161 | goto err; | ||
| 162 | |||
| 163 | rsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2); /* d */ | ||
| 164 | if (rsa->d == NULL) | ||
| 165 | goto err; | ||
| 166 | |||
| 167 | /* calculate d mod (p-1) */ | ||
| 168 | rsa->dmp1=BN_new(); | ||
| 169 | if (rsa->dmp1 == NULL) | ||
| 170 | goto err; | ||
| 171 | if (!BN_mod(rsa->dmp1,rsa->d,r1,ctx)) | ||
| 172 | goto err; | ||
| 173 | |||
| 174 | /* calculate d mod (q-1) */ | ||
| 175 | rsa->dmq1=BN_new(); | ||
| 176 | if (rsa->dmq1 == NULL) | ||
| 177 | goto err; | ||
| 178 | if (!BN_mod(rsa->dmq1,rsa->d,r2,ctx)) | ||
| 179 | goto err; | ||
| 180 | |||
| 181 | /* calculate inverse of q mod p */ | ||
| 182 | rsa->iqmp=BN_mod_inverse(NULL,rsa->q,rsa->p,ctx2); | ||
| 183 | |||
| 184 | err: | ||
| 185 | if (ctx) | ||
| 186 | { | ||
| 187 | BN_CTX_end(ctx); | ||
| 188 | BN_CTX_free(ctx); | ||
| 189 | } | ||
| 190 | if (ctx2) | ||
| 191 | BN_CTX_free(ctx2); | ||
| 192 | /* If this is set all calls successful */ | ||
| 193 | if (rsa && rsa->iqmp != NULL) | ||
| 194 | return 1; | ||
| 195 | |||
| 196 | return 0; | ||
| 197 | |||
| 198 | } | ||
| 199 | |||
| 200 | int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, BN_GENCB *cb) | ||
| 201 | { | ||
| 202 | int ok = 0; | ||
| 203 | BIGNUM *Xp = NULL, *Xq = NULL; | ||
| 204 | BN_CTX *ctx = NULL; | ||
| 205 | |||
| 206 | ctx = BN_CTX_new(); | ||
| 207 | if (!ctx) | ||
| 208 | goto error; | ||
| 209 | |||
| 210 | BN_CTX_start(ctx); | ||
| 211 | Xp = BN_CTX_get(ctx); | ||
| 212 | Xq = BN_CTX_get(ctx); | ||
| 213 | if (!BN_X931_generate_Xpq(Xp, Xq, bits, ctx)) | ||
| 214 | goto error; | ||
| 215 | |||
| 216 | rsa->p = BN_new(); | ||
| 217 | rsa->q = BN_new(); | ||
| 218 | if (!rsa->p || !rsa->q) | ||
| 219 | goto error; | ||
| 220 | |||
| 221 | /* Generate two primes from Xp, Xq */ | ||
| 222 | |||
| 223 | if (!BN_X931_generate_prime_ex(rsa->p, NULL, NULL, NULL, NULL, Xp, | ||
| 224 | e, ctx, cb)) | ||
| 225 | goto error; | ||
| 226 | |||
| 227 | if (!BN_X931_generate_prime_ex(rsa->q, NULL, NULL, NULL, NULL, Xq, | ||
| 228 | e, ctx, cb)) | ||
| 229 | goto error; | ||
| 230 | |||
| 231 | /* Since rsa->p and rsa->q are valid this call will just derive | ||
| 232 | * remaining RSA components. | ||
| 233 | */ | ||
| 234 | |||
| 235 | if (!RSA_X931_derive_ex(rsa, NULL, NULL, NULL, NULL, | ||
| 236 | NULL, NULL, NULL, NULL, NULL, NULL, e, cb)) | ||
| 237 | goto error; | ||
| 238 | |||
| 239 | ok = 1; | ||
| 240 | |||
| 241 | error: | ||
| 242 | if (ctx) | ||
| 243 | { | ||
| 244 | BN_CTX_end(ctx); | ||
| 245 | BN_CTX_free(ctx); | ||
| 246 | } | ||
| 247 | |||
| 248 | if (ok) | ||
| 249 | return 1; | ||
| 250 | |||
| 251 | return 0; | ||
| 252 | |||
| 253 | } | ||
| 254 | |||
| 255 | #endif | ||
diff --git a/src/lib/libcrypto/seed/Makefile b/src/lib/libcrypto/seed/Makefile new file mode 100644 index 0000000000..4bc55e4916 --- /dev/null +++ b/src/lib/libcrypto/seed/Makefile | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | # | ||
| 2 | # crypto/seed/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= seed | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | CPP= $(CC) -E | ||
| 9 | INCLUDES= | ||
| 10 | CFLAG=-g | ||
| 11 | MAKEFILE= Makefile | ||
| 12 | AR= ar r | ||
| 13 | |||
| 14 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 15 | |||
| 16 | GENERAL=Makefile | ||
| 17 | TEST= | ||
| 18 | APPS= | ||
| 19 | |||
| 20 | LIB=$(TOP)/libcrypto.a | ||
| 21 | LIBSRC=seed.c seed_ecb.c seed_cbc.c seed_cfb.c seed_ofb.c | ||
| 22 | LIBOBJ=seed.o seed_ecb.o seed_cbc.o seed_cfb.o seed_ofb.o | ||
| 23 | |||
| 24 | SRC= $(LIBSRC) | ||
| 25 | |||
| 26 | EXHEADER= seed.h | ||
| 27 | HEADER= seed_locl.h $(EXHEADER) | ||
| 28 | |||
| 29 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 30 | |||
| 31 | top: | ||
| 32 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 33 | |||
| 34 | all: lib | ||
| 35 | |||
| 36 | lib: $(LIBOBJ) | ||
| 37 | $(AR) $(LIB) $(LIBOBJ) | ||
| 38 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 39 | @touch lib | ||
| 40 | |||
| 41 | files: | ||
| 42 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 43 | |||
| 44 | links: | ||
| 45 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 46 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 47 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 48 | |||
| 49 | install: | ||
| 50 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 51 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 52 | do \ | ||
| 53 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 54 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 55 | done; | ||
| 56 | |||
| 57 | tags: | ||
| 58 | ctags $(SRC) | ||
| 59 | |||
| 60 | tests: | ||
| 61 | |||
| 62 | lint: | ||
| 63 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 64 | |||
| 65 | depend: | ||
| 66 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 67 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 68 | |||
| 69 | dclean: | ||
| 70 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 71 | mv -f Makefile.new $(MAKEFILE) | ||
| 72 | |||
| 73 | clean: | ||
| 74 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 75 | |||
| 76 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 77 | |||
| 78 | seed.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 79 | seed.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 80 | seed.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 81 | seed.o: ../../include/openssl/seed.h ../../include/openssl/stack.h | ||
| 82 | seed.o: ../../include/openssl/symhacks.h seed.c seed_locl.h | ||
| 83 | seed_cbc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 84 | seed_cbc.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h | ||
| 85 | seed_cbc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 86 | seed_cbc.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h | ||
| 87 | seed_cbc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 88 | seed_cbc.o: seed_cbc.c | ||
| 89 | seed_cfb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 90 | seed_cfb.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h | ||
| 91 | seed_cfb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 92 | seed_cfb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h | ||
| 93 | seed_cfb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 94 | seed_cfb.o: seed_cfb.c | ||
| 95 | seed_ecb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 96 | seed_ecb.o: ../../include/openssl/opensslconf.h | ||
| 97 | seed_ecb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 98 | seed_ecb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h | ||
| 99 | seed_ecb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 100 | seed_ecb.o: seed_ecb.c | ||
| 101 | seed_ofb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 102 | seed_ofb.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h | ||
| 103 | seed_ofb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 104 | seed_ofb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h | ||
| 105 | seed_ofb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 106 | seed_ofb.o: seed_ofb.c | ||
diff --git a/src/lib/libcrypto/seed/seed.c b/src/lib/libcrypto/seed/seed.c new file mode 100644 index 0000000000..2bc384a19f --- /dev/null +++ b/src/lib/libcrypto/seed/seed.c | |||
| @@ -0,0 +1,325 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2007 KISA(Korea Information Security Agency). All rights reserved. | ||
| 3 | * | ||
| 4 | * Redistribution and use in source and binary forms, with or without | ||
| 5 | * modification, are permitted provided that the following conditions | ||
| 6 | * are met: | ||
| 7 | * 1. Redistributions of source code must retain the above copyright | ||
| 8 | * notice, this list of conditions and the following disclaimer. | ||
| 9 | * 2. Neither the name of author nor the names of its contributors may | ||
| 10 | * be used to endorse or promote products derived from this software | ||
| 11 | * without specific prior written permission. | ||
| 12 | * | ||
| 13 | * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 16 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 23 | * SUCH DAMAGE. | ||
| 24 | * | ||
| 25 | */ | ||
| 26 | #ifndef OPENSSL_NO_SEED | ||
| 27 | |||
| 28 | #include <stdio.h> | ||
| 29 | #include <stdlib.h> | ||
| 30 | #include <string.h> | ||
| 31 | #ifdef WIN32 | ||
| 32 | #include <memory.h> | ||
| 33 | #endif | ||
| 34 | |||
| 35 | #include <openssl/seed.h> | ||
| 36 | #include "seed_locl.h" | ||
| 37 | |||
| 38 | static const seed_word SS[4][256] = { { | ||
| 39 | 0x2989a1a8, 0x05858184, 0x16c6d2d4, 0x13c3d3d0, 0x14445054, 0x1d0d111c, 0x2c8ca0ac, 0x25052124, | ||
| 40 | 0x1d4d515c, 0x03434340, 0x18081018, 0x1e0e121c, 0x11415150, 0x3cccf0fc, 0x0acac2c8, 0x23436360, | ||
| 41 | 0x28082028, 0x04444044, 0x20002020, 0x1d8d919c, 0x20c0e0e0, 0x22c2e2e0, 0x08c8c0c8, 0x17071314, | ||
| 42 | 0x2585a1a4, 0x0f8f838c, 0x03030300, 0x3b4b7378, 0x3b8bb3b8, 0x13031310, 0x12c2d2d0, 0x2ecee2ec, | ||
| 43 | 0x30407070, 0x0c8c808c, 0x3f0f333c, 0x2888a0a8, 0x32023230, 0x1dcdd1dc, 0x36c6f2f4, 0x34447074, | ||
| 44 | 0x2ccce0ec, 0x15859194, 0x0b0b0308, 0x17475354, 0x1c4c505c, 0x1b4b5358, 0x3d8db1bc, 0x01010100, | ||
| 45 | 0x24042024, 0x1c0c101c, 0x33437370, 0x18889098, 0x10001010, 0x0cccc0cc, 0x32c2f2f0, 0x19c9d1d8, | ||
| 46 | 0x2c0c202c, 0x27c7e3e4, 0x32427270, 0x03838380, 0x1b8b9398, 0x11c1d1d0, 0x06868284, 0x09c9c1c8, | ||
| 47 | 0x20406060, 0x10405050, 0x2383a3a0, 0x2bcbe3e8, 0x0d0d010c, 0x3686b2b4, 0x1e8e929c, 0x0f4f434c, | ||
| 48 | 0x3787b3b4, 0x1a4a5258, 0x06c6c2c4, 0x38487078, 0x2686a2a4, 0x12021210, 0x2f8fa3ac, 0x15c5d1d4, | ||
| 49 | 0x21416160, 0x03c3c3c0, 0x3484b0b4, 0x01414140, 0x12425250, 0x3d4d717c, 0x0d8d818c, 0x08080008, | ||
| 50 | 0x1f0f131c, 0x19899198, 0x00000000, 0x19091118, 0x04040004, 0x13435350, 0x37c7f3f4, 0x21c1e1e0, | ||
| 51 | 0x3dcdf1fc, 0x36467274, 0x2f0f232c, 0x27072324, 0x3080b0b0, 0x0b8b8388, 0x0e0e020c, 0x2b8ba3a8, | ||
| 52 | 0x2282a2a0, 0x2e4e626c, 0x13839390, 0x0d4d414c, 0x29496168, 0x3c4c707c, 0x09090108, 0x0a0a0208, | ||
| 53 | 0x3f8fb3bc, 0x2fcfe3ec, 0x33c3f3f0, 0x05c5c1c4, 0x07878384, 0x14041014, 0x3ecef2fc, 0x24446064, | ||
| 54 | 0x1eced2dc, 0x2e0e222c, 0x0b4b4348, 0x1a0a1218, 0x06060204, 0x21012120, 0x2b4b6368, 0x26466264, | ||
| 55 | 0x02020200, 0x35c5f1f4, 0x12829290, 0x0a8a8288, 0x0c0c000c, 0x3383b3b0, 0x3e4e727c, 0x10c0d0d0, | ||
| 56 | 0x3a4a7278, 0x07474344, 0x16869294, 0x25c5e1e4, 0x26062224, 0x00808080, 0x2d8da1ac, 0x1fcfd3dc, | ||
| 57 | 0x2181a1a0, 0x30003030, 0x37073334, 0x2e8ea2ac, 0x36063234, 0x15051114, 0x22022220, 0x38083038, | ||
| 58 | 0x34c4f0f4, 0x2787a3a4, 0x05454144, 0x0c4c404c, 0x01818180, 0x29c9e1e8, 0x04848084, 0x17879394, | ||
| 59 | 0x35053134, 0x0bcbc3c8, 0x0ecec2cc, 0x3c0c303c, 0x31417170, 0x11011110, 0x07c7c3c4, 0x09898188, | ||
| 60 | 0x35457174, 0x3bcbf3f8, 0x1acad2d8, 0x38c8f0f8, 0x14849094, 0x19495158, 0x02828280, 0x04c4c0c4, | ||
| 61 | 0x3fcff3fc, 0x09494148, 0x39093138, 0x27476364, 0x00c0c0c0, 0x0fcfc3cc, 0x17c7d3d4, 0x3888b0b8, | ||
| 62 | 0x0f0f030c, 0x0e8e828c, 0x02424240, 0x23032320, 0x11819190, 0x2c4c606c, 0x1bcbd3d8, 0x2484a0a4, | ||
| 63 | 0x34043034, 0x31c1f1f0, 0x08484048, 0x02c2c2c0, 0x2f4f636c, 0x3d0d313c, 0x2d0d212c, 0x00404040, | ||
| 64 | 0x3e8eb2bc, 0x3e0e323c, 0x3c8cb0bc, 0x01c1c1c0, 0x2a8aa2a8, 0x3a8ab2b8, 0x0e4e424c, 0x15455154, | ||
| 65 | 0x3b0b3338, 0x1cccd0dc, 0x28486068, 0x3f4f737c, 0x1c8c909c, 0x18c8d0d8, 0x0a4a4248, 0x16465254, | ||
| 66 | 0x37477374, 0x2080a0a0, 0x2dcde1ec, 0x06464244, 0x3585b1b4, 0x2b0b2328, 0x25456164, 0x3acaf2f8, | ||
| 67 | 0x23c3e3e0, 0x3989b1b8, 0x3181b1b0, 0x1f8f939c, 0x1e4e525c, 0x39c9f1f8, 0x26c6e2e4, 0x3282b2b0, | ||
| 68 | 0x31013130, 0x2acae2e8, 0x2d4d616c, 0x1f4f535c, 0x24c4e0e4, 0x30c0f0f0, 0x0dcdc1cc, 0x08888088, | ||
| 69 | 0x16061214, 0x3a0a3238, 0x18485058, 0x14c4d0d4, 0x22426260, 0x29092128, 0x07070304, 0x33033330, | ||
| 70 | 0x28c8e0e8, 0x1b0b1318, 0x05050104, 0x39497178, 0x10809090, 0x2a4a6268, 0x2a0a2228, 0x1a8a9298 | ||
| 71 | }, { | ||
| 72 | 0x38380830, 0xe828c8e0, 0x2c2d0d21, 0xa42686a2, 0xcc0fcfc3, 0xdc1eced2, 0xb03383b3, 0xb83888b0, | ||
| 73 | 0xac2f8fa3, 0x60204060, 0x54154551, 0xc407c7c3, 0x44044440, 0x6c2f4f63, 0x682b4b63, 0x581b4b53, | ||
| 74 | 0xc003c3c3, 0x60224262, 0x30330333, 0xb43585b1, 0x28290921, 0xa02080a0, 0xe022c2e2, 0xa42787a3, | ||
| 75 | 0xd013c3d3, 0x90118191, 0x10110111, 0x04060602, 0x1c1c0c10, 0xbc3c8cb0, 0x34360632, 0x480b4b43, | ||
| 76 | 0xec2fcfe3, 0x88088880, 0x6c2c4c60, 0xa82888a0, 0x14170713, 0xc404c4c0, 0x14160612, 0xf434c4f0, | ||
| 77 | 0xc002c2c2, 0x44054541, 0xe021c1e1, 0xd416c6d2, 0x3c3f0f33, 0x3c3d0d31, 0x8c0e8e82, 0x98188890, | ||
| 78 | 0x28280820, 0x4c0e4e42, 0xf436c6f2, 0x3c3e0e32, 0xa42585a1, 0xf839c9f1, 0x0c0d0d01, 0xdc1fcfd3, | ||
| 79 | 0xd818c8d0, 0x282b0b23, 0x64264662, 0x783a4a72, 0x24270723, 0x2c2f0f23, 0xf031c1f1, 0x70324272, | ||
| 80 | 0x40024242, 0xd414c4d0, 0x40014141, 0xc000c0c0, 0x70334373, 0x64274763, 0xac2c8ca0, 0x880b8b83, | ||
| 81 | 0xf437c7f3, 0xac2d8da1, 0x80008080, 0x1c1f0f13, 0xc80acac2, 0x2c2c0c20, 0xa82a8aa2, 0x34340430, | ||
| 82 | 0xd012c2d2, 0x080b0b03, 0xec2ecee2, 0xe829c9e1, 0x5c1d4d51, 0x94148490, 0x18180810, 0xf838c8f0, | ||
| 83 | 0x54174753, 0xac2e8ea2, 0x08080800, 0xc405c5c1, 0x10130313, 0xcc0dcdc1, 0x84068682, 0xb83989b1, | ||
| 84 | 0xfc3fcff3, 0x7c3d4d71, 0xc001c1c1, 0x30310131, 0xf435c5f1, 0x880a8a82, 0x682a4a62, 0xb03181b1, | ||
| 85 | 0xd011c1d1, 0x20200020, 0xd417c7d3, 0x00020202, 0x20220222, 0x04040400, 0x68284860, 0x70314171, | ||
| 86 | 0x04070703, 0xd81bcbd3, 0x9c1d8d91, 0x98198991, 0x60214161, 0xbc3e8eb2, 0xe426c6e2, 0x58194951, | ||
| 87 | 0xdc1dcdd1, 0x50114151, 0x90108090, 0xdc1cccd0, 0x981a8a92, 0xa02383a3, 0xa82b8ba3, 0xd010c0d0, | ||
| 88 | 0x80018181, 0x0c0f0f03, 0x44074743, 0x181a0a12, 0xe023c3e3, 0xec2ccce0, 0x8c0d8d81, 0xbc3f8fb3, | ||
| 89 | 0x94168692, 0x783b4b73, 0x5c1c4c50, 0xa02282a2, 0xa02181a1, 0x60234363, 0x20230323, 0x4c0d4d41, | ||
| 90 | 0xc808c8c0, 0x9c1e8e92, 0x9c1c8c90, 0x383a0a32, 0x0c0c0c00, 0x2c2e0e22, 0xb83a8ab2, 0x6c2e4e62, | ||
| 91 | 0x9c1f8f93, 0x581a4a52, 0xf032c2f2, 0x90128292, 0xf033c3f3, 0x48094941, 0x78384870, 0xcc0cccc0, | ||
| 92 | 0x14150511, 0xf83bcbf3, 0x70304070, 0x74354571, 0x7c3f4f73, 0x34350531, 0x10100010, 0x00030303, | ||
| 93 | 0x64244460, 0x6c2d4d61, 0xc406c6c2, 0x74344470, 0xd415c5d1, 0xb43484b0, 0xe82acae2, 0x08090901, | ||
| 94 | 0x74364672, 0x18190911, 0xfc3ecef2, 0x40004040, 0x10120212, 0xe020c0e0, 0xbc3d8db1, 0x04050501, | ||
| 95 | 0xf83acaf2, 0x00010101, 0xf030c0f0, 0x282a0a22, 0x5c1e4e52, 0xa82989a1, 0x54164652, 0x40034343, | ||
| 96 | 0x84058581, 0x14140410, 0x88098981, 0x981b8b93, 0xb03080b0, 0xe425c5e1, 0x48084840, 0x78394971, | ||
| 97 | 0x94178793, 0xfc3cccf0, 0x1c1e0e12, 0x80028282, 0x20210121, 0x8c0c8c80, 0x181b0b13, 0x5c1f4f53, | ||
| 98 | 0x74374773, 0x54144450, 0xb03282b2, 0x1c1d0d11, 0x24250521, 0x4c0f4f43, 0x00000000, 0x44064642, | ||
| 99 | 0xec2dcde1, 0x58184850, 0x50124252, 0xe82bcbe3, 0x7c3e4e72, 0xd81acad2, 0xc809c9c1, 0xfc3dcdf1, | ||
| 100 | 0x30300030, 0x94158591, 0x64254561, 0x3c3c0c30, 0xb43686b2, 0xe424c4e0, 0xb83b8bb3, 0x7c3c4c70, | ||
| 101 | 0x0c0e0e02, 0x50104050, 0x38390931, 0x24260622, 0x30320232, 0x84048480, 0x68294961, 0x90138393, | ||
| 102 | 0x34370733, 0xe427c7e3, 0x24240420, 0xa42484a0, 0xc80bcbc3, 0x50134353, 0x080a0a02, 0x84078783, | ||
| 103 | 0xd819c9d1, 0x4c0c4c40, 0x80038383, 0x8c0f8f83, 0xcc0ecec2, 0x383b0b33, 0x480a4a42, 0xb43787b3 | ||
| 104 | }, { | ||
| 105 | 0xa1a82989, 0x81840585, 0xd2d416c6, 0xd3d013c3, 0x50541444, 0x111c1d0d, 0xa0ac2c8c, 0x21242505, | ||
| 106 | 0x515c1d4d, 0x43400343, 0x10181808, 0x121c1e0e, 0x51501141, 0xf0fc3ccc, 0xc2c80aca, 0x63602343, | ||
| 107 | 0x20282808, 0x40440444, 0x20202000, 0x919c1d8d, 0xe0e020c0, 0xe2e022c2, 0xc0c808c8, 0x13141707, | ||
| 108 | 0xa1a42585, 0x838c0f8f, 0x03000303, 0x73783b4b, 0xb3b83b8b, 0x13101303, 0xd2d012c2, 0xe2ec2ece, | ||
| 109 | 0x70703040, 0x808c0c8c, 0x333c3f0f, 0xa0a82888, 0x32303202, 0xd1dc1dcd, 0xf2f436c6, 0x70743444, | ||
| 110 | 0xe0ec2ccc, 0x91941585, 0x03080b0b, 0x53541747, 0x505c1c4c, 0x53581b4b, 0xb1bc3d8d, 0x01000101, | ||
| 111 | 0x20242404, 0x101c1c0c, 0x73703343, 0x90981888, 0x10101000, 0xc0cc0ccc, 0xf2f032c2, 0xd1d819c9, | ||
| 112 | 0x202c2c0c, 0xe3e427c7, 0x72703242, 0x83800383, 0x93981b8b, 0xd1d011c1, 0x82840686, 0xc1c809c9, | ||
| 113 | 0x60602040, 0x50501040, 0xa3a02383, 0xe3e82bcb, 0x010c0d0d, 0xb2b43686, 0x929c1e8e, 0x434c0f4f, | ||
| 114 | 0xb3b43787, 0x52581a4a, 0xc2c406c6, 0x70783848, 0xa2a42686, 0x12101202, 0xa3ac2f8f, 0xd1d415c5, | ||
| 115 | 0x61602141, 0xc3c003c3, 0xb0b43484, 0x41400141, 0x52501242, 0x717c3d4d, 0x818c0d8d, 0x00080808, | ||
| 116 | 0x131c1f0f, 0x91981989, 0x00000000, 0x11181909, 0x00040404, 0x53501343, 0xf3f437c7, 0xe1e021c1, | ||
| 117 | 0xf1fc3dcd, 0x72743646, 0x232c2f0f, 0x23242707, 0xb0b03080, 0x83880b8b, 0x020c0e0e, 0xa3a82b8b, | ||
| 118 | 0xa2a02282, 0x626c2e4e, 0x93901383, 0x414c0d4d, 0x61682949, 0x707c3c4c, 0x01080909, 0x02080a0a, | ||
| 119 | 0xb3bc3f8f, 0xe3ec2fcf, 0xf3f033c3, 0xc1c405c5, 0x83840787, 0x10141404, 0xf2fc3ece, 0x60642444, | ||
| 120 | 0xd2dc1ece, 0x222c2e0e, 0x43480b4b, 0x12181a0a, 0x02040606, 0x21202101, 0x63682b4b, 0x62642646, | ||
| 121 | 0x02000202, 0xf1f435c5, 0x92901282, 0x82880a8a, 0x000c0c0c, 0xb3b03383, 0x727c3e4e, 0xd0d010c0, | ||
| 122 | 0x72783a4a, 0x43440747, 0x92941686, 0xe1e425c5, 0x22242606, 0x80800080, 0xa1ac2d8d, 0xd3dc1fcf, | ||
| 123 | 0xa1a02181, 0x30303000, 0x33343707, 0xa2ac2e8e, 0x32343606, 0x11141505, 0x22202202, 0x30383808, | ||
| 124 | 0xf0f434c4, 0xa3a42787, 0x41440545, 0x404c0c4c, 0x81800181, 0xe1e829c9, 0x80840484, 0x93941787, | ||
| 125 | 0x31343505, 0xc3c80bcb, 0xc2cc0ece, 0x303c3c0c, 0x71703141, 0x11101101, 0xc3c407c7, 0x81880989, | ||
| 126 | 0x71743545, 0xf3f83bcb, 0xd2d81aca, 0xf0f838c8, 0x90941484, 0x51581949, 0x82800282, 0xc0c404c4, | ||
| 127 | 0xf3fc3fcf, 0x41480949, 0x31383909, 0x63642747, 0xc0c000c0, 0xc3cc0fcf, 0xd3d417c7, 0xb0b83888, | ||
| 128 | 0x030c0f0f, 0x828c0e8e, 0x42400242, 0x23202303, 0x91901181, 0x606c2c4c, 0xd3d81bcb, 0xa0a42484, | ||
| 129 | 0x30343404, 0xf1f031c1, 0x40480848, 0xc2c002c2, 0x636c2f4f, 0x313c3d0d, 0x212c2d0d, 0x40400040, | ||
| 130 | 0xb2bc3e8e, 0x323c3e0e, 0xb0bc3c8c, 0xc1c001c1, 0xa2a82a8a, 0xb2b83a8a, 0x424c0e4e, 0x51541545, | ||
| 131 | 0x33383b0b, 0xd0dc1ccc, 0x60682848, 0x737c3f4f, 0x909c1c8c, 0xd0d818c8, 0x42480a4a, 0x52541646, | ||
| 132 | 0x73743747, 0xa0a02080, 0xe1ec2dcd, 0x42440646, 0xb1b43585, 0x23282b0b, 0x61642545, 0xf2f83aca, | ||
| 133 | 0xe3e023c3, 0xb1b83989, 0xb1b03181, 0x939c1f8f, 0x525c1e4e, 0xf1f839c9, 0xe2e426c6, 0xb2b03282, | ||
| 134 | 0x31303101, 0xe2e82aca, 0x616c2d4d, 0x535c1f4f, 0xe0e424c4, 0xf0f030c0, 0xc1cc0dcd, 0x80880888, | ||
| 135 | 0x12141606, 0x32383a0a, 0x50581848, 0xd0d414c4, 0x62602242, 0x21282909, 0x03040707, 0x33303303, | ||
| 136 | 0xe0e828c8, 0x13181b0b, 0x01040505, 0x71783949, 0x90901080, 0x62682a4a, 0x22282a0a, 0x92981a8a | ||
| 137 | }, { | ||
| 138 | 0x08303838, 0xc8e0e828, 0x0d212c2d, 0x86a2a426, 0xcfc3cc0f, 0xced2dc1e, 0x83b3b033, 0x88b0b838, | ||
| 139 | 0x8fa3ac2f, 0x40606020, 0x45515415, 0xc7c3c407, 0x44404404, 0x4f636c2f, 0x4b63682b, 0x4b53581b, | ||
| 140 | 0xc3c3c003, 0x42626022, 0x03333033, 0x85b1b435, 0x09212829, 0x80a0a020, 0xc2e2e022, 0x87a3a427, | ||
| 141 | 0xc3d3d013, 0x81919011, 0x01111011, 0x06020406, 0x0c101c1c, 0x8cb0bc3c, 0x06323436, 0x4b43480b, | ||
| 142 | 0xcfe3ec2f, 0x88808808, 0x4c606c2c, 0x88a0a828, 0x07131417, 0xc4c0c404, 0x06121416, 0xc4f0f434, | ||
| 143 | 0xc2c2c002, 0x45414405, 0xc1e1e021, 0xc6d2d416, 0x0f333c3f, 0x0d313c3d, 0x8e828c0e, 0x88909818, | ||
| 144 | 0x08202828, 0x4e424c0e, 0xc6f2f436, 0x0e323c3e, 0x85a1a425, 0xc9f1f839, 0x0d010c0d, 0xcfd3dc1f, | ||
| 145 | 0xc8d0d818, 0x0b23282b, 0x46626426, 0x4a72783a, 0x07232427, 0x0f232c2f, 0xc1f1f031, 0x42727032, | ||
| 146 | 0x42424002, 0xc4d0d414, 0x41414001, 0xc0c0c000, 0x43737033, 0x47636427, 0x8ca0ac2c, 0x8b83880b, | ||
| 147 | 0xc7f3f437, 0x8da1ac2d, 0x80808000, 0x0f131c1f, 0xcac2c80a, 0x0c202c2c, 0x8aa2a82a, 0x04303434, | ||
| 148 | 0xc2d2d012, 0x0b03080b, 0xcee2ec2e, 0xc9e1e829, 0x4d515c1d, 0x84909414, 0x08101818, 0xc8f0f838, | ||
| 149 | 0x47535417, 0x8ea2ac2e, 0x08000808, 0xc5c1c405, 0x03131013, 0xcdc1cc0d, 0x86828406, 0x89b1b839, | ||
| 150 | 0xcff3fc3f, 0x4d717c3d, 0xc1c1c001, 0x01313031, 0xc5f1f435, 0x8a82880a, 0x4a62682a, 0x81b1b031, | ||
| 151 | 0xc1d1d011, 0x00202020, 0xc7d3d417, 0x02020002, 0x02222022, 0x04000404, 0x48606828, 0x41717031, | ||
| 152 | 0x07030407, 0xcbd3d81b, 0x8d919c1d, 0x89919819, 0x41616021, 0x8eb2bc3e, 0xc6e2e426, 0x49515819, | ||
| 153 | 0xcdd1dc1d, 0x41515011, 0x80909010, 0xccd0dc1c, 0x8a92981a, 0x83a3a023, 0x8ba3a82b, 0xc0d0d010, | ||
| 154 | 0x81818001, 0x0f030c0f, 0x47434407, 0x0a12181a, 0xc3e3e023, 0xcce0ec2c, 0x8d818c0d, 0x8fb3bc3f, | ||
| 155 | 0x86929416, 0x4b73783b, 0x4c505c1c, 0x82a2a022, 0x81a1a021, 0x43636023, 0x03232023, 0x4d414c0d, | ||
| 156 | 0xc8c0c808, 0x8e929c1e, 0x8c909c1c, 0x0a32383a, 0x0c000c0c, 0x0e222c2e, 0x8ab2b83a, 0x4e626c2e, | ||
| 157 | 0x8f939c1f, 0x4a52581a, 0xc2f2f032, 0x82929012, 0xc3f3f033, 0x49414809, 0x48707838, 0xccc0cc0c, | ||
| 158 | 0x05111415, 0xcbf3f83b, 0x40707030, 0x45717435, 0x4f737c3f, 0x05313435, 0x00101010, 0x03030003, | ||
| 159 | 0x44606424, 0x4d616c2d, 0xc6c2c406, 0x44707434, 0xc5d1d415, 0x84b0b434, 0xcae2e82a, 0x09010809, | ||
| 160 | 0x46727436, 0x09111819, 0xcef2fc3e, 0x40404000, 0x02121012, 0xc0e0e020, 0x8db1bc3d, 0x05010405, | ||
| 161 | 0xcaf2f83a, 0x01010001, 0xc0f0f030, 0x0a22282a, 0x4e525c1e, 0x89a1a829, 0x46525416, 0x43434003, | ||
| 162 | 0x85818405, 0x04101414, 0x89818809, 0x8b93981b, 0x80b0b030, 0xc5e1e425, 0x48404808, 0x49717839, | ||
| 163 | 0x87939417, 0xccf0fc3c, 0x0e121c1e, 0x82828002, 0x01212021, 0x8c808c0c, 0x0b13181b, 0x4f535c1f, | ||
| 164 | 0x47737437, 0x44505414, 0x82b2b032, 0x0d111c1d, 0x05212425, 0x4f434c0f, 0x00000000, 0x46424406, | ||
| 165 | 0xcde1ec2d, 0x48505818, 0x42525012, 0xcbe3e82b, 0x4e727c3e, 0xcad2d81a, 0xc9c1c809, 0xcdf1fc3d, | ||
| 166 | 0x00303030, 0x85919415, 0x45616425, 0x0c303c3c, 0x86b2b436, 0xc4e0e424, 0x8bb3b83b, 0x4c707c3c, | ||
| 167 | 0x0e020c0e, 0x40505010, 0x09313839, 0x06222426, 0x02323032, 0x84808404, 0x49616829, 0x83939013, | ||
| 168 | 0x07333437, 0xc7e3e427, 0x04202424, 0x84a0a424, 0xcbc3c80b, 0x43535013, 0x0a02080a, 0x87838407, | ||
| 169 | 0xc9d1d819, 0x4c404c0c, 0x83838003, 0x8f838c0f, 0xcec2cc0e, 0x0b33383b, 0x4a42480a, 0x87b3b437 | ||
| 170 | } }; | ||
| 171 | |||
| 172 | /* key schedule constants - golden ratio */ | ||
| 173 | #define KC0 0x9e3779b9 | ||
| 174 | #define KC1 0x3c6ef373 | ||
| 175 | #define KC2 0x78dde6e6 | ||
| 176 | #define KC3 0xf1bbcdcc | ||
| 177 | #define KC4 0xe3779b99 | ||
| 178 | #define KC5 0xc6ef3733 | ||
| 179 | #define KC6 0x8dde6e67 | ||
| 180 | #define KC7 0x1bbcdccf | ||
| 181 | #define KC8 0x3779b99e | ||
| 182 | #define KC9 0x6ef3733c | ||
| 183 | #define KC10 0xdde6e678 | ||
| 184 | #define KC11 0xbbcdccf1 | ||
| 185 | #define KC12 0x779b99e3 | ||
| 186 | #define KC13 0xef3733c6 | ||
| 187 | #define KC14 0xde6e678d | ||
| 188 | #define KC15 0xbcdccf1b | ||
| 189 | |||
| 190 | #if defined(OPENSSL_SMALL_FOOTPRINT) | ||
| 191 | static const seed_word KC[] = { | ||
| 192 | KC0, KC1, KC2, KC3, KC4, KC5, KC6, KC7, | ||
| 193 | KC8, KC9, KC10, KC11, KC12, KC13, KC14, KC15 }; | ||
| 194 | #endif | ||
| 195 | |||
| 196 | void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE *ks) | ||
| 197 | { | ||
| 198 | seed_word x1, x2, x3, x4; | ||
| 199 | seed_word t0, t1; | ||
| 200 | |||
| 201 | char2word(rawkey , x1); | ||
| 202 | char2word(rawkey+4 , x2); | ||
| 203 | char2word(rawkey+8 , x3); | ||
| 204 | char2word(rawkey+12, x4); | ||
| 205 | |||
| 206 | t0 = (x1 + x3 - KC0) & 0xffffffff; | ||
| 207 | t1 = (x2 - x4 + KC0) & 0xffffffff; KEYUPDATE_TEMP(t0, t1, &ks->data[0]); | ||
| 208 | KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC1); KEYUPDATE_TEMP(t0, t1, &ks->data[2]); | ||
| 209 | |||
| 210 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | ||
| 211 | KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC2); KEYUPDATE_TEMP(t0, t1, &ks->data[4]); | ||
| 212 | KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC3); KEYUPDATE_TEMP(t0, t1, &ks->data[6]); | ||
| 213 | KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC4); KEYUPDATE_TEMP(t0, t1, &ks->data[8]); | ||
| 214 | KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC5); KEYUPDATE_TEMP(t0, t1, &ks->data[10]); | ||
| 215 | KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC6); KEYUPDATE_TEMP(t0, t1, &ks->data[12]); | ||
| 216 | KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC7); KEYUPDATE_TEMP(t0, t1, &ks->data[14]); | ||
| 217 | KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC8); KEYUPDATE_TEMP(t0, t1, &ks->data[16]); | ||
| 218 | KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC9); KEYUPDATE_TEMP(t0, t1, &ks->data[18]); | ||
| 219 | KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC10); KEYUPDATE_TEMP(t0, t1, &ks->data[20]); | ||
| 220 | KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC11); KEYUPDATE_TEMP(t0, t1, &ks->data[22]); | ||
| 221 | KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC12); KEYUPDATE_TEMP(t0, t1, &ks->data[24]); | ||
| 222 | KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC13); KEYUPDATE_TEMP(t0, t1, &ks->data[26]); | ||
| 223 | KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC14); KEYUPDATE_TEMP(t0, t1, &ks->data[28]); | ||
| 224 | KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC15); KEYUPDATE_TEMP(t0, t1, &ks->data[30]); | ||
| 225 | #else | ||
| 226 | { | ||
| 227 | int i; | ||
| 228 | for (i=2; i<16; i+=2) { | ||
| 229 | KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC[i]); | ||
| 230 | KEYUPDATE_TEMP(t0, t1, &ks->data[i*2]); | ||
| 231 | KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC[i+1]); | ||
| 232 | KEYUPDATE_TEMP(t0, t1, &ks->data[i*2+2]); | ||
| 233 | } | ||
| 234 | } | ||
| 235 | #endif | ||
| 236 | } | ||
| 237 | |||
| 238 | void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_BLOCK_SIZE], const SEED_KEY_SCHEDULE *ks) | ||
| 239 | { | ||
| 240 | seed_word x1, x2, x3, x4; | ||
| 241 | seed_word t0, t1; | ||
| 242 | |||
| 243 | char2word(s, x1); | ||
| 244 | char2word(s+4, x2); | ||
| 245 | char2word(s+8, x3); | ||
| 246 | char2word(s+12, x4); | ||
| 247 | |||
| 248 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | ||
| 249 | E_SEED(t0, t1, x1, x2, x3, x4, 0); | ||
| 250 | E_SEED(t0, t1, x3, x4, x1, x2, 2); | ||
| 251 | E_SEED(t0, t1, x1, x2, x3, x4, 4); | ||
| 252 | E_SEED(t0, t1, x3, x4, x1, x2, 6); | ||
| 253 | E_SEED(t0, t1, x1, x2, x3, x4, 8); | ||
| 254 | E_SEED(t0, t1, x3, x4, x1, x2, 10); | ||
| 255 | E_SEED(t0, t1, x1, x2, x3, x4, 12); | ||
| 256 | E_SEED(t0, t1, x3, x4, x1, x2, 14); | ||
| 257 | E_SEED(t0, t1, x1, x2, x3, x4, 16); | ||
| 258 | E_SEED(t0, t1, x3, x4, x1, x2, 18); | ||
| 259 | E_SEED(t0, t1, x1, x2, x3, x4, 20); | ||
| 260 | E_SEED(t0, t1, x3, x4, x1, x2, 22); | ||
| 261 | E_SEED(t0, t1, x1, x2, x3, x4, 24); | ||
| 262 | E_SEED(t0, t1, x3, x4, x1, x2, 26); | ||
| 263 | E_SEED(t0, t1, x1, x2, x3, x4, 28); | ||
| 264 | E_SEED(t0, t1, x3, x4, x1, x2, 30); | ||
| 265 | #else | ||
| 266 | { | ||
| 267 | int i; | ||
| 268 | for (i=0;i<30;i+=4) { | ||
| 269 | E_SEED(t0,t1,x1,x2,x3,x4,i); | ||
| 270 | E_SEED(t0,t1,x3,x4,x1,x2,i+2); | ||
| 271 | } | ||
| 272 | } | ||
| 273 | #endif | ||
| 274 | |||
| 275 | word2char(x3, d); | ||
| 276 | word2char(x4, d+4); | ||
| 277 | word2char(x1, d+8); | ||
| 278 | word2char(x2, d+12); | ||
| 279 | } | ||
| 280 | |||
| 281 | void SEED_decrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_BLOCK_SIZE], const SEED_KEY_SCHEDULE *ks) | ||
| 282 | { | ||
| 283 | seed_word x1, x2, x3, x4; | ||
| 284 | seed_word t0, t1; | ||
| 285 | |||
| 286 | char2word(s, x1); | ||
| 287 | char2word(s+4, x2); | ||
| 288 | char2word(s+8, x3); | ||
| 289 | char2word(s+12, x4); | ||
| 290 | |||
| 291 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | ||
| 292 | E_SEED(t0, t1, x1, x2, x3, x4, 30); | ||
| 293 | E_SEED(t0, t1, x3, x4, x1, x2, 28); | ||
| 294 | E_SEED(t0, t1, x1, x2, x3, x4, 26); | ||
| 295 | E_SEED(t0, t1, x3, x4, x1, x2, 24); | ||
| 296 | E_SEED(t0, t1, x1, x2, x3, x4, 22); | ||
| 297 | E_SEED(t0, t1, x3, x4, x1, x2, 20); | ||
| 298 | E_SEED(t0, t1, x1, x2, x3, x4, 18); | ||
| 299 | E_SEED(t0, t1, x3, x4, x1, x2, 16); | ||
| 300 | E_SEED(t0, t1, x1, x2, x3, x4, 14); | ||
| 301 | E_SEED(t0, t1, x3, x4, x1, x2, 12); | ||
| 302 | E_SEED(t0, t1, x1, x2, x3, x4, 10); | ||
| 303 | E_SEED(t0, t1, x3, x4, x1, x2, 8); | ||
| 304 | E_SEED(t0, t1, x1, x2, x3, x4, 6); | ||
| 305 | E_SEED(t0, t1, x3, x4, x1, x2, 4); | ||
| 306 | E_SEED(t0, t1, x1, x2, x3, x4, 2); | ||
| 307 | E_SEED(t0, t1, x3, x4, x1, x2, 0); | ||
| 308 | #else | ||
| 309 | { | ||
| 310 | int i; | ||
| 311 | for (i=30; i>0; i-=4) { | ||
| 312 | E_SEED(t0, t1, x1, x2, x3, x4, i); | ||
| 313 | E_SEED(t0, t1, x3, x4, x1, x2, i-2); | ||
| 314 | |||
| 315 | } | ||
| 316 | } | ||
| 317 | #endif | ||
| 318 | |||
| 319 | word2char(x3, d); | ||
| 320 | word2char(x4, d+4); | ||
| 321 | word2char(x1, d+8); | ||
| 322 | word2char(x2, d+12); | ||
| 323 | } | ||
| 324 | |||
| 325 | #endif /* OPENSSL_NO_SEED */ | ||
diff --git a/src/lib/libcrypto/seed/seed.h b/src/lib/libcrypto/seed/seed.h new file mode 100644 index 0000000000..6ffa5f024e --- /dev/null +++ b/src/lib/libcrypto/seed/seed.h | |||
| @@ -0,0 +1,137 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2007 KISA(Korea Information Security Agency). All rights reserved. | ||
| 3 | * | ||
| 4 | * Redistribution and use in source and binary forms, with or without | ||
| 5 | * modification, are permitted provided that the following conditions | ||
| 6 | * are met: | ||
| 7 | * 1. Redistributions of source code must retain the above copyright | ||
| 8 | * notice, this list of conditions and the following disclaimer. | ||
| 9 | * 2. Neither the name of author nor the names of its contributors may | ||
| 10 | * be used to endorse or promote products derived from this software | ||
| 11 | * without specific prior written permission. | ||
| 12 | * | ||
| 13 | * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 16 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 23 | * SUCH DAMAGE. | ||
| 24 | * | ||
| 25 | */ | ||
| 26 | /* ==================================================================== | ||
| 27 | * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. | ||
| 28 | * | ||
| 29 | * Redistribution and use in source and binary forms, with or without | ||
| 30 | * modification, are permitted provided that the following conditions | ||
| 31 | * are met: | ||
| 32 | * | ||
| 33 | * 1. Redistributions of source code must retain the above copyright | ||
| 34 | * notice, this list of conditions and the following disclaimer. | ||
| 35 | * | ||
| 36 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 37 | * notice, this list of conditions and the following disclaimer in | ||
| 38 | * the documentation and/or other materials provided with the | ||
| 39 | * distribution. | ||
| 40 | * | ||
| 41 | * 3. All advertising materials mentioning features or use of this | ||
| 42 | * software must display the following acknowledgment: | ||
| 43 | * "This product includes software developed by the OpenSSL Project | ||
| 44 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 45 | * | ||
| 46 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 47 | * endorse or promote products derived from this software without | ||
| 48 | * prior written permission. For written permission, please contact | ||
| 49 | * openssl-core@openssl.org. | ||
| 50 | * | ||
| 51 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 52 | * nor may "OpenSSL" appear in their names without prior written | ||
| 53 | * permission of the OpenSSL Project. | ||
| 54 | * | ||
| 55 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 56 | * acknowledgment: | ||
| 57 | * "This product includes software developed by the OpenSSL Project | ||
| 58 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 59 | * | ||
| 60 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 61 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 62 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 63 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 64 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 65 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 66 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 67 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 68 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 69 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 70 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 71 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 72 | * ==================================================================== | ||
| 73 | * | ||
| 74 | * This product includes cryptographic software written by Eric Young | ||
| 75 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 76 | * Hudson (tjh@cryptsoft.com). | ||
| 77 | * | ||
| 78 | */ | ||
| 79 | |||
| 80 | |||
| 81 | #ifndef HEADER_SEED_H | ||
| 82 | #define HEADER_SEED_H | ||
| 83 | |||
| 84 | #include <openssl/opensslconf.h> | ||
| 85 | #include <openssl/e_os2.h> | ||
| 86 | #include <openssl/crypto.h> | ||
| 87 | |||
| 88 | #ifdef OPENSSL_NO_SEED | ||
| 89 | #error SEED is disabled. | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #ifdef AES_LONG /* look whether we need 'long' to get 32 bits */ | ||
| 93 | # ifndef SEED_LONG | ||
| 94 | # define SEED_LONG 1 | ||
| 95 | # endif | ||
| 96 | #endif | ||
| 97 | |||
| 98 | #if !defined(NO_SYS_TYPES_H) | ||
| 99 | # include <sys/types.h> | ||
| 100 | #endif | ||
| 101 | |||
| 102 | #define SEED_BLOCK_SIZE 16 | ||
| 103 | #define SEED_KEY_LENGTH 16 | ||
| 104 | |||
| 105 | |||
| 106 | #ifdef __cplusplus | ||
| 107 | extern "C" { | ||
| 108 | #endif | ||
| 109 | |||
| 110 | |||
| 111 | typedef struct seed_key_st { | ||
| 112 | #ifdef SEED_LONG | ||
| 113 | unsigned long data[32]; | ||
| 114 | #else | ||
| 115 | unsigned int data[32]; | ||
| 116 | #endif | ||
| 117 | } SEED_KEY_SCHEDULE; | ||
| 118 | |||
| 119 | |||
| 120 | void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE *ks); | ||
| 121 | |||
| 122 | void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_BLOCK_SIZE], const SEED_KEY_SCHEDULE *ks); | ||
| 123 | void SEED_decrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_BLOCK_SIZE], const SEED_KEY_SCHEDULE *ks); | ||
| 124 | |||
| 125 | void SEED_ecb_encrypt(const unsigned char *in, unsigned char *out, const SEED_KEY_SCHEDULE *ks, int enc); | ||
| 126 | void SEED_cbc_encrypt(const unsigned char *in, unsigned char *out, | ||
| 127 | size_t len, const SEED_KEY_SCHEDULE *ks, unsigned char ivec[SEED_BLOCK_SIZE], int enc); | ||
| 128 | void SEED_cfb128_encrypt(const unsigned char *in, unsigned char *out, | ||
| 129 | size_t len, const SEED_KEY_SCHEDULE *ks, unsigned char ivec[SEED_BLOCK_SIZE], int *num, int enc); | ||
| 130 | void SEED_ofb128_encrypt(const unsigned char *in, unsigned char *out, | ||
| 131 | size_t len, const SEED_KEY_SCHEDULE *ks, unsigned char ivec[SEED_BLOCK_SIZE], int *num); | ||
| 132 | |||
| 133 | #ifdef __cplusplus | ||
| 134 | } | ||
| 135 | #endif | ||
| 136 | |||
| 137 | #endif /* HEADER_SEED_H */ | ||
diff --git a/src/lib/libcrypto/seed/seed_cbc.c b/src/lib/libcrypto/seed/seed_cbc.c new file mode 100644 index 0000000000..6c3f9b527a --- /dev/null +++ b/src/lib/libcrypto/seed/seed_cbc.c | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | /* crypto/seed/seed_cbc.c -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | */ | ||
| 51 | |||
| 52 | #include <openssl/seed.h> | ||
| 53 | #include <openssl/modes.h> | ||
| 54 | |||
| 55 | void SEED_cbc_encrypt(const unsigned char *in, unsigned char *out, | ||
| 56 | size_t len, const SEED_KEY_SCHEDULE *ks, | ||
| 57 | unsigned char ivec[SEED_BLOCK_SIZE], int enc) | ||
| 58 | { | ||
| 59 | if (enc) | ||
| 60 | CRYPTO_cbc128_encrypt(in,out,len,ks,ivec,(block128_f)SEED_encrypt); | ||
| 61 | else | ||
| 62 | CRYPTO_cbc128_decrypt(in,out,len,ks,ivec,(block128_f)SEED_decrypt); | ||
| 63 | } | ||
diff --git a/src/lib/libcrypto/seed/seed_cfb.c b/src/lib/libcrypto/seed/seed_cfb.c new file mode 100644 index 0000000000..694597dd06 --- /dev/null +++ b/src/lib/libcrypto/seed/seed_cfb.c | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | /* crypto/seed/seed_cfb.c -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | */ | ||
| 51 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 52 | * All rights reserved. | ||
| 53 | * | ||
| 54 | * This package is an SSL implementation written | ||
| 55 | * by Eric Young (eay@cryptsoft.com). | ||
| 56 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 57 | * | ||
| 58 | * This library is free for commercial and non-commercial use as long as | ||
| 59 | * the following conditions are aheared to. The following conditions | ||
| 60 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 61 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 62 | * included with this distribution is covered by the same copyright terms | ||
| 63 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 64 | * | ||
| 65 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 66 | * the code are not to be removed. | ||
| 67 | * If this package is used in a product, Eric Young should be given attribution | ||
| 68 | * as the author of the parts of the library used. | ||
| 69 | * This can be in the form of a textual message at program startup or | ||
| 70 | * in documentation (online or textual) provided with the package. | ||
| 71 | * | ||
| 72 | * Redistribution and use in source and binary forms, with or without | ||
| 73 | * modification, are permitted provided that the following conditions | ||
| 74 | * are met: | ||
| 75 | * 1. Redistributions of source code must retain the copyright | ||
| 76 | * notice, this list of conditions and the following disclaimer. | ||
| 77 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 78 | * notice, this list of conditions and the following disclaimer in the | ||
| 79 | * documentation and/or other materials provided with the distribution. | ||
| 80 | * 3. All advertising materials mentioning features or use of this software | ||
| 81 | * must display the following acknowledgement: | ||
| 82 | * "This product includes cryptographic software written by | ||
| 83 | * Eric Young (eay@cryptsoft.com)" | ||
| 84 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 85 | * being used are not cryptographic related :-). | ||
| 86 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 87 | * the apps directory (application code) you must include an acknowledgement: | ||
| 88 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 89 | * | ||
| 90 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 91 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 92 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 93 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 94 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 95 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 96 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 97 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 98 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 99 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 100 | * SUCH DAMAGE. | ||
| 101 | * | ||
| 102 | * The licence and distribution terms for any publically available version or | ||
| 103 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 104 | * copied and put under another distribution licence | ||
| 105 | * [including the GNU Public Licence.] | ||
| 106 | */ | ||
| 107 | |||
| 108 | #include <openssl/seed.h> | ||
| 109 | #include <openssl/modes.h> | ||
| 110 | |||
| 111 | void SEED_cfb128_encrypt(const unsigned char *in, unsigned char *out, | ||
| 112 | size_t len, const SEED_KEY_SCHEDULE *ks, | ||
| 113 | unsigned char ivec[SEED_BLOCK_SIZE], int *num, int enc) | ||
| 114 | { | ||
| 115 | CRYPTO_cfb128_encrypt(in,out,len,ks,ivec,num,enc,(block128_f)SEED_encrypt); | ||
| 116 | } | ||
diff --git a/src/lib/libssl/src/fips/fips_locl.h b/src/lib/libcrypto/seed/seed_ecb.c index 03fed36e3c..e63f5ae14e 100644 --- a/src/lib/libssl/src/fips/fips_locl.h +++ b/src/lib/libcrypto/seed/seed_ecb.c | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | /* crypto/seed/seed_ecb.c -*- mode:C; c-file-style: "eay" -*- */ | ||
| 1 | /* ==================================================================== | 2 | /* ==================================================================== |
| 2 | * Copyright (c) 2003 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2007 The OpenSSL Project. All rights reserved. |
| 3 | * | 4 | * |
| 4 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| @@ -44,30 +45,16 @@ | |||
| 44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 46 | * OF THE POSSIBILITY OF SUCH DAMAGE. | 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 48 | * ==================================================================== | ||
| 47 | * | 49 | * |
| 48 | */ | 50 | */ |
| 49 | 51 | ||
| 50 | #ifdef OPENSSL_FIPS | 52 | #include <openssl/seed.h> |
| 51 | 53 | ||
| 52 | #ifdef __cplusplus | 54 | void SEED_ecb_encrypt(const unsigned char *in, unsigned char *out, const SEED_KEY_SCHEDULE *ks, int enc) |
| 53 | extern "C" { | 55 | { |
| 54 | #endif | 56 | if (enc) |
| 55 | 57 | SEED_encrypt(in, out, ks); | |
| 56 | void fips_w_lock(void); | 58 | else |
| 57 | void fips_w_unlock(void); | 59 | SEED_decrypt(in, out, ks); |
| 58 | void fips_r_lock(void); | 60 | } |
| 59 | void fips_r_unlock(void); | ||
| 60 | int fips_is_started(void); | ||
| 61 | void fips_set_started(void); | ||
| 62 | int fips_is_owning_thread(void); | ||
| 63 | int fips_set_owning_thread(void); | ||
| 64 | void fips_set_selftest_fail(void); | ||
| 65 | int fips_clear_owning_thread(void); | ||
| 66 | unsigned char *fips_signature_witness(void); | ||
| 67 | |||
| 68 | #define FIPS_MAX_CIPHER_TEST_SIZE 16 | ||
| 69 | |||
| 70 | #ifdef __cplusplus | ||
| 71 | } | ||
| 72 | #endif | ||
| 73 | #endif | ||
diff --git a/src/lib/libcrypto/seed/seed_locl.h b/src/lib/libcrypto/seed/seed_locl.h new file mode 100644 index 0000000000..fd456b6422 --- /dev/null +++ b/src/lib/libcrypto/seed/seed_locl.h | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2007 KISA(Korea Information Security Agency). All rights reserved. | ||
| 3 | * | ||
| 4 | * Redistribution and use in source and binary forms, with or without | ||
| 5 | * modification, are permitted provided that the following conditions | ||
| 6 | * are met: | ||
| 7 | * 1. Redistributions of source code must retain the above copyright | ||
| 8 | * notice, this list of conditions and the following disclaimer. | ||
| 9 | * 2. Neither the name of author nor the names of its contributors may | ||
| 10 | * be used to endorse or promote products derived from this software | ||
| 11 | * without specific prior written permission. | ||
| 12 | * | ||
| 13 | * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 16 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 23 | * SUCH DAMAGE. | ||
| 24 | * | ||
| 25 | */ | ||
| 26 | #ifndef HEADER_SEED_LOCL_H | ||
| 27 | #define HEADER_SEED_LOCL_H | ||
| 28 | |||
| 29 | #include "openssl/e_os2.h" | ||
| 30 | #include <openssl/seed.h> | ||
| 31 | |||
| 32 | |||
| 33 | #ifdef SEED_LONG /* need 32-bit type */ | ||
| 34 | typedef unsigned long seed_word; | ||
| 35 | #else | ||
| 36 | typedef unsigned int seed_word; | ||
| 37 | #endif | ||
| 38 | |||
| 39 | |||
| 40 | #ifdef __cplusplus | ||
| 41 | extern "C" { | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #define G_FUNC(v) \ | ||
| 45 | SS[0][(unsigned char) (v) & 0xff] ^ SS[1][(unsigned char) ((v)>>8) & 0xff] ^ \ | ||
| 46 | SS[2][(unsigned char)((v)>>16) & 0xff] ^ SS[3][(unsigned char)((v)>>24) & 0xff] | ||
| 47 | |||
| 48 | #define char2word(c, i) \ | ||
| 49 | (i) = ((((seed_word)(c)[0]) << 24) | (((seed_word)(c)[1]) << 16) | (((seed_word)(c)[2]) << 8) | ((seed_word)(c)[3])) | ||
| 50 | |||
| 51 | #define word2char(l, c) \ | ||
| 52 | *((c)+0) = (unsigned char)((l)>>24) & 0xff; \ | ||
| 53 | *((c)+1) = (unsigned char)((l)>>16) & 0xff; \ | ||
| 54 | *((c)+2) = (unsigned char)((l)>> 8) & 0xff; \ | ||
| 55 | *((c)+3) = (unsigned char)((l)) & 0xff | ||
| 56 | |||
| 57 | #define KEYSCHEDULE_UPDATE0(T0, T1, X1, X2, X3, X4, KC) \ | ||
| 58 | (T0) = (X3); \ | ||
| 59 | (X3) = (((X3)<<8) ^ ((X4)>>24)) & 0xffffffff; \ | ||
| 60 | (X4) = (((X4)<<8) ^ ((T0)>>24)) & 0xffffffff; \ | ||
| 61 | (T0) = ((X1) + (X3) - (KC)) & 0xffffffff; \ | ||
| 62 | (T1) = ((X2) + (KC) - (X4)) & 0xffffffff | ||
| 63 | |||
| 64 | #define KEYSCHEDULE_UPDATE1(T0, T1, X1, X2, X3, X4, KC) \ | ||
| 65 | (T0) = (X1); \ | ||
| 66 | (X1) = (((X1)>>8) ^ ((X2)<<24)) & 0xffffffff; \ | ||
| 67 | (X2) = (((X2)>>8) ^ ((T0)<<24)) & 0xffffffff; \ | ||
| 68 | (T0) = ((X1) + (X3) - (KC)) & 0xffffffff; \ | ||
| 69 | (T1) = ((X2) + (KC) - (X4)) & 0xffffffff | ||
| 70 | |||
| 71 | #define KEYUPDATE_TEMP(T0, T1, K) \ | ||
| 72 | (K)[0] = G_FUNC((T0)); \ | ||
| 73 | (K)[1] = G_FUNC((T1)) | ||
| 74 | |||
| 75 | #define XOR_SEEDBLOCK(DST, SRC) \ | ||
| 76 | ((DST))[0] ^= ((SRC))[0]; \ | ||
| 77 | ((DST))[1] ^= ((SRC))[1]; \ | ||
| 78 | ((DST))[2] ^= ((SRC))[2]; \ | ||
| 79 | ((DST))[3] ^= ((SRC))[3] | ||
| 80 | |||
| 81 | #define MOV_SEEDBLOCK(DST, SRC) \ | ||
| 82 | ((DST))[0] = ((SRC))[0]; \ | ||
| 83 | ((DST))[1] = ((SRC))[1]; \ | ||
| 84 | ((DST))[2] = ((SRC))[2]; \ | ||
| 85 | ((DST))[3] = ((SRC))[3] | ||
| 86 | |||
| 87 | # define CHAR2WORD(C, I) \ | ||
| 88 | char2word((C), (I)[0]); \ | ||
| 89 | char2word((C+4), (I)[1]); \ | ||
| 90 | char2word((C+8), (I)[2]); \ | ||
| 91 | char2word((C+12), (I)[3]) | ||
| 92 | |||
| 93 | # define WORD2CHAR(I, C) \ | ||
| 94 | word2char((I)[0], (C)); \ | ||
| 95 | word2char((I)[1], (C+4)); \ | ||
| 96 | word2char((I)[2], (C+8)); \ | ||
| 97 | word2char((I)[3], (C+12)) | ||
| 98 | |||
| 99 | # define E_SEED(T0, T1, X1, X2, X3, X4, rbase) \ | ||
| 100 | (T0) = (X3) ^ (ks->data)[(rbase)]; \ | ||
| 101 | (T1) = (X4) ^ (ks->data)[(rbase)+1]; \ | ||
| 102 | (T1) ^= (T0); \ | ||
| 103 | (T1) = G_FUNC((T1)); \ | ||
| 104 | (T0) = ((T0) + (T1)) & 0xffffffff; \ | ||
| 105 | (T0) = G_FUNC((T0)); \ | ||
| 106 | (T1) = ((T1) + (T0)) & 0xffffffff; \ | ||
| 107 | (T1) = G_FUNC((T1)); \ | ||
| 108 | (T0) = ((T0) + (T1)) & 0xffffffff; \ | ||
| 109 | (X1) ^= (T0); \ | ||
| 110 | (X2) ^= (T1) | ||
| 111 | |||
| 112 | #ifdef __cplusplus | ||
| 113 | } | ||
| 114 | #endif | ||
| 115 | |||
| 116 | #endif /* HEADER_SEED_LOCL_H */ | ||
diff --git a/src/lib/libssl/src/fips/dh/fips_dh_check.c b/src/lib/libcrypto/seed/seed_ofb.c index 7333f7c80f..3c8ba33bb9 100644 --- a/src/lib/libssl/src/fips/dh/fips_dh_check.c +++ b/src/lib/libcrypto/seed/seed_ofb.c | |||
| @@ -1,4 +1,53 @@ | |||
| 1 | /* crypto/dh/dh_check.c */ | 1 | /* crypto/seed/seed_ofb.c -*- mode:C; c-file-style: "eay" -*- */ |
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 51 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 52 | * All rights reserved. |
| 4 | * | 53 | * |
| @@ -56,92 +105,12 @@ | |||
| 56 | * [including the GNU Public Licence.] | 105 | * [including the GNU Public Licence.] |
| 57 | */ | 106 | */ |
| 58 | 107 | ||
| 59 | #include <stdio.h> | 108 | #include <openssl/seed.h> |
| 60 | #include <openssl/bn.h> | 109 | #include <openssl/modes.h> |
| 61 | #include <openssl/dh.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include <openssl/fips.h> | ||
| 64 | |||
| 65 | /* Check that p is a safe prime and | ||
| 66 | * if g is 2, 3 or 5, check that is is a suitable generator | ||
| 67 | * where | ||
| 68 | * for 2, p mod 24 == 11 | ||
| 69 | * for 3, p mod 12 == 5 | ||
| 70 | * for 5, p mod 10 == 3 or 7 | ||
| 71 | * should hold. | ||
| 72 | */ | ||
| 73 | |||
| 74 | #ifdef OPENSSL_FIPS | ||
| 75 | 110 | ||
| 76 | int DH_check(const DH *dh, int *ret) | 111 | void SEED_ofb128_encrypt(const unsigned char *in, unsigned char *out, |
| 112 | size_t len, const SEED_KEY_SCHEDULE *ks, | ||
| 113 | unsigned char ivec[SEED_BLOCK_SIZE], int *num) | ||
| 77 | { | 114 | { |
| 78 | int ok=0; | 115 | CRYPTO_ofb128_encrypt(in,out,len,ks,ivec,num,(block128_f)SEED_encrypt); |
| 79 | BN_CTX *ctx=NULL; | ||
| 80 | BN_ULONG l; | ||
| 81 | BIGNUM *q=NULL; | ||
| 82 | |||
| 83 | *ret=0; | ||
| 84 | ctx=BN_CTX_new(); | ||
| 85 | if (ctx == NULL) goto err; | ||
| 86 | q=BN_new(); | ||
| 87 | if (q == NULL) goto err; | ||
| 88 | |||
| 89 | if (BN_is_word(dh->g,DH_GENERATOR_2)) | ||
| 90 | { | ||
| 91 | l=BN_mod_word(dh->p,24); | ||
| 92 | if (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR; | ||
| 93 | } | ||
| 94 | #if 0 | ||
| 95 | else if (BN_is_word(dh->g,DH_GENERATOR_3)) | ||
| 96 | { | ||
| 97 | l=BN_mod_word(dh->p,12); | ||
| 98 | if (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR; | ||
| 99 | } | ||
| 100 | #endif | ||
| 101 | else if (BN_is_word(dh->g,DH_GENERATOR_5)) | ||
| 102 | { | ||
| 103 | l=BN_mod_word(dh->p,10); | ||
| 104 | if ((l != 3) && (l != 7)) | ||
| 105 | *ret|=DH_NOT_SUITABLE_GENERATOR; | ||
| 106 | } | ||
| 107 | else | ||
| 108 | *ret|=DH_UNABLE_TO_CHECK_GENERATOR; | ||
| 109 | |||
| 110 | if (!BN_is_prime_ex(dh->p,BN_prime_checks,ctx,NULL)) | ||
| 111 | *ret|=DH_CHECK_P_NOT_PRIME; | ||
| 112 | else | ||
| 113 | { | ||
| 114 | if (!BN_rshift1(q,dh->p)) goto err; | ||
| 115 | if (!BN_is_prime_ex(q,BN_prime_checks,ctx,NULL)) | ||
| 116 | *ret|=DH_CHECK_P_NOT_SAFE_PRIME; | ||
| 117 | } | ||
| 118 | ok=1; | ||
| 119 | err: | ||
| 120 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 121 | if (q != NULL) BN_free(q); | ||
| 122 | return(ok); | ||
| 123 | } | 116 | } |
| 124 | |||
| 125 | int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret) | ||
| 126 | { | ||
| 127 | int ok=0; | ||
| 128 | BIGNUM *q=NULL; | ||
| 129 | |||
| 130 | *ret=0; | ||
| 131 | q=BN_new(); | ||
| 132 | if (q == NULL) goto err; | ||
| 133 | BN_set_word(q,1); | ||
| 134 | if (BN_cmp(pub_key,q) <= 0) | ||
| 135 | *ret|=DH_CHECK_PUBKEY_TOO_SMALL; | ||
| 136 | BN_copy(q,dh->p); | ||
| 137 | BN_sub_word(q,1); | ||
| 138 | if (BN_cmp(pub_key,q) >= 0) | ||
| 139 | *ret|=DH_CHECK_PUBKEY_TOO_LARGE; | ||
| 140 | |||
| 141 | ok = 1; | ||
| 142 | err: | ||
| 143 | if (q != NULL) BN_free(q); | ||
| 144 | return(ok); | ||
| 145 | } | ||
| 146 | |||
| 147 | #endif | ||
diff --git a/src/lib/libcrypto/sha/asm/sha512-sse2.pl b/src/lib/libcrypto/sha/asm/sha512-sse2.pl deleted file mode 100644 index 10902bf673..0000000000 --- a/src/lib/libcrypto/sha/asm/sha512-sse2.pl +++ /dev/null | |||
| @@ -1,404 +0,0 @@ | |||
| 1 | #!/usr/bin/env perl | ||
| 2 | # | ||
| 3 | # ==================================================================== | ||
| 4 | # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL | ||
| 5 | # project. Rights for redistribution and usage in source and binary | ||
| 6 | # forms are granted according to the OpenSSL license. | ||
| 7 | # ==================================================================== | ||
| 8 | # | ||
| 9 | # SHA512_Transform_SSE2. | ||
| 10 | # | ||
| 11 | # As the name suggests, this is an IA-32 SSE2 implementation of | ||
| 12 | # SHA512_Transform. Motivating factor for the undertaken effort was that | ||
| 13 | # SHA512 was observed to *consistently* perform *significantly* poorer | ||
| 14 | # than SHA256 [2x and slower is common] on 32-bit platforms. On 64-bit | ||
| 15 | # platforms on the other hand SHA512 tend to outperform SHA256 [~50% | ||
| 16 | # seem to be common improvement factor]. All this is perfectly natural, | ||
| 17 | # as SHA512 is a 64-bit algorithm. But isn't IA-32 SSE2 essentially | ||
| 18 | # a 64-bit instruction set? Is it rich enough to implement SHA512? | ||
| 19 | # If answer was "no," then you wouldn't have been reading this... | ||
| 20 | # | ||
| 21 | # Throughput performance in MBps (larger is better): | ||
| 22 | # | ||
| 23 | # 2.4GHz P4 1.4GHz AMD32 1.4GHz AMD64(*) | ||
| 24 | # SHA256/gcc(*) 54 43 59 | ||
| 25 | # SHA512/gcc 17 23 92 | ||
| 26 | # SHA512/sse2 61(**) 57(**) | ||
| 27 | # SHA512/icc 26 28 | ||
| 28 | # SHA256/icc(*) 65 54 | ||
| 29 | # | ||
| 30 | # (*) AMD64 and SHA256 numbers are presented mostly for amusement or | ||
| 31 | # reference purposes. | ||
| 32 | # (**) I.e. it gives ~2-3x speed-up if compared with compiler generated | ||
| 33 | # code. One can argue that hand-coded *non*-SSE2 implementation | ||
| 34 | # would perform better than compiler generated one as well, and | ||
| 35 | # that comparison is therefore not exactly fair. Well, as SHA512 | ||
| 36 | # puts enormous pressure on IA-32 GP register bank, I reckon that | ||
| 37 | # hand-coded version wouldn't perform significantly better than | ||
| 38 | # one compiled with icc, ~20% perhaps... So that this code would | ||
| 39 | # still outperform it with distinguishing marginal. But feel free | ||
| 40 | # to prove me wrong:-) | ||
| 41 | # <appro@fy.chalmers.se> | ||
| 42 | push(@INC,"perlasm","../../perlasm"); | ||
| 43 | require "x86asm.pl"; | ||
| 44 | |||
| 45 | &asm_init($ARGV[0],"sha512-sse2.pl",$ARGV[$#ARGV] eq "386"); | ||
| 46 | |||
| 47 | $K512="esi"; # K512[80] table, found at the end... | ||
| 48 | #$W512="esp"; # $W512 is not just W512[16]: it comprises *two* copies | ||
| 49 | # of W512[16] and a copy of A-H variables... | ||
| 50 | $W512_SZ=8*(16+16+8); # see above... | ||
| 51 | #$Kidx="ebx"; # index in K512 table, advances from 0 to 80... | ||
| 52 | $Widx="edx"; # index in W512, wraps around at 16... | ||
| 53 | $data="edi"; # 16 qwords of input data... | ||
| 54 | $A="mm0"; # B-D and | ||
| 55 | $E="mm1"; # F-H are allocated dynamically... | ||
| 56 | $Aoff=256+0; # A-H offsets relative to $W512... | ||
| 57 | $Boff=256+8; | ||
| 58 | $Coff=256+16; | ||
| 59 | $Doff=256+24; | ||
| 60 | $Eoff=256+32; | ||
| 61 | $Foff=256+40; | ||
| 62 | $Goff=256+48; | ||
| 63 | $Hoff=256+56; | ||
| 64 | |||
| 65 | sub SHA2_ROUND() | ||
| 66 | { local ($kidx,$widx)=@_; | ||
| 67 | |||
| 68 | # One can argue that one could reorder instructions for better | ||
| 69 | # performance. Well, I tried and it doesn't seem to make any | ||
| 70 | # noticeable difference. Modern out-of-order execution cores | ||
| 71 | # reorder instructions to their liking in either case and they | ||
| 72 | # apparently do decent job. So we can keep the code more | ||
| 73 | # readable/regular/comprehensible:-) | ||
| 74 | |||
| 75 | # I adhere to 64-bit %mmX registers in order to avoid/not care | ||
| 76 | # about #GP exceptions on misaligned 128-bit access, most | ||
| 77 | # notably in paddq with memory operand. Not to mention that | ||
| 78 | # SSE2 intructions operating on %mmX can be scheduled every | ||
| 79 | # cycle [and not every second one if operating on %xmmN]. | ||
| 80 | |||
| 81 | &movq ("mm4",&QWP($Foff,$W512)); # load f | ||
| 82 | &movq ("mm5",&QWP($Goff,$W512)); # load g | ||
| 83 | &movq ("mm6",&QWP($Hoff,$W512)); # load h | ||
| 84 | |||
| 85 | &movq ("mm2",$E); # %mm2 is sliding right | ||
| 86 | &movq ("mm3",$E); # %mm3 is sliding left | ||
| 87 | &psrlq ("mm2",14); | ||
| 88 | &psllq ("mm3",23); | ||
| 89 | &movq ("mm7","mm2"); # %mm7 is T1 | ||
| 90 | &pxor ("mm7","mm3"); | ||
| 91 | &psrlq ("mm2",4); | ||
| 92 | &psllq ("mm3",23); | ||
| 93 | &pxor ("mm7","mm2"); | ||
| 94 | &pxor ("mm7","mm3"); | ||
| 95 | &psrlq ("mm2",23); | ||
| 96 | &psllq ("mm3",4); | ||
| 97 | &pxor ("mm7","mm2"); | ||
| 98 | &pxor ("mm7","mm3"); # T1=Sigma1_512(e) | ||
| 99 | |||
| 100 | &movq (&QWP($Foff,$W512),$E); # f = e | ||
| 101 | &movq (&QWP($Goff,$W512),"mm4"); # g = f | ||
| 102 | &movq (&QWP($Hoff,$W512),"mm5"); # h = g | ||
| 103 | |||
| 104 | &pxor ("mm4","mm5"); # f^=g | ||
| 105 | &pand ("mm4",$E); # f&=e | ||
| 106 | &pxor ("mm4","mm5"); # f^=g | ||
| 107 | &paddq ("mm7","mm4"); # T1+=Ch(e,f,g) | ||
| 108 | |||
| 109 | &movq ("mm2",&QWP($Boff,$W512)); # load b | ||
| 110 | &movq ("mm3",&QWP($Coff,$W512)); # load c | ||
| 111 | &movq ($E,&QWP($Doff,$W512)); # e = d | ||
| 112 | |||
| 113 | &paddq ("mm7","mm6"); # T1+=h | ||
| 114 | &paddq ("mm7",&QWP(0,$K512,$kidx,8)); # T1+=K512[i] | ||
| 115 | &paddq ("mm7",&QWP(0,$W512,$widx,8)); # T1+=W512[i] | ||
| 116 | &paddq ($E,"mm7"); # e += T1 | ||
| 117 | |||
| 118 | &movq ("mm4",$A); # %mm4 is sliding right | ||
| 119 | &movq ("mm5",$A); # %mm5 is sliding left | ||
| 120 | &psrlq ("mm4",28); | ||
| 121 | &psllq ("mm5",25); | ||
| 122 | &movq ("mm6","mm4"); # %mm6 is T2 | ||
| 123 | &pxor ("mm6","mm5"); | ||
| 124 | &psrlq ("mm4",6); | ||
| 125 | &psllq ("mm5",5); | ||
| 126 | &pxor ("mm6","mm4"); | ||
| 127 | &pxor ("mm6","mm5"); | ||
| 128 | &psrlq ("mm4",5); | ||
| 129 | &psllq ("mm5",6); | ||
| 130 | &pxor ("mm6","mm4"); | ||
| 131 | &pxor ("mm6","mm5"); # T2=Sigma0_512(a) | ||
| 132 | |||
| 133 | &movq (&QWP($Boff,$W512),$A); # b = a | ||
| 134 | &movq (&QWP($Coff,$W512),"mm2"); # c = b | ||
| 135 | &movq (&QWP($Doff,$W512),"mm3"); # d = c | ||
| 136 | |||
| 137 | &movq ("mm4",$A); # %mm4=a | ||
| 138 | &por ($A,"mm3"); # a=a|c | ||
| 139 | &pand ("mm4","mm3"); # %mm4=a&c | ||
| 140 | &pand ($A,"mm2"); # a=(a|c)&b | ||
| 141 | &por ("mm4",$A); # %mm4=(a&c)|((a|c)&b) | ||
| 142 | &paddq ("mm6","mm4"); # T2+=Maj(a,b,c) | ||
| 143 | |||
| 144 | &movq ($A,"mm7"); # a=T1 | ||
| 145 | &paddq ($A,"mm6"); # a+=T2 | ||
| 146 | } | ||
| 147 | |||
| 148 | $func="sha512_block_sse2"; | ||
| 149 | |||
| 150 | &function_begin_B($func); | ||
| 151 | if (0) {# Caller is expected to check if it's appropriate to | ||
| 152 | # call this routine. Below 3 lines are retained for | ||
| 153 | # debugging purposes... | ||
| 154 | &picmeup("eax","OPENSSL_ia32cap"); | ||
| 155 | &bt (&DWP(0,"eax"),26); | ||
| 156 | &jnc ("SHA512_Transform"); | ||
| 157 | } | ||
| 158 | |||
| 159 | &push ("ebp"); | ||
| 160 | &mov ("ebp","esp"); | ||
| 161 | &push ("ebx"); | ||
| 162 | &push ("esi"); | ||
| 163 | &push ("edi"); | ||
| 164 | |||
| 165 | &mov ($Widx,&DWP(8,"ebp")); # A-H state, 1st arg | ||
| 166 | &mov ($data,&DWP(12,"ebp")); # input data, 2nd arg | ||
| 167 | &call (&label("pic_point")); # make it PIC! | ||
| 168 | &set_label("pic_point"); | ||
| 169 | &blindpop($K512); | ||
| 170 | &lea ($K512,&DWP(&label("K512")."-".&label("pic_point"),$K512)); | ||
| 171 | |||
| 172 | $W512 = "esp"; # start using %esp as W512 | ||
| 173 | &sub ($W512,$W512_SZ); | ||
| 174 | &and ($W512,-16); # ensure 128-bit alignment | ||
| 175 | |||
| 176 | # make private copy of A-H | ||
| 177 | # v assume the worst and stick to unaligned load | ||
| 178 | &movdqu ("xmm0",&QWP(0,$Widx)); | ||
| 179 | &movdqu ("xmm1",&QWP(16,$Widx)); | ||
| 180 | &movdqu ("xmm2",&QWP(32,$Widx)); | ||
| 181 | &movdqu ("xmm3",&QWP(48,$Widx)); | ||
| 182 | |||
| 183 | &align(8); | ||
| 184 | &set_label("_chunk_loop"); | ||
| 185 | |||
| 186 | &movdqa (&QWP($Aoff,$W512),"xmm0"); # a,b | ||
| 187 | &movdqa (&QWP($Coff,$W512),"xmm1"); # c,d | ||
| 188 | &movdqa (&QWP($Eoff,$W512),"xmm2"); # e,f | ||
| 189 | &movdqa (&QWP($Goff,$W512),"xmm3"); # g,h | ||
| 190 | |||
| 191 | &xor ($Widx,$Widx); | ||
| 192 | |||
| 193 | &movdq2q($A,"xmm0"); # load a | ||
| 194 | &movdq2q($E,"xmm2"); # load e | ||
| 195 | |||
| 196 | # Why aren't loops unrolled? It makes sense to unroll if | ||
| 197 | # execution time for loop body is comparable with branch | ||
| 198 | # penalties and/or if whole data-set resides in register bank. | ||
| 199 | # Neither is case here... Well, it would be possible to | ||
| 200 | # eliminate few store operations, but it would hardly affect | ||
| 201 | # so to say stop-watch performance, as there is a lot of | ||
| 202 | # available memory slots to fill. It will only relieve some | ||
| 203 | # pressure off memory bus... | ||
| 204 | |||
| 205 | # flip input stream byte order... | ||
| 206 | &mov ("eax",&DWP(0,$data,$Widx,8)); | ||
| 207 | &mov ("ebx",&DWP(4,$data,$Widx,8)); | ||
| 208 | &bswap ("eax"); | ||
| 209 | &bswap ("ebx"); | ||
| 210 | &mov (&DWP(0,$W512,$Widx,8),"ebx"); # W512[i] | ||
| 211 | &mov (&DWP(4,$W512,$Widx,8),"eax"); | ||
| 212 | &mov (&DWP(128+0,$W512,$Widx,8),"ebx"); # copy of W512[i] | ||
| 213 | &mov (&DWP(128+4,$W512,$Widx,8),"eax"); | ||
| 214 | |||
| 215 | &align(8); | ||
| 216 | &set_label("_1st_loop"); # 0-15 | ||
| 217 | # flip input stream byte order... | ||
| 218 | &mov ("eax",&DWP(0+8,$data,$Widx,8)); | ||
| 219 | &mov ("ebx",&DWP(4+8,$data,$Widx,8)); | ||
| 220 | &bswap ("eax"); | ||
| 221 | &bswap ("ebx"); | ||
| 222 | &mov (&DWP(0+8,$W512,$Widx,8),"ebx"); # W512[i] | ||
| 223 | &mov (&DWP(4+8,$W512,$Widx,8),"eax"); | ||
| 224 | &mov (&DWP(128+0+8,$W512,$Widx,8),"ebx"); # copy of W512[i] | ||
| 225 | &mov (&DWP(128+4+8,$W512,$Widx,8),"eax"); | ||
| 226 | &set_label("_1st_looplet"); | ||
| 227 | &SHA2_ROUND($Widx,$Widx); &inc($Widx); | ||
| 228 | |||
| 229 | &cmp ($Widx,15) | ||
| 230 | &jl (&label("_1st_loop")); | ||
| 231 | &je (&label("_1st_looplet")); # playing similar trick on 2nd loop | ||
| 232 | # does not improve performance... | ||
| 233 | |||
| 234 | $Kidx = "ebx"; # start using %ebx as Kidx | ||
| 235 | &mov ($Kidx,$Widx); | ||
| 236 | |||
| 237 | &align(8); | ||
| 238 | &set_label("_2nd_loop"); # 16-79 | ||
| 239 | &and($Widx,0xf); | ||
| 240 | |||
| 241 | # 128-bit fragment! I update W512[i] and W512[i+1] in | ||
| 242 | # parallel:-) Note that I refer to W512[(i&0xf)+N] and not to | ||
| 243 | # W512[(i+N)&0xf]! This is exactly what I maintain the second | ||
| 244 | # copy of W512[16] for... | ||
| 245 | &movdqu ("xmm0",&QWP(8*1,$W512,$Widx,8)); # s0=W512[i+1] | ||
| 246 | &movdqa ("xmm2","xmm0"); # %xmm2 is sliding right | ||
| 247 | &movdqa ("xmm3","xmm0"); # %xmm3 is sliding left | ||
| 248 | &psrlq ("xmm2",1); | ||
| 249 | &psllq ("xmm3",56); | ||
| 250 | &movdqa ("xmm0","xmm2"); | ||
| 251 | &pxor ("xmm0","xmm3"); | ||
| 252 | &psrlq ("xmm2",6); | ||
| 253 | &psllq ("xmm3",7); | ||
| 254 | &pxor ("xmm0","xmm2"); | ||
| 255 | &pxor ("xmm0","xmm3"); | ||
| 256 | &psrlq ("xmm2",1); | ||
| 257 | &pxor ("xmm0","xmm2"); # s0 = sigma0_512(s0); | ||
| 258 | |||
| 259 | &movdqa ("xmm1",&QWP(8*14,$W512,$Widx,8)); # s1=W512[i+14] | ||
| 260 | &movdqa ("xmm4","xmm1"); # %xmm4 is sliding right | ||
| 261 | &movdqa ("xmm5","xmm1"); # %xmm5 is sliding left | ||
| 262 | &psrlq ("xmm4",6); | ||
| 263 | &psllq ("xmm5",3); | ||
| 264 | &movdqa ("xmm1","xmm4"); | ||
| 265 | &pxor ("xmm1","xmm5"); | ||
| 266 | &psrlq ("xmm4",13); | ||
| 267 | &psllq ("xmm5",42); | ||
| 268 | &pxor ("xmm1","xmm4"); | ||
| 269 | &pxor ("xmm1","xmm5"); | ||
| 270 | &psrlq ("xmm4",42); | ||
| 271 | &pxor ("xmm1","xmm4"); # s1 = sigma1_512(s1); | ||
| 272 | |||
| 273 | # + have to explictly load W512[i+9] as it's not 128-bit | ||
| 274 | # v aligned and paddq would throw an exception... | ||
| 275 | &movdqu ("xmm6",&QWP(8*9,$W512,$Widx,8)); | ||
| 276 | &paddq ("xmm0","xmm1"); # s0 += s1 | ||
| 277 | &paddq ("xmm0","xmm6"); # s0 += W512[i+9] | ||
| 278 | &paddq ("xmm0",&QWP(0,$W512,$Widx,8)); # s0 += W512[i] | ||
| 279 | |||
| 280 | &movdqa (&QWP(0,$W512,$Widx,8),"xmm0"); # W512[i] = s0 | ||
| 281 | &movdqa (&QWP(16*8,$W512,$Widx,8),"xmm0"); # copy of W512[i] | ||
| 282 | |||
| 283 | # as the above fragment was 128-bit, we "owe" 2 rounds... | ||
| 284 | &SHA2_ROUND($Kidx,$Widx); &inc($Kidx); &inc($Widx); | ||
| 285 | &SHA2_ROUND($Kidx,$Widx); &inc($Kidx); &inc($Widx); | ||
| 286 | |||
| 287 | &cmp ($Kidx,80); | ||
| 288 | &jl (&label("_2nd_loop")); | ||
| 289 | |||
| 290 | # update A-H state | ||
| 291 | &mov ($Widx,&DWP(8,"ebp")); # A-H state, 1st arg | ||
| 292 | &movq (&QWP($Aoff,$W512),$A); # write out a | ||
| 293 | &movq (&QWP($Eoff,$W512),$E); # write out e | ||
| 294 | &movdqu ("xmm0",&QWP(0,$Widx)); | ||
| 295 | &movdqu ("xmm1",&QWP(16,$Widx)); | ||
| 296 | &movdqu ("xmm2",&QWP(32,$Widx)); | ||
| 297 | &movdqu ("xmm3",&QWP(48,$Widx)); | ||
| 298 | &paddq ("xmm0",&QWP($Aoff,$W512)); # 128-bit additions... | ||
| 299 | &paddq ("xmm1",&QWP($Coff,$W512)); | ||
| 300 | &paddq ("xmm2",&QWP($Eoff,$W512)); | ||
| 301 | &paddq ("xmm3",&QWP($Goff,$W512)); | ||
| 302 | &movdqu (&QWP(0,$Widx),"xmm0"); | ||
| 303 | &movdqu (&QWP(16,$Widx),"xmm1"); | ||
| 304 | &movdqu (&QWP(32,$Widx),"xmm2"); | ||
| 305 | &movdqu (&QWP(48,$Widx),"xmm3"); | ||
| 306 | |||
| 307 | &add ($data,16*8); # advance input data pointer | ||
| 308 | &dec (&DWP(16,"ebp")); # decrement 3rd arg | ||
| 309 | &jnz (&label("_chunk_loop")); | ||
| 310 | |||
| 311 | # epilogue | ||
| 312 | &emms (); # required for at least ELF and Win32 ABIs | ||
| 313 | &mov ("edi",&DWP(-12,"ebp")); | ||
| 314 | &mov ("esi",&DWP(-8,"ebp")); | ||
| 315 | &mov ("ebx",&DWP(-4,"ebp")); | ||
| 316 | &leave (); | ||
| 317 | &ret (); | ||
| 318 | |||
| 319 | &align(64); | ||
| 320 | &set_label("K512"); # Yes! I keep it in the code segment! | ||
| 321 | &data_word(0xd728ae22,0x428a2f98); # u64 | ||
| 322 | &data_word(0x23ef65cd,0x71374491); # u64 | ||
| 323 | &data_word(0xec4d3b2f,0xb5c0fbcf); # u64 | ||
| 324 | &data_word(0x8189dbbc,0xe9b5dba5); # u64 | ||
| 325 | &data_word(0xf348b538,0x3956c25b); # u64 | ||
| 326 | &data_word(0xb605d019,0x59f111f1); # u64 | ||
| 327 | &data_word(0xaf194f9b,0x923f82a4); # u64 | ||
| 328 | &data_word(0xda6d8118,0xab1c5ed5); # u64 | ||
| 329 | &data_word(0xa3030242,0xd807aa98); # u64 | ||
| 330 | &data_word(0x45706fbe,0x12835b01); # u64 | ||
| 331 | &data_word(0x4ee4b28c,0x243185be); # u64 | ||
| 332 | &data_word(0xd5ffb4e2,0x550c7dc3); # u64 | ||
| 333 | &data_word(0xf27b896f,0x72be5d74); # u64 | ||
| 334 | &data_word(0x3b1696b1,0x80deb1fe); # u64 | ||
| 335 | &data_word(0x25c71235,0x9bdc06a7); # u64 | ||
| 336 | &data_word(0xcf692694,0xc19bf174); # u64 | ||
| 337 | &data_word(0x9ef14ad2,0xe49b69c1); # u64 | ||
| 338 | &data_word(0x384f25e3,0xefbe4786); # u64 | ||
| 339 | &data_word(0x8b8cd5b5,0x0fc19dc6); # u64 | ||
| 340 | &data_word(0x77ac9c65,0x240ca1cc); # u64 | ||
| 341 | &data_word(0x592b0275,0x2de92c6f); # u64 | ||
| 342 | &data_word(0x6ea6e483,0x4a7484aa); # u64 | ||
| 343 | &data_word(0xbd41fbd4,0x5cb0a9dc); # u64 | ||
| 344 | &data_word(0x831153b5,0x76f988da); # u64 | ||
| 345 | &data_word(0xee66dfab,0x983e5152); # u64 | ||
| 346 | &data_word(0x2db43210,0xa831c66d); # u64 | ||
| 347 | &data_word(0x98fb213f,0xb00327c8); # u64 | ||
| 348 | &data_word(0xbeef0ee4,0xbf597fc7); # u64 | ||
| 349 | &data_word(0x3da88fc2,0xc6e00bf3); # u64 | ||
| 350 | &data_word(0x930aa725,0xd5a79147); # u64 | ||
| 351 | &data_word(0xe003826f,0x06ca6351); # u64 | ||
| 352 | &data_word(0x0a0e6e70,0x14292967); # u64 | ||
| 353 | &data_word(0x46d22ffc,0x27b70a85); # u64 | ||
| 354 | &data_word(0x5c26c926,0x2e1b2138); # u64 | ||
| 355 | &data_word(0x5ac42aed,0x4d2c6dfc); # u64 | ||
| 356 | &data_word(0x9d95b3df,0x53380d13); # u64 | ||
| 357 | &data_word(0x8baf63de,0x650a7354); # u64 | ||
| 358 | &data_word(0x3c77b2a8,0x766a0abb); # u64 | ||
| 359 | &data_word(0x47edaee6,0x81c2c92e); # u64 | ||
| 360 | &data_word(0x1482353b,0x92722c85); # u64 | ||
| 361 | &data_word(0x4cf10364,0xa2bfe8a1); # u64 | ||
| 362 | &data_word(0xbc423001,0xa81a664b); # u64 | ||
| 363 | &data_word(0xd0f89791,0xc24b8b70); # u64 | ||
| 364 | &data_word(0x0654be30,0xc76c51a3); # u64 | ||
| 365 | &data_word(0xd6ef5218,0xd192e819); # u64 | ||
| 366 | &data_word(0x5565a910,0xd6990624); # u64 | ||
| 367 | &data_word(0x5771202a,0xf40e3585); # u64 | ||
| 368 | &data_word(0x32bbd1b8,0x106aa070); # u64 | ||
| 369 | &data_word(0xb8d2d0c8,0x19a4c116); # u64 | ||
| 370 | &data_word(0x5141ab53,0x1e376c08); # u64 | ||
| 371 | &data_word(0xdf8eeb99,0x2748774c); # u64 | ||
| 372 | &data_word(0xe19b48a8,0x34b0bcb5); # u64 | ||
| 373 | &data_word(0xc5c95a63,0x391c0cb3); # u64 | ||
| 374 | &data_word(0xe3418acb,0x4ed8aa4a); # u64 | ||
| 375 | &data_word(0x7763e373,0x5b9cca4f); # u64 | ||
| 376 | &data_word(0xd6b2b8a3,0x682e6ff3); # u64 | ||
| 377 | &data_word(0x5defb2fc,0x748f82ee); # u64 | ||
| 378 | &data_word(0x43172f60,0x78a5636f); # u64 | ||
| 379 | &data_word(0xa1f0ab72,0x84c87814); # u64 | ||
| 380 | &data_word(0x1a6439ec,0x8cc70208); # u64 | ||
| 381 | &data_word(0x23631e28,0x90befffa); # u64 | ||
| 382 | &data_word(0xde82bde9,0xa4506ceb); # u64 | ||
| 383 | &data_word(0xb2c67915,0xbef9a3f7); # u64 | ||
| 384 | &data_word(0xe372532b,0xc67178f2); # u64 | ||
| 385 | &data_word(0xea26619c,0xca273ece); # u64 | ||
| 386 | &data_word(0x21c0c207,0xd186b8c7); # u64 | ||
| 387 | &data_word(0xcde0eb1e,0xeada7dd6); # u64 | ||
| 388 | &data_word(0xee6ed178,0xf57d4f7f); # u64 | ||
| 389 | &data_word(0x72176fba,0x06f067aa); # u64 | ||
| 390 | &data_word(0xa2c898a6,0x0a637dc5); # u64 | ||
| 391 | &data_word(0xbef90dae,0x113f9804); # u64 | ||
| 392 | &data_word(0x131c471b,0x1b710b35); # u64 | ||
| 393 | &data_word(0x23047d84,0x28db77f5); # u64 | ||
| 394 | &data_word(0x40c72493,0x32caab7b); # u64 | ||
| 395 | &data_word(0x15c9bebc,0x3c9ebe0a); # u64 | ||
| 396 | &data_word(0x9c100d4c,0x431d67c4); # u64 | ||
| 397 | &data_word(0xcb3e42b6,0x4cc5d4be); # u64 | ||
| 398 | &data_word(0xfc657e2a,0x597f299c); # u64 | ||
| 399 | &data_word(0x3ad6faec,0x5fcb6fab); # u64 | ||
| 400 | &data_word(0x4a475817,0x6c44198c); # u64 | ||
| 401 | |||
| 402 | &function_end_B($func); | ||
| 403 | |||
| 404 | &asm_finish(); | ||
diff --git a/src/lib/libcrypto/sha/sha1s.cpp b/src/lib/libcrypto/sha/sha1s.cpp deleted file mode 100644 index af23d1e0f2..0000000000 --- a/src/lib/libcrypto/sha/sha1s.cpp +++ /dev/null | |||
| @@ -1,82 +0,0 @@ | |||
| 1 | // | ||
| 2 | // gettsc.inl | ||
| 3 | // | ||
| 4 | // gives access to the Pentium's (secret) cycle counter | ||
| 5 | // | ||
| 6 | // This software was written by Leonard Janke (janke@unixg.ubc.ca) | ||
| 7 | // in 1996-7 and is entered, by him, into the public domain. | ||
| 8 | |||
| 9 | #if defined(__WATCOMC__) | ||
| 10 | void GetTSC(unsigned long&); | ||
| 11 | #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; | ||
| 12 | #elif defined(__GNUC__) | ||
| 13 | inline | ||
| 14 | void GetTSC(unsigned long& tsc) | ||
| 15 | { | ||
| 16 | asm volatile(".byte 15, 49\n\t" | ||
| 17 | : "=eax" (tsc) | ||
| 18 | : | ||
| 19 | : "%edx", "%eax"); | ||
| 20 | } | ||
| 21 | #elif defined(_MSC_VER) | ||
| 22 | inline | ||
| 23 | void GetTSC(unsigned long& tsc) | ||
| 24 | { | ||
| 25 | unsigned long a; | ||
| 26 | __asm _emit 0fh | ||
| 27 | __asm _emit 31h | ||
| 28 | __asm mov a, eax; | ||
| 29 | tsc=a; | ||
| 30 | } | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #include <stdio.h> | ||
| 34 | #include <stdlib.h> | ||
| 35 | #include <openssl/sha.h> | ||
| 36 | |||
| 37 | #define sha1_block_x86 sha1_block_asm_data_order | ||
| 38 | extern "C" { | ||
| 39 | void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num); | ||
| 40 | } | ||
| 41 | |||
| 42 | void main(int argc,char *argv[]) | ||
| 43 | { | ||
| 44 | unsigned char buffer[64*256]; | ||
| 45 | SHA_CTX ctx; | ||
| 46 | unsigned long s1,s2,e1,e2; | ||
| 47 | unsigned char k[16]; | ||
| 48 | unsigned long data[2]; | ||
| 49 | unsigned char iv[8]; | ||
| 50 | int i,num=0,numm; | ||
| 51 | int j=0; | ||
| 52 | |||
| 53 | if (argc >= 2) | ||
| 54 | num=atoi(argv[1]); | ||
| 55 | |||
| 56 | if (num == 0) num=16; | ||
| 57 | if (num > 250) num=16; | ||
| 58 | numm=num+2; | ||
| 59 | #if 0 | ||
| 60 | num*=64; | ||
| 61 | numm*=64; | ||
| 62 | #endif | ||
| 63 | |||
| 64 | for (j=0; j<6; j++) | ||
| 65 | { | ||
| 66 | for (i=0; i<10; i++) /**/ | ||
| 67 | { | ||
| 68 | sha1_block_x86(&ctx,buffer,numm); | ||
| 69 | GetTSC(s1); | ||
| 70 | sha1_block_x86(&ctx,buffer,numm); | ||
| 71 | GetTSC(e1); | ||
| 72 | GetTSC(s2); | ||
| 73 | sha1_block_x86(&ctx,buffer,num); | ||
| 74 | GetTSC(e2); | ||
| 75 | sha1_block_x86(&ctx,buffer,num); | ||
| 76 | } | ||
| 77 | |||
| 78 | printf("sha1 (%d bytes) %d %d (%.2f)\n",num*64, | ||
| 79 | e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
diff --git a/src/lib/libcrypto/sha/sha256t.c b/src/lib/libcrypto/sha/sha256t.c new file mode 100644 index 0000000000..6b4a3bd001 --- /dev/null +++ b/src/lib/libcrypto/sha/sha256t.c | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | /* crypto/sha/sha256t.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | ||
| 4 | * ==================================================================== | ||
| 5 | */ | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | |||
| 10 | #include <openssl/sha.h> | ||
| 11 | #include <openssl/evp.h> | ||
| 12 | |||
| 13 | #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA256) | ||
| 14 | int main(int argc, char *argv[]) | ||
| 15 | { | ||
| 16 | printf("No SHA256 support\n"); | ||
| 17 | return(0); | ||
| 18 | } | ||
| 19 | #else | ||
| 20 | |||
| 21 | unsigned char app_b1[SHA256_DIGEST_LENGTH] = { | ||
| 22 | 0xba,0x78,0x16,0xbf,0x8f,0x01,0xcf,0xea, | ||
| 23 | 0x41,0x41,0x40,0xde,0x5d,0xae,0x22,0x23, | ||
| 24 | 0xb0,0x03,0x61,0xa3,0x96,0x17,0x7a,0x9c, | ||
| 25 | 0xb4,0x10,0xff,0x61,0xf2,0x00,0x15,0xad }; | ||
| 26 | |||
| 27 | unsigned char app_b2[SHA256_DIGEST_LENGTH] = { | ||
| 28 | 0x24,0x8d,0x6a,0x61,0xd2,0x06,0x38,0xb8, | ||
| 29 | 0xe5,0xc0,0x26,0x93,0x0c,0x3e,0x60,0x39, | ||
| 30 | 0xa3,0x3c,0xe4,0x59,0x64,0xff,0x21,0x67, | ||
| 31 | 0xf6,0xec,0xed,0xd4,0x19,0xdb,0x06,0xc1 }; | ||
| 32 | |||
| 33 | unsigned char app_b3[SHA256_DIGEST_LENGTH] = { | ||
| 34 | 0xcd,0xc7,0x6e,0x5c,0x99,0x14,0xfb,0x92, | ||
| 35 | 0x81,0xa1,0xc7,0xe2,0x84,0xd7,0x3e,0x67, | ||
| 36 | 0xf1,0x80,0x9a,0x48,0xa4,0x97,0x20,0x0e, | ||
| 37 | 0x04,0x6d,0x39,0xcc,0xc7,0x11,0x2c,0xd0 }; | ||
| 38 | |||
| 39 | unsigned char addenum_1[SHA224_DIGEST_LENGTH] = { | ||
| 40 | 0x23,0x09,0x7d,0x22,0x34,0x05,0xd8,0x22, | ||
| 41 | 0x86,0x42,0xa4,0x77,0xbd,0xa2,0x55,0xb3, | ||
| 42 | 0x2a,0xad,0xbc,0xe4,0xbd,0xa0,0xb3,0xf7, | ||
| 43 | 0xe3,0x6c,0x9d,0xa7 }; | ||
| 44 | |||
| 45 | unsigned char addenum_2[SHA224_DIGEST_LENGTH] = { | ||
| 46 | 0x75,0x38,0x8b,0x16,0x51,0x27,0x76,0xcc, | ||
| 47 | 0x5d,0xba,0x5d,0xa1,0xfd,0x89,0x01,0x50, | ||
| 48 | 0xb0,0xc6,0x45,0x5c,0xb4,0xf5,0x8b,0x19, | ||
| 49 | 0x52,0x52,0x25,0x25 }; | ||
| 50 | |||
| 51 | unsigned char addenum_3[SHA224_DIGEST_LENGTH] = { | ||
| 52 | 0x20,0x79,0x46,0x55,0x98,0x0c,0x91,0xd8, | ||
| 53 | 0xbb,0xb4,0xc1,0xea,0x97,0x61,0x8a,0x4b, | ||
| 54 | 0xf0,0x3f,0x42,0x58,0x19,0x48,0xb2,0xee, | ||
| 55 | 0x4e,0xe7,0xad,0x67 }; | ||
| 56 | |||
| 57 | int main (int argc,char **argv) | ||
| 58 | { unsigned char md[SHA256_DIGEST_LENGTH]; | ||
| 59 | int i; | ||
| 60 | EVP_MD_CTX evp; | ||
| 61 | |||
| 62 | fprintf(stdout,"Testing SHA-256 "); | ||
| 63 | |||
| 64 | EVP_Digest ("abc",3,md,NULL,EVP_sha256(),NULL); | ||
| 65 | if (memcmp(md,app_b1,sizeof(app_b1))) | ||
| 66 | { fflush(stdout); | ||
| 67 | fprintf(stderr,"\nTEST 1 of 3 failed.\n"); | ||
| 68 | return 1; | ||
| 69 | } | ||
| 70 | else | ||
| 71 | fprintf(stdout,"."); fflush(stdout); | ||
| 72 | |||
| 73 | EVP_Digest ("abcdbcde""cdefdefg""efghfghi""ghijhijk" | ||
| 74 | "ijkljklm""klmnlmno""mnopnopq",56,md,NULL,EVP_sha256(),NULL); | ||
| 75 | if (memcmp(md,app_b2,sizeof(app_b2))) | ||
| 76 | { fflush(stdout); | ||
| 77 | fprintf(stderr,"\nTEST 2 of 3 failed.\n"); | ||
| 78 | return 1; | ||
| 79 | } | ||
| 80 | else | ||
| 81 | fprintf(stdout,"."); fflush(stdout); | ||
| 82 | |||
| 83 | EVP_MD_CTX_init (&evp); | ||
| 84 | EVP_DigestInit_ex (&evp,EVP_sha256(),NULL); | ||
| 85 | for (i=0;i<1000000;i+=160) | ||
| 86 | EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 87 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 88 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 89 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 90 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 91 | (1000000-i)<160?1000000-i:160); | ||
| 92 | EVP_DigestFinal_ex (&evp,md,NULL); | ||
| 93 | EVP_MD_CTX_cleanup (&evp); | ||
| 94 | |||
| 95 | if (memcmp(md,app_b3,sizeof(app_b3))) | ||
| 96 | { fflush(stdout); | ||
| 97 | fprintf(stderr,"\nTEST 3 of 3 failed.\n"); | ||
| 98 | return 1; | ||
| 99 | } | ||
| 100 | else | ||
| 101 | fprintf(stdout,"."); fflush(stdout); | ||
| 102 | |||
| 103 | fprintf(stdout," passed.\n"); fflush(stdout); | ||
| 104 | |||
| 105 | fprintf(stdout,"Testing SHA-224 "); | ||
| 106 | |||
| 107 | EVP_Digest ("abc",3,md,NULL,EVP_sha224(),NULL); | ||
| 108 | if (memcmp(md,addenum_1,sizeof(addenum_1))) | ||
| 109 | { fflush(stdout); | ||
| 110 | fprintf(stderr,"\nTEST 1 of 3 failed.\n"); | ||
| 111 | return 1; | ||
| 112 | } | ||
| 113 | else | ||
| 114 | fprintf(stdout,"."); fflush(stdout); | ||
| 115 | |||
| 116 | EVP_Digest ("abcdbcde""cdefdefg""efghfghi""ghijhijk" | ||
| 117 | "ijkljklm""klmnlmno""mnopnopq",56,md,NULL,EVP_sha224(),NULL); | ||
| 118 | if (memcmp(md,addenum_2,sizeof(addenum_2))) | ||
| 119 | { fflush(stdout); | ||
| 120 | fprintf(stderr,"\nTEST 2 of 3 failed.\n"); | ||
| 121 | return 1; | ||
| 122 | } | ||
| 123 | else | ||
| 124 | fprintf(stdout,"."); fflush(stdout); | ||
| 125 | |||
| 126 | EVP_MD_CTX_init (&evp); | ||
| 127 | EVP_DigestInit_ex (&evp,EVP_sha224(),NULL); | ||
| 128 | for (i=0;i<1000000;i+=64) | ||
| 129 | EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 130 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 131 | (1000000-i)<64?1000000-i:64); | ||
| 132 | EVP_DigestFinal_ex (&evp,md,NULL); | ||
| 133 | EVP_MD_CTX_cleanup (&evp); | ||
| 134 | |||
| 135 | if (memcmp(md,addenum_3,sizeof(addenum_3))) | ||
| 136 | { fflush(stdout); | ||
| 137 | fprintf(stderr,"\nTEST 3 of 3 failed.\n"); | ||
| 138 | return 1; | ||
| 139 | } | ||
| 140 | else | ||
| 141 | fprintf(stdout,"."); fflush(stdout); | ||
| 142 | |||
| 143 | fprintf(stdout," passed.\n"); fflush(stdout); | ||
| 144 | |||
| 145 | return 0; | ||
| 146 | } | ||
| 147 | #endif | ||
diff --git a/src/lib/libcrypto/sha/sha512t.c b/src/lib/libcrypto/sha/sha512t.c new file mode 100644 index 0000000000..210041d435 --- /dev/null +++ b/src/lib/libcrypto/sha/sha512t.c | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | /* crypto/sha/sha512t.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | ||
| 4 | * ==================================================================== | ||
| 5 | */ | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | |||
| 10 | #include <openssl/sha.h> | ||
| 11 | #include <openssl/evp.h> | ||
| 12 | #include <openssl/crypto.h> | ||
| 13 | |||
| 14 | #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA512) | ||
| 15 | int main(int argc, char *argv[]) | ||
| 16 | { | ||
| 17 | printf("No SHA512 support\n"); | ||
| 18 | return(0); | ||
| 19 | } | ||
| 20 | #else | ||
| 21 | |||
| 22 | unsigned char app_c1[SHA512_DIGEST_LENGTH] = { | ||
| 23 | 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba, | ||
| 24 | 0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31, | ||
| 25 | 0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2, | ||
| 26 | 0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a, | ||
| 27 | 0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8, | ||
| 28 | 0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd, | ||
| 29 | 0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e, | ||
| 30 | 0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f }; | ||
| 31 | |||
| 32 | unsigned char app_c2[SHA512_DIGEST_LENGTH] = { | ||
| 33 | 0x8e,0x95,0x9b,0x75,0xda,0xe3,0x13,0xda, | ||
| 34 | 0x8c,0xf4,0xf7,0x28,0x14,0xfc,0x14,0x3f, | ||
| 35 | 0x8f,0x77,0x79,0xc6,0xeb,0x9f,0x7f,0xa1, | ||
| 36 | 0x72,0x99,0xae,0xad,0xb6,0x88,0x90,0x18, | ||
| 37 | 0x50,0x1d,0x28,0x9e,0x49,0x00,0xf7,0xe4, | ||
| 38 | 0x33,0x1b,0x99,0xde,0xc4,0xb5,0x43,0x3a, | ||
| 39 | 0xc7,0xd3,0x29,0xee,0xb6,0xdd,0x26,0x54, | ||
| 40 | 0x5e,0x96,0xe5,0x5b,0x87,0x4b,0xe9,0x09 }; | ||
| 41 | |||
| 42 | unsigned char app_c3[SHA512_DIGEST_LENGTH] = { | ||
| 43 | 0xe7,0x18,0x48,0x3d,0x0c,0xe7,0x69,0x64, | ||
| 44 | 0x4e,0x2e,0x42,0xc7,0xbc,0x15,0xb4,0x63, | ||
| 45 | 0x8e,0x1f,0x98,0xb1,0x3b,0x20,0x44,0x28, | ||
| 46 | 0x56,0x32,0xa8,0x03,0xaf,0xa9,0x73,0xeb, | ||
| 47 | 0xde,0x0f,0xf2,0x44,0x87,0x7e,0xa6,0x0a, | ||
| 48 | 0x4c,0xb0,0x43,0x2c,0xe5,0x77,0xc3,0x1b, | ||
| 49 | 0xeb,0x00,0x9c,0x5c,0x2c,0x49,0xaa,0x2e, | ||
| 50 | 0x4e,0xad,0xb2,0x17,0xad,0x8c,0xc0,0x9b }; | ||
| 51 | |||
| 52 | unsigned char app_d1[SHA384_DIGEST_LENGTH] = { | ||
| 53 | 0xcb,0x00,0x75,0x3f,0x45,0xa3,0x5e,0x8b, | ||
| 54 | 0xb5,0xa0,0x3d,0x69,0x9a,0xc6,0x50,0x07, | ||
| 55 | 0x27,0x2c,0x32,0xab,0x0e,0xde,0xd1,0x63, | ||
| 56 | 0x1a,0x8b,0x60,0x5a,0x43,0xff,0x5b,0xed, | ||
| 57 | 0x80,0x86,0x07,0x2b,0xa1,0xe7,0xcc,0x23, | ||
| 58 | 0x58,0xba,0xec,0xa1,0x34,0xc8,0x25,0xa7 }; | ||
| 59 | |||
| 60 | unsigned char app_d2[SHA384_DIGEST_LENGTH] = { | ||
| 61 | 0x09,0x33,0x0c,0x33,0xf7,0x11,0x47,0xe8, | ||
| 62 | 0x3d,0x19,0x2f,0xc7,0x82,0xcd,0x1b,0x47, | ||
| 63 | 0x53,0x11,0x1b,0x17,0x3b,0x3b,0x05,0xd2, | ||
| 64 | 0x2f,0xa0,0x80,0x86,0xe3,0xb0,0xf7,0x12, | ||
| 65 | 0xfc,0xc7,0xc7,0x1a,0x55,0x7e,0x2d,0xb9, | ||
| 66 | 0x66,0xc3,0xe9,0xfa,0x91,0x74,0x60,0x39 }; | ||
| 67 | |||
| 68 | unsigned char app_d3[SHA384_DIGEST_LENGTH] = { | ||
| 69 | 0x9d,0x0e,0x18,0x09,0x71,0x64,0x74,0xcb, | ||
| 70 | 0x08,0x6e,0x83,0x4e,0x31,0x0a,0x4a,0x1c, | ||
| 71 | 0xed,0x14,0x9e,0x9c,0x00,0xf2,0x48,0x52, | ||
| 72 | 0x79,0x72,0xce,0xc5,0x70,0x4c,0x2a,0x5b, | ||
| 73 | 0x07,0xb8,0xb3,0xdc,0x38,0xec,0xc4,0xeb, | ||
| 74 | 0xae,0x97,0xdd,0xd8,0x7f,0x3d,0x89,0x85 }; | ||
| 75 | |||
| 76 | int main (int argc,char **argv) | ||
| 77 | { unsigned char md[SHA512_DIGEST_LENGTH]; | ||
| 78 | int i; | ||
| 79 | EVP_MD_CTX evp; | ||
| 80 | |||
| 81 | #ifdef OPENSSL_IA32_SSE2 | ||
| 82 | /* Alternative to this is to call OpenSSL_add_all_algorithms... | ||
| 83 | * The below code is retained exclusively for debugging purposes. */ | ||
| 84 | { char *env; | ||
| 85 | |||
| 86 | if ((env=getenv("OPENSSL_ia32cap"))) | ||
| 87 | OPENSSL_ia32cap = strtoul (env,NULL,0); | ||
| 88 | } | ||
| 89 | #endif | ||
| 90 | |||
| 91 | fprintf(stdout,"Testing SHA-512 "); | ||
| 92 | |||
| 93 | EVP_Digest ("abc",3,md,NULL,EVP_sha512(),NULL); | ||
| 94 | if (memcmp(md,app_c1,sizeof(app_c1))) | ||
| 95 | { fflush(stdout); | ||
| 96 | fprintf(stderr,"\nTEST 1 of 3 failed.\n"); | ||
| 97 | return 1; | ||
| 98 | } | ||
| 99 | else | ||
| 100 | fprintf(stdout,"."); fflush(stdout); | ||
| 101 | |||
| 102 | EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk" | ||
| 103 | "efghijkl""fghijklm""ghijklmn""hijklmno" | ||
| 104 | "ijklmnop""jklmnopq""klmnopqr""lmnopqrs" | ||
| 105 | "mnopqrst""nopqrstu",112,md,NULL,EVP_sha512(),NULL); | ||
| 106 | if (memcmp(md,app_c2,sizeof(app_c2))) | ||
| 107 | { fflush(stdout); | ||
| 108 | fprintf(stderr,"\nTEST 2 of 3 failed.\n"); | ||
| 109 | return 1; | ||
| 110 | } | ||
| 111 | else | ||
| 112 | fprintf(stdout,"."); fflush(stdout); | ||
| 113 | |||
| 114 | EVP_MD_CTX_init (&evp); | ||
| 115 | EVP_DigestInit_ex (&evp,EVP_sha512(),NULL); | ||
| 116 | for (i=0;i<1000000;i+=288) | ||
| 117 | EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 118 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 119 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 120 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 121 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 122 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 123 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 124 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 125 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 126 | (1000000-i)<288?1000000-i:288); | ||
| 127 | EVP_DigestFinal_ex (&evp,md,NULL); | ||
| 128 | EVP_MD_CTX_cleanup (&evp); | ||
| 129 | |||
| 130 | if (memcmp(md,app_c3,sizeof(app_c3))) | ||
| 131 | { fflush(stdout); | ||
| 132 | fprintf(stderr,"\nTEST 3 of 3 failed.\n"); | ||
| 133 | return 1; | ||
| 134 | } | ||
| 135 | else | ||
| 136 | fprintf(stdout,"."); fflush(stdout); | ||
| 137 | |||
| 138 | fprintf(stdout," passed.\n"); fflush(stdout); | ||
| 139 | |||
| 140 | fprintf(stdout,"Testing SHA-384 "); | ||
| 141 | |||
| 142 | EVP_Digest ("abc",3,md,NULL,EVP_sha384(),NULL); | ||
| 143 | if (memcmp(md,app_d1,sizeof(app_d1))) | ||
| 144 | { fflush(stdout); | ||
| 145 | fprintf(stderr,"\nTEST 1 of 3 failed.\n"); | ||
| 146 | return 1; | ||
| 147 | } | ||
| 148 | else | ||
| 149 | fprintf(stdout,"."); fflush(stdout); | ||
| 150 | |||
| 151 | EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk" | ||
| 152 | "efghijkl""fghijklm""ghijklmn""hijklmno" | ||
| 153 | "ijklmnop""jklmnopq""klmnopqr""lmnopqrs" | ||
| 154 | "mnopqrst""nopqrstu",112,md,NULL,EVP_sha384(),NULL); | ||
| 155 | if (memcmp(md,app_d2,sizeof(app_d2))) | ||
| 156 | { fflush(stdout); | ||
| 157 | fprintf(stderr,"\nTEST 2 of 3 failed.\n"); | ||
| 158 | return 1; | ||
| 159 | } | ||
| 160 | else | ||
| 161 | fprintf(stdout,"."); fflush(stdout); | ||
| 162 | |||
| 163 | EVP_MD_CTX_init (&evp); | ||
| 164 | EVP_DigestInit_ex (&evp,EVP_sha384(),NULL); | ||
| 165 | for (i=0;i<1000000;i+=64) | ||
| 166 | EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 167 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 168 | (1000000-i)<64?1000000-i:64); | ||
| 169 | EVP_DigestFinal_ex (&evp,md,NULL); | ||
| 170 | EVP_MD_CTX_cleanup (&evp); | ||
| 171 | |||
| 172 | if (memcmp(md,app_d3,sizeof(app_d3))) | ||
| 173 | { fflush(stdout); | ||
| 174 | fprintf(stderr,"\nTEST 3 of 3 failed.\n"); | ||
| 175 | return 1; | ||
| 176 | } | ||
| 177 | else | ||
| 178 | fprintf(stdout,"."); fflush(stdout); | ||
| 179 | |||
| 180 | fprintf(stdout," passed.\n"); fflush(stdout); | ||
| 181 | |||
| 182 | return 0; | ||
| 183 | } | ||
| 184 | #endif | ||
diff --git a/src/lib/libcrypto/store/Makefile b/src/lib/libcrypto/store/Makefile new file mode 100644 index 0000000000..0dcfd7857a --- /dev/null +++ b/src/lib/libcrypto/store/Makefile | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | # | ||
| 2 | # OpenSSL/crypto/store/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= store | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
| 9 | CFLAG=-g | ||
| 10 | MAKEFILE= Makefile | ||
| 11 | AR= ar r | ||
| 12 | |||
| 13 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 14 | |||
| 15 | GENERAL=Makefile | ||
| 16 | #TEST= storetest.c | ||
| 17 | TEST= | ||
| 18 | APPS= | ||
| 19 | |||
| 20 | LIB=$(TOP)/libcrypto.a | ||
| 21 | LIBSRC= str_err.c str_lib.c str_meth.c str_mem.c | ||
| 22 | LIBOBJ= str_err.o str_lib.o str_meth.o str_mem.o | ||
| 23 | |||
| 24 | SRC= $(LIBSRC) | ||
| 25 | |||
| 26 | #EXHEADER= store.h str_compat.h | ||
| 27 | EXHEADER= store.h | ||
| 28 | HEADER= $(EXHEADER) str_locl.h | ||
| 29 | |||
| 30 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 31 | |||
| 32 | top: | ||
| 33 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 34 | |||
| 35 | all: lib | ||
| 36 | |||
| 37 | lib: $(LIBOBJ) | ||
| 38 | $(AR) $(LIB) $(LIBOBJ) | ||
| 39 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 40 | @touch lib | ||
| 41 | |||
| 42 | files: | ||
| 43 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 44 | |||
| 45 | links: | ||
| 46 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 47 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 48 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 49 | |||
| 50 | install: | ||
| 51 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 52 | @headerlist="$(EXHEADER)"; for i in $$headerlist; \ | ||
| 53 | do \ | ||
| 54 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 55 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 56 | done; | ||
| 57 | |||
| 58 | tags: | ||
| 59 | ctags $(SRC) | ||
| 60 | |||
| 61 | tests: | ||
| 62 | |||
| 63 | lint: | ||
| 64 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 65 | |||
| 66 | depend: | ||
| 67 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 68 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 69 | |||
| 70 | dclean: | ||
| 71 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 72 | mv -f Makefile.new $(MAKEFILE) | ||
| 73 | |||
| 74 | clean: | ||
| 75 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 76 | |||
| 77 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 78 | |||
| 79 | str_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
| 80 | str_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 81 | str_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 82 | str_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 83 | str_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 84 | str_err.o: ../../include/openssl/store.h ../../include/openssl/symhacks.h | ||
| 85 | str_err.o: str_err.c | ||
| 86 | str_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 87 | str_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 88 | str_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 89 | str_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 90 | str_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h | ||
| 91 | str_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 92 | str_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 93 | str_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 94 | str_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 95 | str_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
| 96 | str_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 97 | str_lib.o: ../../include/openssl/store.h ../../include/openssl/symhacks.h | ||
| 98 | str_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 99 | str_lib.o: str_lib.c str_locl.h | ||
| 100 | str_mem.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
| 101 | str_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 102 | str_mem.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 103 | str_mem.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 104 | str_mem.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 105 | str_mem.o: ../../include/openssl/store.h ../../include/openssl/symhacks.h | ||
| 106 | str_mem.o: str_locl.h str_mem.c | ||
| 107 | str_meth.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 108 | str_meth.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | ||
| 109 | str_meth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 110 | str_meth.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 111 | str_meth.o: ../../include/openssl/store.h ../../include/openssl/symhacks.h | ||
| 112 | str_meth.o: str_locl.h str_meth.c | ||
diff --git a/src/lib/libcrypto/store/README b/src/lib/libcrypto/store/README new file mode 100644 index 0000000000..966168f6a5 --- /dev/null +++ b/src/lib/libcrypto/store/README | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | The STORE type | ||
| 2 | ============== | ||
| 3 | |||
| 4 | A STORE, as defined in this code section, is really a rather simple | ||
| 5 | thing which stores objects and per-object associations to a number | ||
| 6 | of attributes. What attributes are supported entirely depends on | ||
| 7 | the particular implementation of a STORE. It has some support for | ||
| 8 | generation of certain objects (for example, keys and CRLs). | ||
| 9 | |||
| 10 | |||
| 11 | Supported object types | ||
| 12 | ---------------------- | ||
| 13 | |||
| 14 | For now, the objects that are supported are the following: | ||
| 15 | |||
| 16 | X.509 certificate | ||
| 17 | X.509 CRL | ||
| 18 | private key | ||
| 19 | public key | ||
| 20 | number | ||
| 21 | arbitrary (application) data | ||
| 22 | |||
| 23 | The intention is that a STORE should be able to store everything | ||
| 24 | needed by an application that wants a cert/key store, as well as | ||
| 25 | the data a CA might need to store (this includes the serial number | ||
| 26 | counter, which explains the support for numbers). | ||
| 27 | |||
| 28 | |||
| 29 | Supported attribute types | ||
| 30 | ------------------------- | ||
| 31 | |||
| 32 | For now, the following attributes are supported: | ||
| 33 | |||
| 34 | Friendly Name - the value is a normal C string | ||
| 35 | Key ID - the value is a 160 bit SHA1 hash | ||
| 36 | Issuer Key ID - the value is a 160 bit SHA1 hash | ||
| 37 | Subject Key ID - the value is a 160 bit SHA1 hash | ||
| 38 | Issuer/Serial Hash - the value is a 160 bit SHA1 hash | ||
| 39 | Issuer - the value is a X509_NAME | ||
| 40 | Serial - the value is a BIGNUM | ||
| 41 | Subject - the value is a X509_NAME | ||
| 42 | Certificate Hash - the value is a 160 bit SHA1 hash | ||
| 43 | Email - the value is a normal C string | ||
| 44 | Filename - the value is a normal C string | ||
| 45 | |||
| 46 | It is expected that these attributes should be enough to support | ||
| 47 | the need from most, if not all, current applications. Applications | ||
| 48 | that need to do certificate verification would typically use Subject | ||
| 49 | Key ID, Issuer/Serial Hash or Subject to look up issuer certificates. | ||
| 50 | S/MIME applications would typically use Email to look up recipient | ||
| 51 | and signer certificates. | ||
| 52 | |||
| 53 | There's added support for combined sets of attributes to search for, | ||
| 54 | with the special OR attribute. | ||
| 55 | |||
| 56 | |||
| 57 | Supported basic functionality | ||
| 58 | ----------------------------- | ||
| 59 | |||
| 60 | The functions that are supported through the STORE type are these: | ||
| 61 | |||
| 62 | generate_object - for example to generate keys and CRLs | ||
| 63 | get_object - to look up one object | ||
| 64 | NOTE: this function is really rather | ||
| 65 | redundant and probably of lesser usage | ||
| 66 | than the list functions | ||
| 67 | store_object - store an object and the attributes | ||
| 68 | associated with it | ||
| 69 | modify_object - modify the attributes associated with | ||
| 70 | a specific object | ||
| 71 | revoke_object - revoke an object | ||
| 72 | NOTE: this only marks an object as | ||
| 73 | invalid, it doesn't remove the object | ||
| 74 | from the database | ||
| 75 | delete_object - remove an object from the database | ||
| 76 | list_object - list objects associated with a given | ||
| 77 | set of attributes | ||
| 78 | NOTE: this is really four functions: | ||
| 79 | list_start, list_next, list_end and | ||
| 80 | list_endp | ||
| 81 | update_store - update the internal data of the store | ||
| 82 | lock_store - lock the store | ||
| 83 | unlock_store - unlock the store | ||
| 84 | |||
| 85 | The list functions need some extra explanation: list_start is | ||
| 86 | used to set up a lookup. That's where the attributes to use in | ||
| 87 | the search are set up. It returns a search context. list_next | ||
| 88 | returns the next object searched for. list_end closes the search. | ||
| 89 | list_endp is used to check if we have reached the end. | ||
| 90 | |||
| 91 | A few words on the store functions as well: update_store is | ||
| 92 | typically used by a CA application to update the internal | ||
| 93 | structure of a database. This may for example involve automatic | ||
| 94 | removal of expired certificates. lock_store and unlock_store | ||
| 95 | are used for locking a store to allow exclusive writes. | ||
diff --git a/src/lib/libcrypto/store/store.h b/src/lib/libcrypto/store/store.h new file mode 100644 index 0000000000..0a28c7d5a2 --- /dev/null +++ b/src/lib/libcrypto/store/store.h | |||
| @@ -0,0 +1,561 @@ | |||
| 1 | /* crypto/store/store.h -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | ||
| 3 | * project 2003. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2003 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * openssl-core@openssl.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_STORE_H | ||
| 60 | #define HEADER_STORE_H | ||
| 61 | |||
| 62 | #include <openssl/opensslconf.h> | ||
| 63 | |||
| 64 | #ifdef OPENSSL_NO_STORE | ||
| 65 | #error STORE is disabled. | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #include <openssl/ossl_typ.h> | ||
| 69 | #ifndef OPENSSL_NO_DEPRECATED | ||
| 70 | #include <openssl/evp.h> | ||
| 71 | #include <openssl/bn.h> | ||
| 72 | #include <openssl/x509.h> | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #ifdef __cplusplus | ||
| 76 | extern "C" { | ||
| 77 | #endif | ||
| 78 | |||
| 79 | /* Already defined in ossl_typ.h */ | ||
| 80 | /* typedef struct store_st STORE; */ | ||
| 81 | /* typedef struct store_method_st STORE_METHOD; */ | ||
| 82 | |||
| 83 | |||
| 84 | /* All the following functions return 0, a negative number or NULL on error. | ||
| 85 | When everything is fine, they return a positive value or a non-NULL | ||
| 86 | pointer, all depending on their purpose. */ | ||
| 87 | |||
| 88 | /* Creators and destructor. */ | ||
| 89 | STORE *STORE_new_method(const STORE_METHOD *method); | ||
| 90 | STORE *STORE_new_engine(ENGINE *engine); | ||
| 91 | void STORE_free(STORE *ui); | ||
| 92 | |||
| 93 | |||
| 94 | /* Give a user interface parametrised control commands. This can be used to | ||
| 95 | send down an integer, a data pointer or a function pointer, as well as | ||
| 96 | be used to get information from a STORE. */ | ||
| 97 | int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void)); | ||
| 98 | |||
| 99 | /* A control to set the directory with keys and certificates. Used by the | ||
| 100 | built-in directory level method. */ | ||
| 101 | #define STORE_CTRL_SET_DIRECTORY 0x0001 | ||
| 102 | /* A control to set a file to load. Used by the built-in file level method. */ | ||
| 103 | #define STORE_CTRL_SET_FILE 0x0002 | ||
| 104 | /* A control to set a configuration file to load. Can be used by any method | ||
| 105 | that wishes to load a configuration file. */ | ||
| 106 | #define STORE_CTRL_SET_CONF_FILE 0x0003 | ||
| 107 | /* A control to set a the section of the loaded configuration file. Can be | ||
| 108 | used by any method that wishes to load a configuration file. */ | ||
| 109 | #define STORE_CTRL_SET_CONF_SECTION 0x0004 | ||
| 110 | |||
| 111 | |||
| 112 | /* Some methods may use extra data */ | ||
| 113 | #define STORE_set_app_data(s,arg) STORE_set_ex_data(s,0,arg) | ||
| 114 | #define STORE_get_app_data(s) STORE_get_ex_data(s,0) | ||
| 115 | int STORE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 116 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
| 117 | int STORE_set_ex_data(STORE *r,int idx,void *arg); | ||
| 118 | void *STORE_get_ex_data(STORE *r, int idx); | ||
| 119 | |||
| 120 | /* Use specific methods instead of the built-in one */ | ||
| 121 | const STORE_METHOD *STORE_get_method(STORE *store); | ||
| 122 | const STORE_METHOD *STORE_set_method(STORE *store, const STORE_METHOD *meth); | ||
| 123 | |||
| 124 | /* The standard OpenSSL methods. */ | ||
| 125 | /* This is the in-memory method. It does everything except revoking and updating, | ||
| 126 | and is of course volatile. It's used by other methods that have an in-memory | ||
| 127 | cache. */ | ||
| 128 | const STORE_METHOD *STORE_Memory(void); | ||
| 129 | #if 0 /* Not yet implemented */ | ||
| 130 | /* This is the directory store. It does everything except revoking and updating, | ||
| 131 | and uses STORE_Memory() to cache things in memory. */ | ||
| 132 | const STORE_METHOD *STORE_Directory(void); | ||
| 133 | /* This is the file store. It does everything except revoking and updating, | ||
| 134 | and uses STORE_Memory() to cache things in memory. Certificates are added | ||
| 135 | to it with the store operation, and it will only get cached certificates. */ | ||
| 136 | const STORE_METHOD *STORE_File(void); | ||
| 137 | #endif | ||
| 138 | |||
| 139 | /* Store functions take a type code for the type of data they should store | ||
| 140 | or fetch */ | ||
| 141 | typedef enum STORE_object_types | ||
| 142 | { | ||
| 143 | STORE_OBJECT_TYPE_X509_CERTIFICATE= 0x01, /* X509 * */ | ||
| 144 | STORE_OBJECT_TYPE_X509_CRL= 0x02, /* X509_CRL * */ | ||
| 145 | STORE_OBJECT_TYPE_PRIVATE_KEY= 0x03, /* EVP_PKEY * */ | ||
| 146 | STORE_OBJECT_TYPE_PUBLIC_KEY= 0x04, /* EVP_PKEY * */ | ||
| 147 | STORE_OBJECT_TYPE_NUMBER= 0x05, /* BIGNUM * */ | ||
| 148 | STORE_OBJECT_TYPE_ARBITRARY= 0x06, /* BUF_MEM * */ | ||
| 149 | STORE_OBJECT_TYPE_NUM= 0x06 /* The amount of known | ||
| 150 | object types */ | ||
| 151 | } STORE_OBJECT_TYPES; | ||
| 152 | /* List of text strings corresponding to the object types. */ | ||
| 153 | extern const char * const STORE_object_type_string[STORE_OBJECT_TYPE_NUM+1]; | ||
| 154 | |||
| 155 | /* Some store functions take a parameter list. Those parameters come with | ||
| 156 | one of the following codes. The comments following the codes below indicate | ||
| 157 | what type the value should be a pointer to. */ | ||
| 158 | typedef enum STORE_params | ||
| 159 | { | ||
| 160 | STORE_PARAM_EVP_TYPE= 0x01, /* int */ | ||
| 161 | STORE_PARAM_BITS= 0x02, /* size_t */ | ||
| 162 | STORE_PARAM_KEY_PARAMETERS= 0x03, /* ??? */ | ||
| 163 | STORE_PARAM_KEY_NO_PARAMETERS= 0x04, /* N/A */ | ||
| 164 | STORE_PARAM_AUTH_PASSPHRASE= 0x05, /* char * */ | ||
| 165 | STORE_PARAM_AUTH_KRB5_TICKET= 0x06, /* void * */ | ||
| 166 | STORE_PARAM_TYPE_NUM= 0x06 /* The amount of known | ||
| 167 | parameter types */ | ||
| 168 | } STORE_PARAM_TYPES; | ||
| 169 | /* Parameter value sizes. -1 means unknown, anything else is the required size. */ | ||
| 170 | extern const int STORE_param_sizes[STORE_PARAM_TYPE_NUM+1]; | ||
| 171 | |||
| 172 | /* Store functions take attribute lists. Those attributes come with codes. | ||
| 173 | The comments following the codes below indicate what type the value should | ||
| 174 | be a pointer to. */ | ||
| 175 | typedef enum STORE_attribs | ||
| 176 | { | ||
| 177 | STORE_ATTR_END= 0x00, | ||
| 178 | STORE_ATTR_FRIENDLYNAME= 0x01, /* C string */ | ||
| 179 | STORE_ATTR_KEYID= 0x02, /* 160 bit string (SHA1) */ | ||
| 180 | STORE_ATTR_ISSUERKEYID= 0x03, /* 160 bit string (SHA1) */ | ||
| 181 | STORE_ATTR_SUBJECTKEYID= 0x04, /* 160 bit string (SHA1) */ | ||
| 182 | STORE_ATTR_ISSUERSERIALHASH= 0x05, /* 160 bit string (SHA1) */ | ||
| 183 | STORE_ATTR_ISSUER= 0x06, /* X509_NAME * */ | ||
| 184 | STORE_ATTR_SERIAL= 0x07, /* BIGNUM * */ | ||
| 185 | STORE_ATTR_SUBJECT= 0x08, /* X509_NAME * */ | ||
| 186 | STORE_ATTR_CERTHASH= 0x09, /* 160 bit string (SHA1) */ | ||
| 187 | STORE_ATTR_EMAIL= 0x0a, /* C string */ | ||
| 188 | STORE_ATTR_FILENAME= 0x0b, /* C string */ | ||
| 189 | STORE_ATTR_TYPE_NUM= 0x0b, /* The amount of known | ||
| 190 | attribute types */ | ||
| 191 | STORE_ATTR_OR= 0xff /* This is a special | ||
| 192 | separator, which | ||
| 193 | expresses the OR | ||
| 194 | operation. */ | ||
| 195 | } STORE_ATTR_TYPES; | ||
| 196 | /* Attribute value sizes. -1 means unknown, anything else is the required size. */ | ||
| 197 | extern const int STORE_attr_sizes[STORE_ATTR_TYPE_NUM+1]; | ||
| 198 | |||
| 199 | typedef enum STORE_certificate_status | ||
| 200 | { | ||
| 201 | STORE_X509_VALID= 0x00, | ||
| 202 | STORE_X509_EXPIRED= 0x01, | ||
| 203 | STORE_X509_SUSPENDED= 0x02, | ||
| 204 | STORE_X509_REVOKED= 0x03 | ||
| 205 | } STORE_CERTIFICATE_STATUS; | ||
| 206 | |||
| 207 | /* Engine store functions will return a structure that contains all the necessary | ||
| 208 | * information, including revokation status for certificates. This is really not | ||
| 209 | * needed for application authors, as the ENGINE framework functions will extract | ||
| 210 | * the OpenSSL-specific information when at all possible. However, for engine | ||
| 211 | * authors, it's crucial to know this structure. */ | ||
| 212 | typedef struct STORE_OBJECT_st | ||
| 213 | { | ||
| 214 | STORE_OBJECT_TYPES type; | ||
| 215 | union | ||
| 216 | { | ||
| 217 | struct | ||
| 218 | { | ||
| 219 | STORE_CERTIFICATE_STATUS status; | ||
| 220 | X509 *certificate; | ||
| 221 | } x509; | ||
| 222 | X509_CRL *crl; | ||
| 223 | EVP_PKEY *key; | ||
| 224 | BIGNUM *number; | ||
| 225 | BUF_MEM *arbitrary; | ||
| 226 | } data; | ||
| 227 | } STORE_OBJECT; | ||
| 228 | DECLARE_STACK_OF(STORE_OBJECT) | ||
| 229 | STORE_OBJECT *STORE_OBJECT_new(void); | ||
| 230 | void STORE_OBJECT_free(STORE_OBJECT *data); | ||
| 231 | |||
| 232 | |||
| 233 | |||
| 234 | /* The following functions handle the storage. They return 0, a negative number | ||
| 235 | or NULL on error, anything else on success. */ | ||
| 236 | X509 *STORE_get_certificate(STORE *e, OPENSSL_ITEM attributes[], | ||
| 237 | OPENSSL_ITEM parameters[]); | ||
| 238 | int STORE_store_certificate(STORE *e, X509 *data, OPENSSL_ITEM attributes[], | ||
| 239 | OPENSSL_ITEM parameters[]); | ||
| 240 | int STORE_modify_certificate(STORE *e, OPENSSL_ITEM search_attributes[], | ||
| 241 | OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], | ||
| 242 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); | ||
| 243 | int STORE_revoke_certificate(STORE *e, OPENSSL_ITEM attributes[], | ||
| 244 | OPENSSL_ITEM parameters[]); | ||
| 245 | int STORE_delete_certificate(STORE *e, OPENSSL_ITEM attributes[], | ||
| 246 | OPENSSL_ITEM parameters[]); | ||
| 247 | void *STORE_list_certificate_start(STORE *e, OPENSSL_ITEM attributes[], | ||
| 248 | OPENSSL_ITEM parameters[]); | ||
| 249 | X509 *STORE_list_certificate_next(STORE *e, void *handle); | ||
| 250 | int STORE_list_certificate_end(STORE *e, void *handle); | ||
| 251 | int STORE_list_certificate_endp(STORE *e, void *handle); | ||
| 252 | EVP_PKEY *STORE_generate_key(STORE *e, OPENSSL_ITEM attributes[], | ||
| 253 | OPENSSL_ITEM parameters[]); | ||
| 254 | EVP_PKEY *STORE_get_private_key(STORE *e, OPENSSL_ITEM attributes[], | ||
| 255 | OPENSSL_ITEM parameters[]); | ||
| 256 | int STORE_store_private_key(STORE *e, EVP_PKEY *data, | ||
| 257 | OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); | ||
| 258 | int STORE_modify_private_key(STORE *e, OPENSSL_ITEM search_attributes[], | ||
| 259 | OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[], | ||
| 260 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); | ||
| 261 | int STORE_revoke_private_key(STORE *e, OPENSSL_ITEM attributes[], | ||
| 262 | OPENSSL_ITEM parameters[]); | ||
| 263 | int STORE_delete_private_key(STORE *e, OPENSSL_ITEM attributes[], | ||
| 264 | OPENSSL_ITEM parameters[]); | ||
| 265 | void *STORE_list_private_key_start(STORE *e, OPENSSL_ITEM attributes[], | ||
| 266 | OPENSSL_ITEM parameters[]); | ||
| 267 | EVP_PKEY *STORE_list_private_key_next(STORE *e, void *handle); | ||
| 268 | int STORE_list_private_key_end(STORE *e, void *handle); | ||
| 269 | int STORE_list_private_key_endp(STORE *e, void *handle); | ||
| 270 | EVP_PKEY *STORE_get_public_key(STORE *e, OPENSSL_ITEM attributes[], | ||
| 271 | OPENSSL_ITEM parameters[]); | ||
| 272 | int STORE_store_public_key(STORE *e, EVP_PKEY *data, OPENSSL_ITEM attributes[], | ||
| 273 | OPENSSL_ITEM parameters[]); | ||
| 274 | int STORE_modify_public_key(STORE *e, OPENSSL_ITEM search_attributes[], | ||
| 275 | OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[], | ||
| 276 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); | ||
| 277 | int STORE_revoke_public_key(STORE *e, OPENSSL_ITEM attributes[], | ||
| 278 | OPENSSL_ITEM parameters[]); | ||
| 279 | int STORE_delete_public_key(STORE *e, OPENSSL_ITEM attributes[], | ||
| 280 | OPENSSL_ITEM parameters[]); | ||
| 281 | void *STORE_list_public_key_start(STORE *e, OPENSSL_ITEM attributes[], | ||
| 282 | OPENSSL_ITEM parameters[]); | ||
| 283 | EVP_PKEY *STORE_list_public_key_next(STORE *e, void *handle); | ||
| 284 | int STORE_list_public_key_end(STORE *e, void *handle); | ||
| 285 | int STORE_list_public_key_endp(STORE *e, void *handle); | ||
| 286 | X509_CRL *STORE_generate_crl(STORE *e, OPENSSL_ITEM attributes[], | ||
| 287 | OPENSSL_ITEM parameters[]); | ||
| 288 | X509_CRL *STORE_get_crl(STORE *e, OPENSSL_ITEM attributes[], | ||
| 289 | OPENSSL_ITEM parameters[]); | ||
| 290 | int STORE_store_crl(STORE *e, X509_CRL *data, OPENSSL_ITEM attributes[], | ||
| 291 | OPENSSL_ITEM parameters[]); | ||
| 292 | int STORE_modify_crl(STORE *e, OPENSSL_ITEM search_attributes[], | ||
| 293 | OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[], | ||
| 294 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); | ||
| 295 | int STORE_delete_crl(STORE *e, OPENSSL_ITEM attributes[], | ||
| 296 | OPENSSL_ITEM parameters[]); | ||
| 297 | void *STORE_list_crl_start(STORE *e, OPENSSL_ITEM attributes[], | ||
| 298 | OPENSSL_ITEM parameters[]); | ||
| 299 | X509_CRL *STORE_list_crl_next(STORE *e, void *handle); | ||
| 300 | int STORE_list_crl_end(STORE *e, void *handle); | ||
| 301 | int STORE_list_crl_endp(STORE *e, void *handle); | ||
| 302 | int STORE_store_number(STORE *e, BIGNUM *data, OPENSSL_ITEM attributes[], | ||
| 303 | OPENSSL_ITEM parameters[]); | ||
| 304 | int STORE_modify_number(STORE *e, OPENSSL_ITEM search_attributes[], | ||
| 305 | OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[], | ||
| 306 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); | ||
| 307 | BIGNUM *STORE_get_number(STORE *e, OPENSSL_ITEM attributes[], | ||
| 308 | OPENSSL_ITEM parameters[]); | ||
| 309 | int STORE_delete_number(STORE *e, OPENSSL_ITEM attributes[], | ||
| 310 | OPENSSL_ITEM parameters[]); | ||
| 311 | int STORE_store_arbitrary(STORE *e, BUF_MEM *data, OPENSSL_ITEM attributes[], | ||
| 312 | OPENSSL_ITEM parameters[]); | ||
| 313 | int STORE_modify_arbitrary(STORE *e, OPENSSL_ITEM search_attributes[], | ||
| 314 | OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[], | ||
| 315 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); | ||
| 316 | BUF_MEM *STORE_get_arbitrary(STORE *e, OPENSSL_ITEM attributes[], | ||
| 317 | OPENSSL_ITEM parameters[]); | ||
| 318 | int STORE_delete_arbitrary(STORE *e, OPENSSL_ITEM attributes[], | ||
| 319 | OPENSSL_ITEM parameters[]); | ||
| 320 | |||
| 321 | |||
| 322 | /* Create and manipulate methods */ | ||
| 323 | STORE_METHOD *STORE_create_method(char *name); | ||
| 324 | void STORE_destroy_method(STORE_METHOD *store_method); | ||
| 325 | |||
| 326 | /* These callback types are use for store handlers */ | ||
| 327 | typedef int (*STORE_INITIALISE_FUNC_PTR)(STORE *); | ||
| 328 | typedef void (*STORE_CLEANUP_FUNC_PTR)(STORE *); | ||
| 329 | typedef STORE_OBJECT *(*STORE_GENERATE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); | ||
| 330 | typedef STORE_OBJECT *(*STORE_GET_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); | ||
| 331 | typedef void *(*STORE_START_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); | ||
| 332 | typedef STORE_OBJECT *(*STORE_NEXT_OBJECT_FUNC_PTR)(STORE *, void *handle); | ||
| 333 | typedef int (*STORE_END_OBJECT_FUNC_PTR)(STORE *, void *handle); | ||
| 334 | typedef int (*STORE_HANDLE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); | ||
| 335 | typedef int (*STORE_STORE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, STORE_OBJECT *data, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); | ||
| 336 | typedef int (*STORE_MODIFY_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM search_attributes[], OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]); | ||
| 337 | typedef int (*STORE_GENERIC_FUNC_PTR)(STORE *, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); | ||
| 338 | typedef int (*STORE_CTRL_FUNC_PTR)(STORE *, int cmd, long l, void *p, void (*f)(void)); | ||
| 339 | |||
| 340 | int STORE_method_set_initialise_function(STORE_METHOD *sm, STORE_INITIALISE_FUNC_PTR init_f); | ||
| 341 | int STORE_method_set_cleanup_function(STORE_METHOD *sm, STORE_CLEANUP_FUNC_PTR clean_f); | ||
| 342 | int STORE_method_set_generate_function(STORE_METHOD *sm, STORE_GENERATE_OBJECT_FUNC_PTR generate_f); | ||
| 343 | int STORE_method_set_get_function(STORE_METHOD *sm, STORE_GET_OBJECT_FUNC_PTR get_f); | ||
| 344 | int STORE_method_set_store_function(STORE_METHOD *sm, STORE_STORE_OBJECT_FUNC_PTR store_f); | ||
| 345 | int STORE_method_set_modify_function(STORE_METHOD *sm, STORE_MODIFY_OBJECT_FUNC_PTR store_f); | ||
| 346 | int STORE_method_set_revoke_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR revoke_f); | ||
| 347 | int STORE_method_set_delete_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR delete_f); | ||
| 348 | int STORE_method_set_list_start_function(STORE_METHOD *sm, STORE_START_OBJECT_FUNC_PTR list_start_f); | ||
| 349 | int STORE_method_set_list_next_function(STORE_METHOD *sm, STORE_NEXT_OBJECT_FUNC_PTR list_next_f); | ||
| 350 | int STORE_method_set_list_end_function(STORE_METHOD *sm, STORE_END_OBJECT_FUNC_PTR list_end_f); | ||
| 351 | int STORE_method_set_update_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR); | ||
| 352 | int STORE_method_set_lock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR); | ||
| 353 | int STORE_method_set_unlock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR); | ||
| 354 | int STORE_method_set_ctrl_function(STORE_METHOD *sm, STORE_CTRL_FUNC_PTR ctrl_f); | ||
| 355 | |||
| 356 | STORE_INITIALISE_FUNC_PTR STORE_method_get_initialise_function(STORE_METHOD *sm); | ||
| 357 | STORE_CLEANUP_FUNC_PTR STORE_method_get_cleanup_function(STORE_METHOD *sm); | ||
| 358 | STORE_GENERATE_OBJECT_FUNC_PTR STORE_method_get_generate_function(STORE_METHOD *sm); | ||
| 359 | STORE_GET_OBJECT_FUNC_PTR STORE_method_get_get_function(STORE_METHOD *sm); | ||
| 360 | STORE_STORE_OBJECT_FUNC_PTR STORE_method_get_store_function(STORE_METHOD *sm); | ||
| 361 | STORE_MODIFY_OBJECT_FUNC_PTR STORE_method_get_modify_function(STORE_METHOD *sm); | ||
| 362 | STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_revoke_function(STORE_METHOD *sm); | ||
| 363 | STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_delete_function(STORE_METHOD *sm); | ||
| 364 | STORE_START_OBJECT_FUNC_PTR STORE_method_get_list_start_function(STORE_METHOD *sm); | ||
| 365 | STORE_NEXT_OBJECT_FUNC_PTR STORE_method_get_list_next_function(STORE_METHOD *sm); | ||
| 366 | STORE_END_OBJECT_FUNC_PTR STORE_method_get_list_end_function(STORE_METHOD *sm); | ||
| 367 | STORE_GENERIC_FUNC_PTR STORE_method_get_update_store_function(STORE_METHOD *sm); | ||
| 368 | STORE_GENERIC_FUNC_PTR STORE_method_get_lock_store_function(STORE_METHOD *sm); | ||
| 369 | STORE_GENERIC_FUNC_PTR STORE_method_get_unlock_store_function(STORE_METHOD *sm); | ||
| 370 | STORE_CTRL_FUNC_PTR STORE_method_get_ctrl_function(STORE_METHOD *sm); | ||
| 371 | |||
| 372 | /* Method helper structures and functions. */ | ||
| 373 | |||
| 374 | /* This structure is the result of parsing through the information in a list | ||
| 375 | of OPENSSL_ITEMs. It stores all the necessary information in a structured | ||
| 376 | way.*/ | ||
| 377 | typedef struct STORE_attr_info_st STORE_ATTR_INFO; | ||
| 378 | |||
| 379 | /* Parse a list of OPENSSL_ITEMs and return a pointer to a STORE_ATTR_INFO. | ||
| 380 | Note that we do this in the list form, since the list of OPENSSL_ITEMs can | ||
| 381 | come in blocks separated with STORE_ATTR_OR. Note that the value returned | ||
| 382 | by STORE_parse_attrs_next() must be freed with STORE_ATTR_INFO_free(). */ | ||
| 383 | void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes); | ||
| 384 | STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle); | ||
| 385 | int STORE_parse_attrs_end(void *handle); | ||
| 386 | int STORE_parse_attrs_endp(void *handle); | ||
| 387 | |||
| 388 | /* Creator and destructor */ | ||
| 389 | STORE_ATTR_INFO *STORE_ATTR_INFO_new(void); | ||
| 390 | int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs); | ||
| 391 | |||
| 392 | /* Manipulators */ | ||
| 393 | char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code); | ||
| 394 | unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs, | ||
| 395 | STORE_ATTR_TYPES code); | ||
| 396 | X509_NAME *STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code); | ||
| 397 | BIGNUM *STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code); | ||
| 398 | int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 399 | char *cstr, size_t cstr_size); | ||
| 400 | int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 401 | unsigned char *sha1str, size_t sha1str_size); | ||
| 402 | int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 403 | X509_NAME *dn); | ||
| 404 | int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 405 | BIGNUM *number); | ||
| 406 | int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 407 | char *cstr, size_t cstr_size); | ||
| 408 | int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 409 | unsigned char *sha1str, size_t sha1str_size); | ||
| 410 | int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 411 | X509_NAME *dn); | ||
| 412 | int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 413 | BIGNUM *number); | ||
| 414 | |||
| 415 | /* Compare on basis of a bit pattern formed by the STORE_ATTR_TYPES values | ||
| 416 | in each contained attribute. */ | ||
| 417 | int STORE_ATTR_INFO_compare(const STORE_ATTR_INFO * const *a, | ||
| 418 | const STORE_ATTR_INFO * const *b); | ||
| 419 | /* Check if the set of attributes in a is within the range of attributes | ||
| 420 | set in b. */ | ||
| 421 | int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b); | ||
| 422 | /* Check if the set of attributes in a are also set in b. */ | ||
| 423 | int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b); | ||
| 424 | /* Same as STORE_ATTR_INFO_in(), but also checks the attribute values. */ | ||
| 425 | int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b); | ||
| 426 | |||
| 427 | |||
| 428 | /* BEGIN ERROR CODES */ | ||
| 429 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 430 | * made after this point may be overwritten when the script is next run. | ||
| 431 | */ | ||
| 432 | void ERR_load_STORE_strings(void); | ||
| 433 | |||
| 434 | /* Error codes for the STORE functions. */ | ||
| 435 | |||
| 436 | /* Function codes. */ | ||
| 437 | #define STORE_F_MEM_DELETE 134 | ||
| 438 | #define STORE_F_MEM_GENERATE 135 | ||
| 439 | #define STORE_F_MEM_LIST_END 168 | ||
| 440 | #define STORE_F_MEM_LIST_NEXT 136 | ||
| 441 | #define STORE_F_MEM_LIST_START 137 | ||
| 442 | #define STORE_F_MEM_MODIFY 169 | ||
| 443 | #define STORE_F_MEM_STORE 138 | ||
| 444 | #define STORE_F_STORE_ATTR_INFO_GET0_CSTR 139 | ||
| 445 | #define STORE_F_STORE_ATTR_INFO_GET0_DN 140 | ||
| 446 | #define STORE_F_STORE_ATTR_INFO_GET0_NUMBER 141 | ||
| 447 | #define STORE_F_STORE_ATTR_INFO_GET0_SHA1STR 142 | ||
| 448 | #define STORE_F_STORE_ATTR_INFO_MODIFY_CSTR 143 | ||
| 449 | #define STORE_F_STORE_ATTR_INFO_MODIFY_DN 144 | ||
| 450 | #define STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER 145 | ||
| 451 | #define STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR 146 | ||
| 452 | #define STORE_F_STORE_ATTR_INFO_SET_CSTR 147 | ||
| 453 | #define STORE_F_STORE_ATTR_INFO_SET_DN 148 | ||
| 454 | #define STORE_F_STORE_ATTR_INFO_SET_NUMBER 149 | ||
| 455 | #define STORE_F_STORE_ATTR_INFO_SET_SHA1STR 150 | ||
| 456 | #define STORE_F_STORE_CERTIFICATE 170 | ||
| 457 | #define STORE_F_STORE_CTRL 161 | ||
| 458 | #define STORE_F_STORE_DELETE_ARBITRARY 158 | ||
| 459 | #define STORE_F_STORE_DELETE_CERTIFICATE 102 | ||
| 460 | #define STORE_F_STORE_DELETE_CRL 103 | ||
| 461 | #define STORE_F_STORE_DELETE_NUMBER 104 | ||
| 462 | #define STORE_F_STORE_DELETE_PRIVATE_KEY 105 | ||
| 463 | #define STORE_F_STORE_DELETE_PUBLIC_KEY 106 | ||
| 464 | #define STORE_F_STORE_GENERATE_CRL 107 | ||
| 465 | #define STORE_F_STORE_GENERATE_KEY 108 | ||
| 466 | #define STORE_F_STORE_GET_ARBITRARY 159 | ||
| 467 | #define STORE_F_STORE_GET_CERTIFICATE 109 | ||
| 468 | #define STORE_F_STORE_GET_CRL 110 | ||
| 469 | #define STORE_F_STORE_GET_NUMBER 111 | ||
| 470 | #define STORE_F_STORE_GET_PRIVATE_KEY 112 | ||
| 471 | #define STORE_F_STORE_GET_PUBLIC_KEY 113 | ||
| 472 | #define STORE_F_STORE_LIST_CERTIFICATE_END 114 | ||
| 473 | #define STORE_F_STORE_LIST_CERTIFICATE_ENDP 153 | ||
| 474 | #define STORE_F_STORE_LIST_CERTIFICATE_NEXT 115 | ||
| 475 | #define STORE_F_STORE_LIST_CERTIFICATE_START 116 | ||
| 476 | #define STORE_F_STORE_LIST_CRL_END 117 | ||
| 477 | #define STORE_F_STORE_LIST_CRL_ENDP 154 | ||
| 478 | #define STORE_F_STORE_LIST_CRL_NEXT 118 | ||
| 479 | #define STORE_F_STORE_LIST_CRL_START 119 | ||
| 480 | #define STORE_F_STORE_LIST_PRIVATE_KEY_END 120 | ||
| 481 | #define STORE_F_STORE_LIST_PRIVATE_KEY_ENDP 155 | ||
| 482 | #define STORE_F_STORE_LIST_PRIVATE_KEY_NEXT 121 | ||
| 483 | #define STORE_F_STORE_LIST_PRIVATE_KEY_START 122 | ||
| 484 | #define STORE_F_STORE_LIST_PUBLIC_KEY_END 123 | ||
| 485 | #define STORE_F_STORE_LIST_PUBLIC_KEY_ENDP 156 | ||
| 486 | #define STORE_F_STORE_LIST_PUBLIC_KEY_NEXT 124 | ||
| 487 | #define STORE_F_STORE_LIST_PUBLIC_KEY_START 125 | ||
| 488 | #define STORE_F_STORE_MODIFY_ARBITRARY 162 | ||
| 489 | #define STORE_F_STORE_MODIFY_CERTIFICATE 163 | ||
| 490 | #define STORE_F_STORE_MODIFY_CRL 164 | ||
| 491 | #define STORE_F_STORE_MODIFY_NUMBER 165 | ||
| 492 | #define STORE_F_STORE_MODIFY_PRIVATE_KEY 166 | ||
| 493 | #define STORE_F_STORE_MODIFY_PUBLIC_KEY 167 | ||
| 494 | #define STORE_F_STORE_NEW_ENGINE 133 | ||
| 495 | #define STORE_F_STORE_NEW_METHOD 132 | ||
| 496 | #define STORE_F_STORE_PARSE_ATTRS_END 151 | ||
| 497 | #define STORE_F_STORE_PARSE_ATTRS_ENDP 172 | ||
| 498 | #define STORE_F_STORE_PARSE_ATTRS_NEXT 152 | ||
| 499 | #define STORE_F_STORE_PARSE_ATTRS_START 171 | ||
| 500 | #define STORE_F_STORE_REVOKE_CERTIFICATE 129 | ||
| 501 | #define STORE_F_STORE_REVOKE_PRIVATE_KEY 130 | ||
| 502 | #define STORE_F_STORE_REVOKE_PUBLIC_KEY 131 | ||
| 503 | #define STORE_F_STORE_STORE_ARBITRARY 157 | ||
| 504 | #define STORE_F_STORE_STORE_CERTIFICATE 100 | ||
| 505 | #define STORE_F_STORE_STORE_CRL 101 | ||
| 506 | #define STORE_F_STORE_STORE_NUMBER 126 | ||
| 507 | #define STORE_F_STORE_STORE_PRIVATE_KEY 127 | ||
| 508 | #define STORE_F_STORE_STORE_PUBLIC_KEY 128 | ||
| 509 | |||
| 510 | /* Reason codes. */ | ||
| 511 | #define STORE_R_ALREADY_HAS_A_VALUE 127 | ||
| 512 | #define STORE_R_FAILED_DELETING_ARBITRARY 132 | ||
| 513 | #define STORE_R_FAILED_DELETING_CERTIFICATE 100 | ||
| 514 | #define STORE_R_FAILED_DELETING_KEY 101 | ||
| 515 | #define STORE_R_FAILED_DELETING_NUMBER 102 | ||
| 516 | #define STORE_R_FAILED_GENERATING_CRL 103 | ||
| 517 | #define STORE_R_FAILED_GENERATING_KEY 104 | ||
| 518 | #define STORE_R_FAILED_GETTING_ARBITRARY 133 | ||
| 519 | #define STORE_R_FAILED_GETTING_CERTIFICATE 105 | ||
| 520 | #define STORE_R_FAILED_GETTING_KEY 106 | ||
| 521 | #define STORE_R_FAILED_GETTING_NUMBER 107 | ||
| 522 | #define STORE_R_FAILED_LISTING_CERTIFICATES 108 | ||
| 523 | #define STORE_R_FAILED_LISTING_KEYS 109 | ||
| 524 | #define STORE_R_FAILED_MODIFYING_ARBITRARY 138 | ||
| 525 | #define STORE_R_FAILED_MODIFYING_CERTIFICATE 139 | ||
| 526 | #define STORE_R_FAILED_MODIFYING_CRL 140 | ||
| 527 | #define STORE_R_FAILED_MODIFYING_NUMBER 141 | ||
| 528 | #define STORE_R_FAILED_MODIFYING_PRIVATE_KEY 142 | ||
| 529 | #define STORE_R_FAILED_MODIFYING_PUBLIC_KEY 143 | ||
| 530 | #define STORE_R_FAILED_REVOKING_CERTIFICATE 110 | ||
| 531 | #define STORE_R_FAILED_REVOKING_KEY 111 | ||
| 532 | #define STORE_R_FAILED_STORING_ARBITRARY 134 | ||
| 533 | #define STORE_R_FAILED_STORING_CERTIFICATE 112 | ||
| 534 | #define STORE_R_FAILED_STORING_KEY 113 | ||
| 535 | #define STORE_R_FAILED_STORING_NUMBER 114 | ||
| 536 | #define STORE_R_NOT_IMPLEMENTED 128 | ||
| 537 | #define STORE_R_NO_CONTROL_FUNCTION 144 | ||
| 538 | #define STORE_R_NO_DELETE_ARBITRARY_FUNCTION 135 | ||
| 539 | #define STORE_R_NO_DELETE_NUMBER_FUNCTION 115 | ||
| 540 | #define STORE_R_NO_DELETE_OBJECT_FUNCTION 116 | ||
| 541 | #define STORE_R_NO_GENERATE_CRL_FUNCTION 117 | ||
| 542 | #define STORE_R_NO_GENERATE_OBJECT_FUNCTION 118 | ||
| 543 | #define STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION 136 | ||
| 544 | #define STORE_R_NO_GET_OBJECT_FUNCTION 119 | ||
| 545 | #define STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION 120 | ||
| 546 | #define STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION 131 | ||
| 547 | #define STORE_R_NO_LIST_OBJECT_END_FUNCTION 121 | ||
| 548 | #define STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION 122 | ||
| 549 | #define STORE_R_NO_LIST_OBJECT_START_FUNCTION 123 | ||
| 550 | #define STORE_R_NO_MODIFY_OBJECT_FUNCTION 145 | ||
| 551 | #define STORE_R_NO_REVOKE_OBJECT_FUNCTION 124 | ||
| 552 | #define STORE_R_NO_STORE 129 | ||
| 553 | #define STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION 137 | ||
| 554 | #define STORE_R_NO_STORE_OBJECT_FUNCTION 125 | ||
| 555 | #define STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION 126 | ||
| 556 | #define STORE_R_NO_VALUE 130 | ||
| 557 | |||
| 558 | #ifdef __cplusplus | ||
| 559 | } | ||
| 560 | #endif | ||
| 561 | #endif | ||
diff --git a/src/lib/libcrypto/store/str_err.c b/src/lib/libcrypto/store/str_err.c new file mode 100644 index 0000000000..924edf0505 --- /dev/null +++ b/src/lib/libcrypto/store/str_err.c | |||
| @@ -0,0 +1,211 @@ | |||
| 1 | /* crypto/store/str_err.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include <openssl/store.h> | ||
| 64 | |||
| 65 | /* BEGIN ERROR CODES */ | ||
| 66 | #ifndef OPENSSL_NO_ERR | ||
| 67 | |||
| 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_STORE,func,0) | ||
| 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_STORE,0,reason) | ||
| 70 | |||
| 71 | static ERR_STRING_DATA STORE_str_functs[]= | ||
| 72 | { | ||
| 73 | {ERR_FUNC(STORE_F_MEM_DELETE), "MEM_DELETE"}, | ||
| 74 | {ERR_FUNC(STORE_F_MEM_GENERATE), "MEM_GENERATE"}, | ||
| 75 | {ERR_FUNC(STORE_F_MEM_LIST_END), "MEM_LIST_END"}, | ||
| 76 | {ERR_FUNC(STORE_F_MEM_LIST_NEXT), "MEM_LIST_NEXT"}, | ||
| 77 | {ERR_FUNC(STORE_F_MEM_LIST_START), "MEM_LIST_START"}, | ||
| 78 | {ERR_FUNC(STORE_F_MEM_MODIFY), "MEM_MODIFY"}, | ||
| 79 | {ERR_FUNC(STORE_F_MEM_STORE), "MEM_STORE"}, | ||
| 80 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_GET0_CSTR), "STORE_ATTR_INFO_get0_cstr"}, | ||
| 81 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_GET0_DN), "STORE_ATTR_INFO_get0_dn"}, | ||
| 82 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_GET0_NUMBER), "STORE_ATTR_INFO_get0_number"}, | ||
| 83 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR), "STORE_ATTR_INFO_get0_sha1str"}, | ||
| 84 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_MODIFY_CSTR), "STORE_ATTR_INFO_modify_cstr"}, | ||
| 85 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_MODIFY_DN), "STORE_ATTR_INFO_modify_dn"}, | ||
| 86 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER), "STORE_ATTR_INFO_modify_number"}, | ||
| 87 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR), "STORE_ATTR_INFO_modify_sha1str"}, | ||
| 88 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_SET_CSTR), "STORE_ATTR_INFO_set_cstr"}, | ||
| 89 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_SET_DN), "STORE_ATTR_INFO_set_dn"}, | ||
| 90 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_SET_NUMBER), "STORE_ATTR_INFO_set_number"}, | ||
| 91 | {ERR_FUNC(STORE_F_STORE_ATTR_INFO_SET_SHA1STR), "STORE_ATTR_INFO_set_sha1str"}, | ||
| 92 | {ERR_FUNC(STORE_F_STORE_CERTIFICATE), "STORE_CERTIFICATE"}, | ||
| 93 | {ERR_FUNC(STORE_F_STORE_CTRL), "STORE_ctrl"}, | ||
| 94 | {ERR_FUNC(STORE_F_STORE_DELETE_ARBITRARY), "STORE_delete_arbitrary"}, | ||
| 95 | {ERR_FUNC(STORE_F_STORE_DELETE_CERTIFICATE), "STORE_delete_certificate"}, | ||
| 96 | {ERR_FUNC(STORE_F_STORE_DELETE_CRL), "STORE_delete_crl"}, | ||
| 97 | {ERR_FUNC(STORE_F_STORE_DELETE_NUMBER), "STORE_delete_number"}, | ||
| 98 | {ERR_FUNC(STORE_F_STORE_DELETE_PRIVATE_KEY), "STORE_delete_private_key"}, | ||
| 99 | {ERR_FUNC(STORE_F_STORE_DELETE_PUBLIC_KEY), "STORE_delete_public_key"}, | ||
| 100 | {ERR_FUNC(STORE_F_STORE_GENERATE_CRL), "STORE_generate_crl"}, | ||
| 101 | {ERR_FUNC(STORE_F_STORE_GENERATE_KEY), "STORE_generate_key"}, | ||
| 102 | {ERR_FUNC(STORE_F_STORE_GET_ARBITRARY), "STORE_get_arbitrary"}, | ||
| 103 | {ERR_FUNC(STORE_F_STORE_GET_CERTIFICATE), "STORE_get_certificate"}, | ||
| 104 | {ERR_FUNC(STORE_F_STORE_GET_CRL), "STORE_get_crl"}, | ||
| 105 | {ERR_FUNC(STORE_F_STORE_GET_NUMBER), "STORE_get_number"}, | ||
| 106 | {ERR_FUNC(STORE_F_STORE_GET_PRIVATE_KEY), "STORE_get_private_key"}, | ||
| 107 | {ERR_FUNC(STORE_F_STORE_GET_PUBLIC_KEY), "STORE_get_public_key"}, | ||
| 108 | {ERR_FUNC(STORE_F_STORE_LIST_CERTIFICATE_END), "STORE_list_certificate_end"}, | ||
| 109 | {ERR_FUNC(STORE_F_STORE_LIST_CERTIFICATE_ENDP), "STORE_list_certificate_endp"}, | ||
| 110 | {ERR_FUNC(STORE_F_STORE_LIST_CERTIFICATE_NEXT), "STORE_list_certificate_next"}, | ||
| 111 | {ERR_FUNC(STORE_F_STORE_LIST_CERTIFICATE_START), "STORE_list_certificate_start"}, | ||
| 112 | {ERR_FUNC(STORE_F_STORE_LIST_CRL_END), "STORE_list_crl_end"}, | ||
| 113 | {ERR_FUNC(STORE_F_STORE_LIST_CRL_ENDP), "STORE_list_crl_endp"}, | ||
| 114 | {ERR_FUNC(STORE_F_STORE_LIST_CRL_NEXT), "STORE_list_crl_next"}, | ||
| 115 | {ERR_FUNC(STORE_F_STORE_LIST_CRL_START), "STORE_list_crl_start"}, | ||
| 116 | {ERR_FUNC(STORE_F_STORE_LIST_PRIVATE_KEY_END), "STORE_list_private_key_end"}, | ||
| 117 | {ERR_FUNC(STORE_F_STORE_LIST_PRIVATE_KEY_ENDP), "STORE_list_private_key_endp"}, | ||
| 118 | {ERR_FUNC(STORE_F_STORE_LIST_PRIVATE_KEY_NEXT), "STORE_list_private_key_next"}, | ||
| 119 | {ERR_FUNC(STORE_F_STORE_LIST_PRIVATE_KEY_START), "STORE_list_private_key_start"}, | ||
| 120 | {ERR_FUNC(STORE_F_STORE_LIST_PUBLIC_KEY_END), "STORE_list_public_key_end"}, | ||
| 121 | {ERR_FUNC(STORE_F_STORE_LIST_PUBLIC_KEY_ENDP), "STORE_list_public_key_endp"}, | ||
| 122 | {ERR_FUNC(STORE_F_STORE_LIST_PUBLIC_KEY_NEXT), "STORE_list_public_key_next"}, | ||
| 123 | {ERR_FUNC(STORE_F_STORE_LIST_PUBLIC_KEY_START), "STORE_list_public_key_start"}, | ||
| 124 | {ERR_FUNC(STORE_F_STORE_MODIFY_ARBITRARY), "STORE_modify_arbitrary"}, | ||
| 125 | {ERR_FUNC(STORE_F_STORE_MODIFY_CERTIFICATE), "STORE_modify_certificate"}, | ||
| 126 | {ERR_FUNC(STORE_F_STORE_MODIFY_CRL), "STORE_modify_crl"}, | ||
| 127 | {ERR_FUNC(STORE_F_STORE_MODIFY_NUMBER), "STORE_modify_number"}, | ||
| 128 | {ERR_FUNC(STORE_F_STORE_MODIFY_PRIVATE_KEY), "STORE_modify_private_key"}, | ||
| 129 | {ERR_FUNC(STORE_F_STORE_MODIFY_PUBLIC_KEY), "STORE_modify_public_key"}, | ||
| 130 | {ERR_FUNC(STORE_F_STORE_NEW_ENGINE), "STORE_new_engine"}, | ||
| 131 | {ERR_FUNC(STORE_F_STORE_NEW_METHOD), "STORE_new_method"}, | ||
| 132 | {ERR_FUNC(STORE_F_STORE_PARSE_ATTRS_END), "STORE_parse_attrs_end"}, | ||
| 133 | {ERR_FUNC(STORE_F_STORE_PARSE_ATTRS_ENDP), "STORE_parse_attrs_endp"}, | ||
| 134 | {ERR_FUNC(STORE_F_STORE_PARSE_ATTRS_NEXT), "STORE_parse_attrs_next"}, | ||
| 135 | {ERR_FUNC(STORE_F_STORE_PARSE_ATTRS_START), "STORE_parse_attrs_start"}, | ||
| 136 | {ERR_FUNC(STORE_F_STORE_REVOKE_CERTIFICATE), "STORE_revoke_certificate"}, | ||
| 137 | {ERR_FUNC(STORE_F_STORE_REVOKE_PRIVATE_KEY), "STORE_revoke_private_key"}, | ||
| 138 | {ERR_FUNC(STORE_F_STORE_REVOKE_PUBLIC_KEY), "STORE_revoke_public_key"}, | ||
| 139 | {ERR_FUNC(STORE_F_STORE_STORE_ARBITRARY), "STORE_store_arbitrary"}, | ||
| 140 | {ERR_FUNC(STORE_F_STORE_STORE_CERTIFICATE), "STORE_store_certificate"}, | ||
| 141 | {ERR_FUNC(STORE_F_STORE_STORE_CRL), "STORE_store_crl"}, | ||
| 142 | {ERR_FUNC(STORE_F_STORE_STORE_NUMBER), "STORE_store_number"}, | ||
| 143 | {ERR_FUNC(STORE_F_STORE_STORE_PRIVATE_KEY), "STORE_store_private_key"}, | ||
| 144 | {ERR_FUNC(STORE_F_STORE_STORE_PUBLIC_KEY), "STORE_store_public_key"}, | ||
| 145 | {0,NULL} | ||
| 146 | }; | ||
| 147 | |||
| 148 | static ERR_STRING_DATA STORE_str_reasons[]= | ||
| 149 | { | ||
| 150 | {ERR_REASON(STORE_R_ALREADY_HAS_A_VALUE) ,"already has a value"}, | ||
| 151 | {ERR_REASON(STORE_R_FAILED_DELETING_ARBITRARY),"failed deleting arbitrary"}, | ||
| 152 | {ERR_REASON(STORE_R_FAILED_DELETING_CERTIFICATE),"failed deleting certificate"}, | ||
| 153 | {ERR_REASON(STORE_R_FAILED_DELETING_KEY) ,"failed deleting key"}, | ||
| 154 | {ERR_REASON(STORE_R_FAILED_DELETING_NUMBER),"failed deleting number"}, | ||
| 155 | {ERR_REASON(STORE_R_FAILED_GENERATING_CRL),"failed generating crl"}, | ||
| 156 | {ERR_REASON(STORE_R_FAILED_GENERATING_KEY),"failed generating key"}, | ||
| 157 | {ERR_REASON(STORE_R_FAILED_GETTING_ARBITRARY),"failed getting arbitrary"}, | ||
| 158 | {ERR_REASON(STORE_R_FAILED_GETTING_CERTIFICATE),"failed getting certificate"}, | ||
| 159 | {ERR_REASON(STORE_R_FAILED_GETTING_KEY) ,"failed getting key"}, | ||
| 160 | {ERR_REASON(STORE_R_FAILED_GETTING_NUMBER),"failed getting number"}, | ||
| 161 | {ERR_REASON(STORE_R_FAILED_LISTING_CERTIFICATES),"failed listing certificates"}, | ||
| 162 | {ERR_REASON(STORE_R_FAILED_LISTING_KEYS) ,"failed listing keys"}, | ||
| 163 | {ERR_REASON(STORE_R_FAILED_MODIFYING_ARBITRARY),"failed modifying arbitrary"}, | ||
| 164 | {ERR_REASON(STORE_R_FAILED_MODIFYING_CERTIFICATE),"failed modifying certificate"}, | ||
| 165 | {ERR_REASON(STORE_R_FAILED_MODIFYING_CRL),"failed modifying crl"}, | ||
| 166 | {ERR_REASON(STORE_R_FAILED_MODIFYING_NUMBER),"failed modifying number"}, | ||
| 167 | {ERR_REASON(STORE_R_FAILED_MODIFYING_PRIVATE_KEY),"failed modifying private key"}, | ||
| 168 | {ERR_REASON(STORE_R_FAILED_MODIFYING_PUBLIC_KEY),"failed modifying public key"}, | ||
| 169 | {ERR_REASON(STORE_R_FAILED_REVOKING_CERTIFICATE),"failed revoking certificate"}, | ||
| 170 | {ERR_REASON(STORE_R_FAILED_REVOKING_KEY) ,"failed revoking key"}, | ||
| 171 | {ERR_REASON(STORE_R_FAILED_STORING_ARBITRARY),"failed storing arbitrary"}, | ||
| 172 | {ERR_REASON(STORE_R_FAILED_STORING_CERTIFICATE),"failed storing certificate"}, | ||
| 173 | {ERR_REASON(STORE_R_FAILED_STORING_KEY) ,"failed storing key"}, | ||
| 174 | {ERR_REASON(STORE_R_FAILED_STORING_NUMBER),"failed storing number"}, | ||
| 175 | {ERR_REASON(STORE_R_NOT_IMPLEMENTED) ,"not implemented"}, | ||
| 176 | {ERR_REASON(STORE_R_NO_CONTROL_FUNCTION) ,"no control function"}, | ||
| 177 | {ERR_REASON(STORE_R_NO_DELETE_ARBITRARY_FUNCTION),"no delete arbitrary function"}, | ||
| 178 | {ERR_REASON(STORE_R_NO_DELETE_NUMBER_FUNCTION),"no delete number function"}, | ||
| 179 | {ERR_REASON(STORE_R_NO_DELETE_OBJECT_FUNCTION),"no delete object function"}, | ||
| 180 | {ERR_REASON(STORE_R_NO_GENERATE_CRL_FUNCTION),"no generate crl function"}, | ||
| 181 | {ERR_REASON(STORE_R_NO_GENERATE_OBJECT_FUNCTION),"no generate object function"}, | ||
| 182 | {ERR_REASON(STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION),"no get object arbitrary function"}, | ||
| 183 | {ERR_REASON(STORE_R_NO_GET_OBJECT_FUNCTION),"no get object function"}, | ||
| 184 | {ERR_REASON(STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION),"no get object number function"}, | ||
| 185 | {ERR_REASON(STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION),"no list object endp function"}, | ||
| 186 | {ERR_REASON(STORE_R_NO_LIST_OBJECT_END_FUNCTION),"no list object end function"}, | ||
| 187 | {ERR_REASON(STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION),"no list object next function"}, | ||
| 188 | {ERR_REASON(STORE_R_NO_LIST_OBJECT_START_FUNCTION),"no list object start function"}, | ||
| 189 | {ERR_REASON(STORE_R_NO_MODIFY_OBJECT_FUNCTION),"no modify object function"}, | ||
| 190 | {ERR_REASON(STORE_R_NO_REVOKE_OBJECT_FUNCTION),"no revoke object function"}, | ||
| 191 | {ERR_REASON(STORE_R_NO_STORE) ,"no store"}, | ||
| 192 | {ERR_REASON(STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION),"no store object arbitrary function"}, | ||
| 193 | {ERR_REASON(STORE_R_NO_STORE_OBJECT_FUNCTION),"no store object function"}, | ||
| 194 | {ERR_REASON(STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION),"no store object number function"}, | ||
| 195 | {ERR_REASON(STORE_R_NO_VALUE) ,"no value"}, | ||
| 196 | {0,NULL} | ||
| 197 | }; | ||
| 198 | |||
| 199 | #endif | ||
| 200 | |||
| 201 | void ERR_load_STORE_strings(void) | ||
| 202 | { | ||
| 203 | #ifndef OPENSSL_NO_ERR | ||
| 204 | |||
| 205 | if (ERR_func_error_string(STORE_str_functs[0].error) == NULL) | ||
| 206 | { | ||
| 207 | ERR_load_strings(0,STORE_str_functs); | ||
| 208 | ERR_load_strings(0,STORE_str_reasons); | ||
| 209 | } | ||
| 210 | #endif | ||
| 211 | } | ||
diff --git a/src/lib/libcrypto/store/str_lib.c b/src/lib/libcrypto/store/str_lib.c new file mode 100644 index 0000000000..f1dbcbd0e0 --- /dev/null +++ b/src/lib/libcrypto/store/str_lib.c | |||
| @@ -0,0 +1,1828 @@ | |||
| 1 | /* crypto/store/str_lib.c -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | ||
| 3 | * project 2003. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2003 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * openssl-core@openssl.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <string.h> | ||
| 60 | #include <openssl/bn.h> | ||
| 61 | #include <openssl/err.h> | ||
| 62 | #ifndef OPENSSL_NO_ENGINE | ||
| 63 | #include <openssl/engine.h> | ||
| 64 | #endif | ||
| 65 | #include <openssl/sha.h> | ||
| 66 | #include <openssl/x509.h> | ||
| 67 | #include "str_locl.h" | ||
| 68 | |||
| 69 | const char * const STORE_object_type_string[STORE_OBJECT_TYPE_NUM+1] = | ||
| 70 | { | ||
| 71 | 0, | ||
| 72 | "X.509 Certificate", | ||
| 73 | "X.509 CRL", | ||
| 74 | "Private Key", | ||
| 75 | "Public Key", | ||
| 76 | "Number", | ||
| 77 | "Arbitrary Data" | ||
| 78 | }; | ||
| 79 | |||
| 80 | const int STORE_param_sizes[STORE_PARAM_TYPE_NUM+1] = | ||
| 81 | { | ||
| 82 | 0, | ||
| 83 | sizeof(int), /* EVP_TYPE */ | ||
| 84 | sizeof(size_t), /* BITS */ | ||
| 85 | -1, /* KEY_PARAMETERS */ | ||
| 86 | 0 /* KEY_NO_PARAMETERS */ | ||
| 87 | }; | ||
| 88 | |||
| 89 | const int STORE_attr_sizes[STORE_ATTR_TYPE_NUM+1] = | ||
| 90 | { | ||
| 91 | 0, | ||
| 92 | -1, /* FRIENDLYNAME: C string */ | ||
| 93 | SHA_DIGEST_LENGTH, /* KEYID: SHA1 digest, 160 bits */ | ||
| 94 | SHA_DIGEST_LENGTH, /* ISSUERKEYID: SHA1 digest, 160 bits */ | ||
| 95 | SHA_DIGEST_LENGTH, /* SUBJECTKEYID: SHA1 digest, 160 bits */ | ||
| 96 | SHA_DIGEST_LENGTH, /* ISSUERSERIALHASH: SHA1 digest, 160 bits */ | ||
| 97 | sizeof(X509_NAME *), /* ISSUER: X509_NAME * */ | ||
| 98 | sizeof(BIGNUM *), /* SERIAL: BIGNUM * */ | ||
| 99 | sizeof(X509_NAME *), /* SUBJECT: X509_NAME * */ | ||
| 100 | SHA_DIGEST_LENGTH, /* CERTHASH: SHA1 digest, 160 bits */ | ||
| 101 | -1, /* EMAIL: C string */ | ||
| 102 | -1, /* FILENAME: C string */ | ||
| 103 | }; | ||
| 104 | |||
| 105 | STORE *STORE_new_method(const STORE_METHOD *method) | ||
| 106 | { | ||
| 107 | STORE *ret; | ||
| 108 | |||
| 109 | if (method == NULL) | ||
| 110 | { | ||
| 111 | STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_PASSED_NULL_PARAMETER); | ||
| 112 | return NULL; | ||
| 113 | } | ||
| 114 | |||
| 115 | ret=(STORE *)OPENSSL_malloc(sizeof(STORE)); | ||
| 116 | if (ret == NULL) | ||
| 117 | { | ||
| 118 | STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_MALLOC_FAILURE); | ||
| 119 | return NULL; | ||
| 120 | } | ||
| 121 | |||
| 122 | ret->meth=method; | ||
| 123 | |||
| 124 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_STORE, ret, &ret->ex_data); | ||
| 125 | if (ret->meth->init && !ret->meth->init(ret)) | ||
| 126 | { | ||
| 127 | STORE_free(ret); | ||
| 128 | ret = NULL; | ||
| 129 | } | ||
| 130 | return ret; | ||
| 131 | } | ||
| 132 | |||
| 133 | STORE *STORE_new_engine(ENGINE *engine) | ||
| 134 | { | ||
| 135 | STORE *ret = NULL; | ||
| 136 | ENGINE *e = engine; | ||
| 137 | const STORE_METHOD *meth = 0; | ||
| 138 | |||
| 139 | #ifdef OPENSSL_NO_ENGINE | ||
| 140 | e = NULL; | ||
| 141 | #else | ||
| 142 | if (engine) | ||
| 143 | { | ||
| 144 | if (!ENGINE_init(engine)) | ||
| 145 | { | ||
| 146 | STOREerr(STORE_F_STORE_NEW_ENGINE, ERR_R_ENGINE_LIB); | ||
| 147 | return NULL; | ||
| 148 | } | ||
| 149 | e = engine; | ||
| 150 | } | ||
| 151 | else | ||
| 152 | { | ||
| 153 | STOREerr(STORE_F_STORE_NEW_ENGINE,ERR_R_PASSED_NULL_PARAMETER); | ||
| 154 | return NULL; | ||
| 155 | } | ||
| 156 | if(e) | ||
| 157 | { | ||
| 158 | meth = ENGINE_get_STORE(e); | ||
| 159 | if(!meth) | ||
| 160 | { | ||
| 161 | STOREerr(STORE_F_STORE_NEW_ENGINE, | ||
| 162 | ERR_R_ENGINE_LIB); | ||
| 163 | ENGINE_finish(e); | ||
| 164 | return NULL; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | #endif | ||
| 168 | |||
| 169 | ret = STORE_new_method(meth); | ||
| 170 | if (ret == NULL) | ||
| 171 | { | ||
| 172 | STOREerr(STORE_F_STORE_NEW_ENGINE,ERR_R_STORE_LIB); | ||
| 173 | return NULL; | ||
| 174 | } | ||
| 175 | |||
| 176 | ret->engine = e; | ||
| 177 | |||
| 178 | return(ret); | ||
| 179 | } | ||
| 180 | |||
| 181 | void STORE_free(STORE *store) | ||
| 182 | { | ||
| 183 | if (store == NULL) | ||
| 184 | return; | ||
| 185 | if (store->meth->clean) | ||
| 186 | store->meth->clean(store); | ||
| 187 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_STORE, store, &store->ex_data); | ||
| 188 | OPENSSL_free(store); | ||
| 189 | } | ||
| 190 | |||
| 191 | int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void)) | ||
| 192 | { | ||
| 193 | if (store == NULL) | ||
| 194 | { | ||
| 195 | STOREerr(STORE_F_STORE_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
| 196 | return 0; | ||
| 197 | } | ||
| 198 | if (store->meth->ctrl) | ||
| 199 | return store->meth->ctrl(store, cmd, i, p, f); | ||
| 200 | STOREerr(STORE_F_STORE_CTRL,STORE_R_NO_CONTROL_FUNCTION); | ||
| 201 | return 0; | ||
| 202 | } | ||
| 203 | |||
| 204 | |||
| 205 | int STORE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 206 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
| 207 | { | ||
| 208 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_STORE, argl, argp, | ||
| 209 | new_func, dup_func, free_func); | ||
| 210 | } | ||
| 211 | |||
| 212 | int STORE_set_ex_data(STORE *r, int idx, void *arg) | ||
| 213 | { | ||
| 214 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); | ||
| 215 | } | ||
| 216 | |||
| 217 | void *STORE_get_ex_data(STORE *r, int idx) | ||
| 218 | { | ||
| 219 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); | ||
| 220 | } | ||
| 221 | |||
| 222 | const STORE_METHOD *STORE_get_method(STORE *store) | ||
| 223 | { | ||
| 224 | return store->meth; | ||
| 225 | } | ||
| 226 | |||
| 227 | const STORE_METHOD *STORE_set_method(STORE *store, const STORE_METHOD *meth) | ||
| 228 | { | ||
| 229 | store->meth=meth; | ||
| 230 | return store->meth; | ||
| 231 | } | ||
| 232 | |||
| 233 | |||
| 234 | /* API helpers */ | ||
| 235 | |||
| 236 | #define check_store(s,fncode,fnname,fnerrcode) \ | ||
| 237 | do \ | ||
| 238 | { \ | ||
| 239 | if ((s) == NULL || (s)->meth == NULL) \ | ||
| 240 | { \ | ||
| 241 | STOREerr((fncode), ERR_R_PASSED_NULL_PARAMETER); \ | ||
| 242 | return 0; \ | ||
| 243 | } \ | ||
| 244 | if ((s)->meth->fnname == NULL) \ | ||
| 245 | { \ | ||
| 246 | STOREerr((fncode), (fnerrcode)); \ | ||
| 247 | return 0; \ | ||
| 248 | } \ | ||
| 249 | } \ | ||
| 250 | while(0) | ||
| 251 | |||
| 252 | /* API functions */ | ||
| 253 | |||
| 254 | X509 *STORE_get_certificate(STORE *s, OPENSSL_ITEM attributes[], | ||
| 255 | OPENSSL_ITEM parameters[]) | ||
| 256 | { | ||
| 257 | STORE_OBJECT *object; | ||
| 258 | X509 *x; | ||
| 259 | |||
| 260 | check_store(s,STORE_F_STORE_GET_CERTIFICATE, | ||
| 261 | get_object,STORE_R_NO_GET_OBJECT_FUNCTION); | ||
| 262 | |||
| 263 | object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE, | ||
| 264 | attributes, parameters); | ||
| 265 | if (!object || !object->data.x509.certificate) | ||
| 266 | { | ||
| 267 | STOREerr(STORE_F_STORE_GET_CERTIFICATE, | ||
| 268 | STORE_R_FAILED_GETTING_CERTIFICATE); | ||
| 269 | return 0; | ||
| 270 | } | ||
| 271 | CRYPTO_add(&object->data.x509.certificate->references,1,CRYPTO_LOCK_X509); | ||
| 272 | #ifdef REF_PRINT | ||
| 273 | REF_PRINT("X509",data); | ||
| 274 | #endif | ||
| 275 | x = object->data.x509.certificate; | ||
| 276 | STORE_OBJECT_free(object); | ||
| 277 | return x; | ||
| 278 | } | ||
| 279 | |||
| 280 | int STORE_store_certificate(STORE *s, X509 *data, OPENSSL_ITEM attributes[], | ||
| 281 | OPENSSL_ITEM parameters[]) | ||
| 282 | { | ||
| 283 | STORE_OBJECT *object; | ||
| 284 | int i; | ||
| 285 | |||
| 286 | check_store(s,STORE_F_STORE_CERTIFICATE, | ||
| 287 | store_object,STORE_R_NO_STORE_OBJECT_FUNCTION); | ||
| 288 | |||
| 289 | object = STORE_OBJECT_new(); | ||
| 290 | if (!object) | ||
| 291 | { | ||
| 292 | STOREerr(STORE_F_STORE_STORE_CERTIFICATE, | ||
| 293 | ERR_R_MALLOC_FAILURE); | ||
| 294 | return 0; | ||
| 295 | } | ||
| 296 | |||
| 297 | CRYPTO_add(&data->references,1,CRYPTO_LOCK_X509); | ||
| 298 | #ifdef REF_PRINT | ||
| 299 | REF_PRINT("X509",data); | ||
| 300 | #endif | ||
| 301 | object->data.x509.certificate = data; | ||
| 302 | |||
| 303 | i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE, | ||
| 304 | object, attributes, parameters); | ||
| 305 | |||
| 306 | STORE_OBJECT_free(object); | ||
| 307 | |||
| 308 | if (!i) | ||
| 309 | { | ||
| 310 | STOREerr(STORE_F_STORE_STORE_CERTIFICATE, | ||
| 311 | STORE_R_FAILED_STORING_CERTIFICATE); | ||
| 312 | return 0; | ||
| 313 | } | ||
| 314 | return 1; | ||
| 315 | } | ||
| 316 | |||
| 317 | int STORE_modify_certificate(STORE *s, OPENSSL_ITEM search_attributes[], | ||
| 318 | OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], | ||
| 319 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]) | ||
| 320 | { | ||
| 321 | check_store(s,STORE_F_STORE_MODIFY_CERTIFICATE, | ||
| 322 | modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION); | ||
| 323 | |||
| 324 | if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE, | ||
| 325 | search_attributes, add_attributes, modify_attributes, | ||
| 326 | delete_attributes, parameters)) | ||
| 327 | { | ||
| 328 | STOREerr(STORE_F_STORE_MODIFY_CERTIFICATE, | ||
| 329 | STORE_R_FAILED_MODIFYING_CERTIFICATE); | ||
| 330 | return 0; | ||
| 331 | } | ||
| 332 | return 1; | ||
| 333 | } | ||
| 334 | |||
| 335 | int STORE_revoke_certificate(STORE *s, OPENSSL_ITEM attributes[], | ||
| 336 | OPENSSL_ITEM parameters[]) | ||
| 337 | { | ||
| 338 | check_store(s,STORE_F_STORE_REVOKE_CERTIFICATE, | ||
| 339 | revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION); | ||
| 340 | |||
| 341 | if (!s->meth->revoke_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE, | ||
| 342 | attributes, parameters)) | ||
| 343 | { | ||
| 344 | STOREerr(STORE_F_STORE_REVOKE_CERTIFICATE, | ||
| 345 | STORE_R_FAILED_REVOKING_CERTIFICATE); | ||
| 346 | return 0; | ||
| 347 | } | ||
| 348 | return 1; | ||
| 349 | } | ||
| 350 | |||
| 351 | int STORE_delete_certificate(STORE *s, OPENSSL_ITEM attributes[], | ||
| 352 | OPENSSL_ITEM parameters[]) | ||
| 353 | { | ||
| 354 | check_store(s,STORE_F_STORE_DELETE_CERTIFICATE, | ||
| 355 | delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION); | ||
| 356 | |||
| 357 | if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE, | ||
| 358 | attributes, parameters)) | ||
| 359 | { | ||
| 360 | STOREerr(STORE_F_STORE_DELETE_CERTIFICATE, | ||
| 361 | STORE_R_FAILED_DELETING_CERTIFICATE); | ||
| 362 | return 0; | ||
| 363 | } | ||
| 364 | return 1; | ||
| 365 | } | ||
| 366 | |||
| 367 | void *STORE_list_certificate_start(STORE *s, OPENSSL_ITEM attributes[], | ||
| 368 | OPENSSL_ITEM parameters[]) | ||
| 369 | { | ||
| 370 | void *handle; | ||
| 371 | |||
| 372 | check_store(s,STORE_F_STORE_LIST_CERTIFICATE_START, | ||
| 373 | list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION); | ||
| 374 | |||
| 375 | handle = s->meth->list_object_start(s, | ||
| 376 | STORE_OBJECT_TYPE_X509_CERTIFICATE, attributes, parameters); | ||
| 377 | if (!handle) | ||
| 378 | { | ||
| 379 | STOREerr(STORE_F_STORE_LIST_CERTIFICATE_START, | ||
| 380 | STORE_R_FAILED_LISTING_CERTIFICATES); | ||
| 381 | return 0; | ||
| 382 | } | ||
| 383 | return handle; | ||
| 384 | } | ||
| 385 | |||
| 386 | X509 *STORE_list_certificate_next(STORE *s, void *handle) | ||
| 387 | { | ||
| 388 | STORE_OBJECT *object; | ||
| 389 | X509 *x; | ||
| 390 | |||
| 391 | check_store(s,STORE_F_STORE_LIST_CERTIFICATE_NEXT, | ||
| 392 | list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION); | ||
| 393 | |||
| 394 | object = s->meth->list_object_next(s, handle); | ||
| 395 | if (!object || !object->data.x509.certificate) | ||
| 396 | { | ||
| 397 | STOREerr(STORE_F_STORE_LIST_CERTIFICATE_NEXT, | ||
| 398 | STORE_R_FAILED_LISTING_CERTIFICATES); | ||
| 399 | return 0; | ||
| 400 | } | ||
| 401 | CRYPTO_add(&object->data.x509.certificate->references,1,CRYPTO_LOCK_X509); | ||
| 402 | #ifdef REF_PRINT | ||
| 403 | REF_PRINT("X509",data); | ||
| 404 | #endif | ||
| 405 | x = object->data.x509.certificate; | ||
| 406 | STORE_OBJECT_free(object); | ||
| 407 | return x; | ||
| 408 | } | ||
| 409 | |||
| 410 | int STORE_list_certificate_end(STORE *s, void *handle) | ||
| 411 | { | ||
| 412 | check_store(s,STORE_F_STORE_LIST_CERTIFICATE_END, | ||
| 413 | list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION); | ||
| 414 | |||
| 415 | if (!s->meth->list_object_end(s, handle)) | ||
| 416 | { | ||
| 417 | STOREerr(STORE_F_STORE_LIST_CERTIFICATE_END, | ||
| 418 | STORE_R_FAILED_LISTING_CERTIFICATES); | ||
| 419 | return 0; | ||
| 420 | } | ||
| 421 | return 1; | ||
| 422 | } | ||
| 423 | |||
| 424 | int STORE_list_certificate_endp(STORE *s, void *handle) | ||
| 425 | { | ||
| 426 | check_store(s,STORE_F_STORE_LIST_CERTIFICATE_ENDP, | ||
| 427 | list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION); | ||
| 428 | |||
| 429 | if (!s->meth->list_object_endp(s, handle)) | ||
| 430 | { | ||
| 431 | STOREerr(STORE_F_STORE_LIST_CERTIFICATE_ENDP, | ||
| 432 | STORE_R_FAILED_LISTING_CERTIFICATES); | ||
| 433 | return 0; | ||
| 434 | } | ||
| 435 | return 1; | ||
| 436 | } | ||
| 437 | |||
| 438 | EVP_PKEY *STORE_generate_key(STORE *s, OPENSSL_ITEM attributes[], | ||
| 439 | OPENSSL_ITEM parameters[]) | ||
| 440 | { | ||
| 441 | STORE_OBJECT *object; | ||
| 442 | EVP_PKEY *pkey; | ||
| 443 | |||
| 444 | check_store(s,STORE_F_STORE_GENERATE_KEY, | ||
| 445 | generate_object,STORE_R_NO_GENERATE_OBJECT_FUNCTION); | ||
| 446 | |||
| 447 | object = s->meth->generate_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, | ||
| 448 | attributes, parameters); | ||
| 449 | if (!object || !object->data.key) | ||
| 450 | { | ||
| 451 | STOREerr(STORE_F_STORE_GENERATE_KEY, | ||
| 452 | STORE_R_FAILED_GENERATING_KEY); | ||
| 453 | return 0; | ||
| 454 | } | ||
| 455 | CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
| 456 | #ifdef REF_PRINT | ||
| 457 | REF_PRINT("EVP_PKEY",data); | ||
| 458 | #endif | ||
| 459 | pkey = object->data.key; | ||
| 460 | STORE_OBJECT_free(object); | ||
| 461 | return pkey; | ||
| 462 | } | ||
| 463 | |||
| 464 | EVP_PKEY *STORE_get_private_key(STORE *s, OPENSSL_ITEM attributes[], | ||
| 465 | OPENSSL_ITEM parameters[]) | ||
| 466 | { | ||
| 467 | STORE_OBJECT *object; | ||
| 468 | EVP_PKEY *pkey; | ||
| 469 | |||
| 470 | check_store(s,STORE_F_STORE_GET_PRIVATE_KEY, | ||
| 471 | get_object,STORE_R_NO_GET_OBJECT_FUNCTION); | ||
| 472 | |||
| 473 | object = s->meth->get_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, | ||
| 474 | attributes, parameters); | ||
| 475 | if (!object || !object->data.key || !object->data.key) | ||
| 476 | { | ||
| 477 | STOREerr(STORE_F_STORE_GET_PRIVATE_KEY, | ||
| 478 | STORE_R_FAILED_GETTING_KEY); | ||
| 479 | return 0; | ||
| 480 | } | ||
| 481 | CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
| 482 | #ifdef REF_PRINT | ||
| 483 | REF_PRINT("EVP_PKEY",data); | ||
| 484 | #endif | ||
| 485 | pkey = object->data.key; | ||
| 486 | STORE_OBJECT_free(object); | ||
| 487 | return pkey; | ||
| 488 | } | ||
| 489 | |||
| 490 | int STORE_store_private_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[], | ||
| 491 | OPENSSL_ITEM parameters[]) | ||
| 492 | { | ||
| 493 | STORE_OBJECT *object; | ||
| 494 | int i; | ||
| 495 | |||
| 496 | check_store(s,STORE_F_STORE_STORE_PRIVATE_KEY, | ||
| 497 | store_object,STORE_R_NO_STORE_OBJECT_FUNCTION); | ||
| 498 | |||
| 499 | object = STORE_OBJECT_new(); | ||
| 500 | if (!object) | ||
| 501 | { | ||
| 502 | STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, | ||
| 503 | ERR_R_MALLOC_FAILURE); | ||
| 504 | return 0; | ||
| 505 | } | ||
| 506 | object->data.key = EVP_PKEY_new(); | ||
| 507 | if (!object->data.key) | ||
| 508 | { | ||
| 509 | STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, | ||
| 510 | ERR_R_MALLOC_FAILURE); | ||
| 511 | return 0; | ||
| 512 | } | ||
| 513 | |||
| 514 | CRYPTO_add(&data->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
| 515 | #ifdef REF_PRINT | ||
| 516 | REF_PRINT("EVP_PKEY",data); | ||
| 517 | #endif | ||
| 518 | object->data.key = data; | ||
| 519 | |||
| 520 | i = s->meth->store_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, object, | ||
| 521 | attributes, parameters); | ||
| 522 | |||
| 523 | STORE_OBJECT_free(object); | ||
| 524 | |||
| 525 | if (!i) | ||
| 526 | { | ||
| 527 | STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, | ||
| 528 | STORE_R_FAILED_STORING_KEY); | ||
| 529 | return 0; | ||
| 530 | } | ||
| 531 | return i; | ||
| 532 | } | ||
| 533 | |||
| 534 | int STORE_modify_private_key(STORE *s, OPENSSL_ITEM search_attributes[], | ||
| 535 | OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], | ||
| 536 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]) | ||
| 537 | { | ||
| 538 | check_store(s,STORE_F_STORE_MODIFY_PRIVATE_KEY, | ||
| 539 | modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION); | ||
| 540 | |||
| 541 | if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, | ||
| 542 | search_attributes, add_attributes, modify_attributes, | ||
| 543 | delete_attributes, parameters)) | ||
| 544 | { | ||
| 545 | STOREerr(STORE_F_STORE_MODIFY_PRIVATE_KEY, | ||
| 546 | STORE_R_FAILED_MODIFYING_PRIVATE_KEY); | ||
| 547 | return 0; | ||
| 548 | } | ||
| 549 | return 1; | ||
| 550 | } | ||
| 551 | |||
| 552 | int STORE_revoke_private_key(STORE *s, OPENSSL_ITEM attributes[], | ||
| 553 | OPENSSL_ITEM parameters[]) | ||
| 554 | { | ||
| 555 | int i; | ||
| 556 | |||
| 557 | check_store(s,STORE_F_STORE_REVOKE_PRIVATE_KEY, | ||
| 558 | revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION); | ||
| 559 | |||
| 560 | i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, | ||
| 561 | attributes, parameters); | ||
| 562 | |||
| 563 | if (!i) | ||
| 564 | { | ||
| 565 | STOREerr(STORE_F_STORE_REVOKE_PRIVATE_KEY, | ||
| 566 | STORE_R_FAILED_REVOKING_KEY); | ||
| 567 | return 0; | ||
| 568 | } | ||
| 569 | return i; | ||
| 570 | } | ||
| 571 | |||
| 572 | int STORE_delete_private_key(STORE *s, OPENSSL_ITEM attributes[], | ||
| 573 | OPENSSL_ITEM parameters[]) | ||
| 574 | { | ||
| 575 | check_store(s,STORE_F_STORE_DELETE_PRIVATE_KEY, | ||
| 576 | delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION); | ||
| 577 | |||
| 578 | if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, | ||
| 579 | attributes, parameters)) | ||
| 580 | { | ||
| 581 | STOREerr(STORE_F_STORE_DELETE_PRIVATE_KEY, | ||
| 582 | STORE_R_FAILED_DELETING_KEY); | ||
| 583 | return 0; | ||
| 584 | } | ||
| 585 | return 1; | ||
| 586 | } | ||
| 587 | |||
| 588 | void *STORE_list_private_key_start(STORE *s, OPENSSL_ITEM attributes[], | ||
| 589 | OPENSSL_ITEM parameters[]) | ||
| 590 | { | ||
| 591 | void *handle; | ||
| 592 | |||
| 593 | check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_START, | ||
| 594 | list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION); | ||
| 595 | |||
| 596 | handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PRIVATE_KEY, | ||
| 597 | attributes, parameters); | ||
| 598 | if (!handle) | ||
| 599 | { | ||
| 600 | STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_START, | ||
| 601 | STORE_R_FAILED_LISTING_KEYS); | ||
| 602 | return 0; | ||
| 603 | } | ||
| 604 | return handle; | ||
| 605 | } | ||
| 606 | |||
| 607 | EVP_PKEY *STORE_list_private_key_next(STORE *s, void *handle) | ||
| 608 | { | ||
| 609 | STORE_OBJECT *object; | ||
| 610 | EVP_PKEY *pkey; | ||
| 611 | |||
| 612 | check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_NEXT, | ||
| 613 | list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION); | ||
| 614 | |||
| 615 | object = s->meth->list_object_next(s, handle); | ||
| 616 | if (!object || !object->data.key || !object->data.key) | ||
| 617 | { | ||
| 618 | STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_NEXT, | ||
| 619 | STORE_R_FAILED_LISTING_KEYS); | ||
| 620 | return 0; | ||
| 621 | } | ||
| 622 | CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
| 623 | #ifdef REF_PRINT | ||
| 624 | REF_PRINT("EVP_PKEY",data); | ||
| 625 | #endif | ||
| 626 | pkey = object->data.key; | ||
| 627 | STORE_OBJECT_free(object); | ||
| 628 | return pkey; | ||
| 629 | } | ||
| 630 | |||
| 631 | int STORE_list_private_key_end(STORE *s, void *handle) | ||
| 632 | { | ||
| 633 | check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_END, | ||
| 634 | list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION); | ||
| 635 | |||
| 636 | if (!s->meth->list_object_end(s, handle)) | ||
| 637 | { | ||
| 638 | STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_END, | ||
| 639 | STORE_R_FAILED_LISTING_KEYS); | ||
| 640 | return 0; | ||
| 641 | } | ||
| 642 | return 1; | ||
| 643 | } | ||
| 644 | |||
| 645 | int STORE_list_private_key_endp(STORE *s, void *handle) | ||
| 646 | { | ||
| 647 | check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_ENDP, | ||
| 648 | list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION); | ||
| 649 | |||
| 650 | if (!s->meth->list_object_endp(s, handle)) | ||
| 651 | { | ||
| 652 | STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_ENDP, | ||
| 653 | STORE_R_FAILED_LISTING_KEYS); | ||
| 654 | return 0; | ||
| 655 | } | ||
| 656 | return 1; | ||
| 657 | } | ||
| 658 | |||
| 659 | EVP_PKEY *STORE_get_public_key(STORE *s, OPENSSL_ITEM attributes[], | ||
| 660 | OPENSSL_ITEM parameters[]) | ||
| 661 | { | ||
| 662 | STORE_OBJECT *object; | ||
| 663 | EVP_PKEY *pkey; | ||
| 664 | |||
| 665 | check_store(s,STORE_F_STORE_GET_PUBLIC_KEY, | ||
| 666 | get_object,STORE_R_NO_GET_OBJECT_FUNCTION); | ||
| 667 | |||
| 668 | object = s->meth->get_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY, | ||
| 669 | attributes, parameters); | ||
| 670 | if (!object || !object->data.key || !object->data.key) | ||
| 671 | { | ||
| 672 | STOREerr(STORE_F_STORE_GET_PUBLIC_KEY, | ||
| 673 | STORE_R_FAILED_GETTING_KEY); | ||
| 674 | return 0; | ||
| 675 | } | ||
| 676 | CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
| 677 | #ifdef REF_PRINT | ||
| 678 | REF_PRINT("EVP_PKEY",data); | ||
| 679 | #endif | ||
| 680 | pkey = object->data.key; | ||
| 681 | STORE_OBJECT_free(object); | ||
| 682 | return pkey; | ||
| 683 | } | ||
| 684 | |||
| 685 | int STORE_store_public_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[], | ||
| 686 | OPENSSL_ITEM parameters[]) | ||
| 687 | { | ||
| 688 | STORE_OBJECT *object; | ||
| 689 | int i; | ||
| 690 | |||
| 691 | check_store(s,STORE_F_STORE_STORE_PUBLIC_KEY, | ||
| 692 | store_object,STORE_R_NO_STORE_OBJECT_FUNCTION); | ||
| 693 | |||
| 694 | object = STORE_OBJECT_new(); | ||
| 695 | if (!object) | ||
| 696 | { | ||
| 697 | STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, | ||
| 698 | ERR_R_MALLOC_FAILURE); | ||
| 699 | return 0; | ||
| 700 | } | ||
| 701 | object->data.key = EVP_PKEY_new(); | ||
| 702 | if (!object->data.key) | ||
| 703 | { | ||
| 704 | STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, | ||
| 705 | ERR_R_MALLOC_FAILURE); | ||
| 706 | return 0; | ||
| 707 | } | ||
| 708 | |||
| 709 | CRYPTO_add(&data->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
| 710 | #ifdef REF_PRINT | ||
| 711 | REF_PRINT("EVP_PKEY",data); | ||
| 712 | #endif | ||
| 713 | object->data.key = data; | ||
| 714 | |||
| 715 | i = s->meth->store_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY, object, | ||
| 716 | attributes, parameters); | ||
| 717 | |||
| 718 | STORE_OBJECT_free(object); | ||
| 719 | |||
| 720 | if (!i) | ||
| 721 | { | ||
| 722 | STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, | ||
| 723 | STORE_R_FAILED_STORING_KEY); | ||
| 724 | return 0; | ||
| 725 | } | ||
| 726 | return i; | ||
| 727 | } | ||
| 728 | |||
| 729 | int STORE_modify_public_key(STORE *s, OPENSSL_ITEM search_attributes[], | ||
| 730 | OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], | ||
| 731 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]) | ||
| 732 | { | ||
| 733 | check_store(s,STORE_F_STORE_MODIFY_PUBLIC_KEY, | ||
| 734 | modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION); | ||
| 735 | |||
| 736 | if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY, | ||
| 737 | search_attributes, add_attributes, modify_attributes, | ||
| 738 | delete_attributes, parameters)) | ||
| 739 | { | ||
| 740 | STOREerr(STORE_F_STORE_MODIFY_PUBLIC_KEY, | ||
| 741 | STORE_R_FAILED_MODIFYING_PUBLIC_KEY); | ||
| 742 | return 0; | ||
| 743 | } | ||
| 744 | return 1; | ||
| 745 | } | ||
| 746 | |||
| 747 | int STORE_revoke_public_key(STORE *s, OPENSSL_ITEM attributes[], | ||
| 748 | OPENSSL_ITEM parameters[]) | ||
| 749 | { | ||
| 750 | int i; | ||
| 751 | |||
| 752 | check_store(s,STORE_F_STORE_REVOKE_PUBLIC_KEY, | ||
| 753 | revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION); | ||
| 754 | |||
| 755 | i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY, | ||
| 756 | attributes, parameters); | ||
| 757 | |||
| 758 | if (!i) | ||
| 759 | { | ||
| 760 | STOREerr(STORE_F_STORE_REVOKE_PUBLIC_KEY, | ||
| 761 | STORE_R_FAILED_REVOKING_KEY); | ||
| 762 | return 0; | ||
| 763 | } | ||
| 764 | return i; | ||
| 765 | } | ||
| 766 | |||
| 767 | int STORE_delete_public_key(STORE *s, OPENSSL_ITEM attributes[], | ||
| 768 | OPENSSL_ITEM parameters[]) | ||
| 769 | { | ||
| 770 | check_store(s,STORE_F_STORE_DELETE_PUBLIC_KEY, | ||
| 771 | delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION); | ||
| 772 | |||
| 773 | if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY, | ||
| 774 | attributes, parameters)) | ||
| 775 | { | ||
| 776 | STOREerr(STORE_F_STORE_DELETE_PUBLIC_KEY, | ||
| 777 | STORE_R_FAILED_DELETING_KEY); | ||
| 778 | return 0; | ||
| 779 | } | ||
| 780 | return 1; | ||
| 781 | } | ||
| 782 | |||
| 783 | void *STORE_list_public_key_start(STORE *s, OPENSSL_ITEM attributes[], | ||
| 784 | OPENSSL_ITEM parameters[]) | ||
| 785 | { | ||
| 786 | void *handle; | ||
| 787 | |||
| 788 | check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_START, | ||
| 789 | list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION); | ||
| 790 | |||
| 791 | handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PUBLIC_KEY, | ||
| 792 | attributes, parameters); | ||
| 793 | if (!handle) | ||
| 794 | { | ||
| 795 | STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_START, | ||
| 796 | STORE_R_FAILED_LISTING_KEYS); | ||
| 797 | return 0; | ||
| 798 | } | ||
| 799 | return handle; | ||
| 800 | } | ||
| 801 | |||
| 802 | EVP_PKEY *STORE_list_public_key_next(STORE *s, void *handle) | ||
| 803 | { | ||
| 804 | STORE_OBJECT *object; | ||
| 805 | EVP_PKEY *pkey; | ||
| 806 | |||
| 807 | check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_NEXT, | ||
| 808 | list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION); | ||
| 809 | |||
| 810 | object = s->meth->list_object_next(s, handle); | ||
| 811 | if (!object || !object->data.key || !object->data.key) | ||
| 812 | { | ||
| 813 | STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_NEXT, | ||
| 814 | STORE_R_FAILED_LISTING_KEYS); | ||
| 815 | return 0; | ||
| 816 | } | ||
| 817 | CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
| 818 | #ifdef REF_PRINT | ||
| 819 | REF_PRINT("EVP_PKEY",data); | ||
| 820 | #endif | ||
| 821 | pkey = object->data.key; | ||
| 822 | STORE_OBJECT_free(object); | ||
| 823 | return pkey; | ||
| 824 | } | ||
| 825 | |||
| 826 | int STORE_list_public_key_end(STORE *s, void *handle) | ||
| 827 | { | ||
| 828 | check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_END, | ||
| 829 | list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION); | ||
| 830 | |||
| 831 | if (!s->meth->list_object_end(s, handle)) | ||
| 832 | { | ||
| 833 | STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_END, | ||
| 834 | STORE_R_FAILED_LISTING_KEYS); | ||
| 835 | return 0; | ||
| 836 | } | ||
| 837 | return 1; | ||
| 838 | } | ||
| 839 | |||
| 840 | int STORE_list_public_key_endp(STORE *s, void *handle) | ||
| 841 | { | ||
| 842 | check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_ENDP, | ||
| 843 | list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION); | ||
| 844 | |||
| 845 | if (!s->meth->list_object_endp(s, handle)) | ||
| 846 | { | ||
| 847 | STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_ENDP, | ||
| 848 | STORE_R_FAILED_LISTING_KEYS); | ||
| 849 | return 0; | ||
| 850 | } | ||
| 851 | return 1; | ||
| 852 | } | ||
| 853 | |||
| 854 | X509_CRL *STORE_generate_crl(STORE *s, OPENSSL_ITEM attributes[], | ||
| 855 | OPENSSL_ITEM parameters[]) | ||
| 856 | { | ||
| 857 | STORE_OBJECT *object; | ||
| 858 | X509_CRL *crl; | ||
| 859 | |||
| 860 | check_store(s,STORE_F_STORE_GENERATE_CRL, | ||
| 861 | generate_object,STORE_R_NO_GENERATE_CRL_FUNCTION); | ||
| 862 | |||
| 863 | object = s->meth->generate_object(s, STORE_OBJECT_TYPE_X509_CRL, | ||
| 864 | attributes, parameters); | ||
| 865 | if (!object || !object->data.crl) | ||
| 866 | { | ||
| 867 | STOREerr(STORE_F_STORE_GENERATE_CRL, | ||
| 868 | STORE_R_FAILED_GENERATING_CRL); | ||
| 869 | return 0; | ||
| 870 | } | ||
| 871 | CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL); | ||
| 872 | #ifdef REF_PRINT | ||
| 873 | REF_PRINT("X509_CRL",data); | ||
| 874 | #endif | ||
| 875 | crl = object->data.crl; | ||
| 876 | STORE_OBJECT_free(object); | ||
| 877 | return crl; | ||
| 878 | } | ||
| 879 | |||
| 880 | X509_CRL *STORE_get_crl(STORE *s, OPENSSL_ITEM attributes[], | ||
| 881 | OPENSSL_ITEM parameters[]) | ||
| 882 | { | ||
| 883 | STORE_OBJECT *object; | ||
| 884 | X509_CRL *crl; | ||
| 885 | |||
| 886 | check_store(s,STORE_F_STORE_GET_CRL, | ||
| 887 | get_object,STORE_R_NO_GET_OBJECT_FUNCTION); | ||
| 888 | |||
| 889 | object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CRL, | ||
| 890 | attributes, parameters); | ||
| 891 | if (!object || !object->data.crl) | ||
| 892 | { | ||
| 893 | STOREerr(STORE_F_STORE_GET_CRL, | ||
| 894 | STORE_R_FAILED_GETTING_KEY); | ||
| 895 | return 0; | ||
| 896 | } | ||
| 897 | CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL); | ||
| 898 | #ifdef REF_PRINT | ||
| 899 | REF_PRINT("X509_CRL",data); | ||
| 900 | #endif | ||
| 901 | crl = object->data.crl; | ||
| 902 | STORE_OBJECT_free(object); | ||
| 903 | return crl; | ||
| 904 | } | ||
| 905 | |||
| 906 | int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[], | ||
| 907 | OPENSSL_ITEM parameters[]) | ||
| 908 | { | ||
| 909 | STORE_OBJECT *object; | ||
| 910 | int i; | ||
| 911 | |||
| 912 | check_store(s,STORE_F_STORE_STORE_CRL, | ||
| 913 | store_object,STORE_R_NO_STORE_OBJECT_FUNCTION); | ||
| 914 | |||
| 915 | object = STORE_OBJECT_new(); | ||
| 916 | if (!object) | ||
| 917 | { | ||
| 918 | STOREerr(STORE_F_STORE_STORE_CRL, | ||
| 919 | ERR_R_MALLOC_FAILURE); | ||
| 920 | return 0; | ||
| 921 | } | ||
| 922 | |||
| 923 | CRYPTO_add(&data->references,1,CRYPTO_LOCK_X509_CRL); | ||
| 924 | #ifdef REF_PRINT | ||
| 925 | REF_PRINT("X509_CRL",data); | ||
| 926 | #endif | ||
| 927 | object->data.crl = data; | ||
| 928 | |||
| 929 | i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CRL, object, | ||
| 930 | attributes, parameters); | ||
| 931 | |||
| 932 | STORE_OBJECT_free(object); | ||
| 933 | |||
| 934 | if (!i) | ||
| 935 | { | ||
| 936 | STOREerr(STORE_F_STORE_STORE_CRL, | ||
| 937 | STORE_R_FAILED_STORING_KEY); | ||
| 938 | return 0; | ||
| 939 | } | ||
| 940 | return i; | ||
| 941 | } | ||
| 942 | |||
| 943 | int STORE_modify_crl(STORE *s, OPENSSL_ITEM search_attributes[], | ||
| 944 | OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], | ||
| 945 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]) | ||
| 946 | { | ||
| 947 | check_store(s,STORE_F_STORE_MODIFY_CRL, | ||
| 948 | modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION); | ||
| 949 | |||
| 950 | if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CRL, | ||
| 951 | search_attributes, add_attributes, modify_attributes, | ||
| 952 | delete_attributes, parameters)) | ||
| 953 | { | ||
| 954 | STOREerr(STORE_F_STORE_MODIFY_CRL, | ||
| 955 | STORE_R_FAILED_MODIFYING_CRL); | ||
| 956 | return 0; | ||
| 957 | } | ||
| 958 | return 1; | ||
| 959 | } | ||
| 960 | |||
| 961 | int STORE_delete_crl(STORE *s, OPENSSL_ITEM attributes[], | ||
| 962 | OPENSSL_ITEM parameters[]) | ||
| 963 | { | ||
| 964 | check_store(s,STORE_F_STORE_DELETE_CRL, | ||
| 965 | delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION); | ||
| 966 | |||
| 967 | if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CRL, | ||
| 968 | attributes, parameters)) | ||
| 969 | { | ||
| 970 | STOREerr(STORE_F_STORE_DELETE_CRL, | ||
| 971 | STORE_R_FAILED_DELETING_KEY); | ||
| 972 | return 0; | ||
| 973 | } | ||
| 974 | return 1; | ||
| 975 | } | ||
| 976 | |||
| 977 | void *STORE_list_crl_start(STORE *s, OPENSSL_ITEM attributes[], | ||
| 978 | OPENSSL_ITEM parameters[]) | ||
| 979 | { | ||
| 980 | void *handle; | ||
| 981 | |||
| 982 | check_store(s,STORE_F_STORE_LIST_CRL_START, | ||
| 983 | list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION); | ||
| 984 | |||
| 985 | handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_X509_CRL, | ||
| 986 | attributes, parameters); | ||
| 987 | if (!handle) | ||
| 988 | { | ||
| 989 | STOREerr(STORE_F_STORE_LIST_CRL_START, | ||
| 990 | STORE_R_FAILED_LISTING_KEYS); | ||
| 991 | return 0; | ||
| 992 | } | ||
| 993 | return handle; | ||
| 994 | } | ||
| 995 | |||
| 996 | X509_CRL *STORE_list_crl_next(STORE *s, void *handle) | ||
| 997 | { | ||
| 998 | STORE_OBJECT *object; | ||
| 999 | X509_CRL *crl; | ||
| 1000 | |||
| 1001 | check_store(s,STORE_F_STORE_LIST_CRL_NEXT, | ||
| 1002 | list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION); | ||
| 1003 | |||
| 1004 | object = s->meth->list_object_next(s, handle); | ||
| 1005 | if (!object || !object->data.crl) | ||
| 1006 | { | ||
| 1007 | STOREerr(STORE_F_STORE_LIST_CRL_NEXT, | ||
| 1008 | STORE_R_FAILED_LISTING_KEYS); | ||
| 1009 | return 0; | ||
| 1010 | } | ||
| 1011 | CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL); | ||
| 1012 | #ifdef REF_PRINT | ||
| 1013 | REF_PRINT("X509_CRL",data); | ||
| 1014 | #endif | ||
| 1015 | crl = object->data.crl; | ||
| 1016 | STORE_OBJECT_free(object); | ||
| 1017 | return crl; | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | int STORE_list_crl_end(STORE *s, void *handle) | ||
| 1021 | { | ||
| 1022 | check_store(s,STORE_F_STORE_LIST_CRL_END, | ||
| 1023 | list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION); | ||
| 1024 | |||
| 1025 | if (!s->meth->list_object_end(s, handle)) | ||
| 1026 | { | ||
| 1027 | STOREerr(STORE_F_STORE_LIST_CRL_END, | ||
| 1028 | STORE_R_FAILED_LISTING_KEYS); | ||
| 1029 | return 0; | ||
| 1030 | } | ||
| 1031 | return 1; | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | int STORE_list_crl_endp(STORE *s, void *handle) | ||
| 1035 | { | ||
| 1036 | check_store(s,STORE_F_STORE_LIST_CRL_ENDP, | ||
| 1037 | list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION); | ||
| 1038 | |||
| 1039 | if (!s->meth->list_object_endp(s, handle)) | ||
| 1040 | { | ||
| 1041 | STOREerr(STORE_F_STORE_LIST_CRL_ENDP, | ||
| 1042 | STORE_R_FAILED_LISTING_KEYS); | ||
| 1043 | return 0; | ||
| 1044 | } | ||
| 1045 | return 1; | ||
| 1046 | } | ||
| 1047 | |||
| 1048 | int STORE_store_number(STORE *s, BIGNUM *data, OPENSSL_ITEM attributes[], | ||
| 1049 | OPENSSL_ITEM parameters[]) | ||
| 1050 | { | ||
| 1051 | STORE_OBJECT *object; | ||
| 1052 | int i; | ||
| 1053 | |||
| 1054 | check_store(s,STORE_F_STORE_STORE_NUMBER, | ||
| 1055 | store_object,STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION); | ||
| 1056 | |||
| 1057 | object = STORE_OBJECT_new(); | ||
| 1058 | if (!object) | ||
| 1059 | { | ||
| 1060 | STOREerr(STORE_F_STORE_STORE_NUMBER, | ||
| 1061 | ERR_R_MALLOC_FAILURE); | ||
| 1062 | return 0; | ||
| 1063 | } | ||
| 1064 | |||
| 1065 | object->data.number = data; | ||
| 1066 | |||
| 1067 | i = s->meth->store_object(s, STORE_OBJECT_TYPE_NUMBER, object, | ||
| 1068 | attributes, parameters); | ||
| 1069 | |||
| 1070 | STORE_OBJECT_free(object); | ||
| 1071 | |||
| 1072 | if (!i) | ||
| 1073 | { | ||
| 1074 | STOREerr(STORE_F_STORE_STORE_NUMBER, | ||
| 1075 | STORE_R_FAILED_STORING_NUMBER); | ||
| 1076 | return 0; | ||
| 1077 | } | ||
| 1078 | return 1; | ||
| 1079 | } | ||
| 1080 | |||
| 1081 | int STORE_modify_number(STORE *s, OPENSSL_ITEM search_attributes[], | ||
| 1082 | OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], | ||
| 1083 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]) | ||
| 1084 | { | ||
| 1085 | check_store(s,STORE_F_STORE_MODIFY_NUMBER, | ||
| 1086 | modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION); | ||
| 1087 | |||
| 1088 | if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_NUMBER, | ||
| 1089 | search_attributes, add_attributes, modify_attributes, | ||
| 1090 | delete_attributes, parameters)) | ||
| 1091 | { | ||
| 1092 | STOREerr(STORE_F_STORE_MODIFY_NUMBER, | ||
| 1093 | STORE_R_FAILED_MODIFYING_NUMBER); | ||
| 1094 | return 0; | ||
| 1095 | } | ||
| 1096 | return 1; | ||
| 1097 | } | ||
| 1098 | |||
| 1099 | BIGNUM *STORE_get_number(STORE *s, OPENSSL_ITEM attributes[], | ||
| 1100 | OPENSSL_ITEM parameters[]) | ||
| 1101 | { | ||
| 1102 | STORE_OBJECT *object; | ||
| 1103 | BIGNUM *n; | ||
| 1104 | |||
| 1105 | check_store(s,STORE_F_STORE_GET_NUMBER, | ||
| 1106 | get_object,STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION); | ||
| 1107 | |||
| 1108 | object = s->meth->get_object(s, STORE_OBJECT_TYPE_NUMBER, attributes, | ||
| 1109 | parameters); | ||
| 1110 | if (!object || !object->data.number) | ||
| 1111 | { | ||
| 1112 | STOREerr(STORE_F_STORE_GET_NUMBER, | ||
| 1113 | STORE_R_FAILED_GETTING_NUMBER); | ||
| 1114 | return 0; | ||
| 1115 | } | ||
| 1116 | n = object->data.number; | ||
| 1117 | object->data.number = NULL; | ||
| 1118 | STORE_OBJECT_free(object); | ||
| 1119 | return n; | ||
| 1120 | } | ||
| 1121 | |||
| 1122 | int STORE_delete_number(STORE *s, OPENSSL_ITEM attributes[], | ||
| 1123 | OPENSSL_ITEM parameters[]) | ||
| 1124 | { | ||
| 1125 | check_store(s,STORE_F_STORE_DELETE_NUMBER, | ||
| 1126 | delete_object,STORE_R_NO_DELETE_NUMBER_FUNCTION); | ||
| 1127 | |||
| 1128 | if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_NUMBER, attributes, | ||
| 1129 | parameters)) | ||
| 1130 | { | ||
| 1131 | STOREerr(STORE_F_STORE_DELETE_NUMBER, | ||
| 1132 | STORE_R_FAILED_DELETING_NUMBER); | ||
| 1133 | return 0; | ||
| 1134 | } | ||
| 1135 | return 1; | ||
| 1136 | } | ||
| 1137 | |||
| 1138 | int STORE_store_arbitrary(STORE *s, BUF_MEM *data, OPENSSL_ITEM attributes[], | ||
| 1139 | OPENSSL_ITEM parameters[]) | ||
| 1140 | { | ||
| 1141 | STORE_OBJECT *object; | ||
| 1142 | int i; | ||
| 1143 | |||
| 1144 | check_store(s,STORE_F_STORE_STORE_ARBITRARY, | ||
| 1145 | store_object,STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION); | ||
| 1146 | |||
| 1147 | object = STORE_OBJECT_new(); | ||
| 1148 | if (!object) | ||
| 1149 | { | ||
| 1150 | STOREerr(STORE_F_STORE_STORE_ARBITRARY, | ||
| 1151 | ERR_R_MALLOC_FAILURE); | ||
| 1152 | return 0; | ||
| 1153 | } | ||
| 1154 | |||
| 1155 | object->data.arbitrary = data; | ||
| 1156 | |||
| 1157 | i = s->meth->store_object(s, STORE_OBJECT_TYPE_ARBITRARY, object, | ||
| 1158 | attributes, parameters); | ||
| 1159 | |||
| 1160 | STORE_OBJECT_free(object); | ||
| 1161 | |||
| 1162 | if (!i) | ||
| 1163 | { | ||
| 1164 | STOREerr(STORE_F_STORE_STORE_ARBITRARY, | ||
| 1165 | STORE_R_FAILED_STORING_ARBITRARY); | ||
| 1166 | return 0; | ||
| 1167 | } | ||
| 1168 | return 1; | ||
| 1169 | } | ||
| 1170 | |||
| 1171 | int STORE_modify_arbitrary(STORE *s, OPENSSL_ITEM search_attributes[], | ||
| 1172 | OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], | ||
| 1173 | OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]) | ||
| 1174 | { | ||
| 1175 | check_store(s,STORE_F_STORE_MODIFY_ARBITRARY, | ||
| 1176 | modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION); | ||
| 1177 | |||
| 1178 | if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_ARBITRARY, | ||
| 1179 | search_attributes, add_attributes, modify_attributes, | ||
| 1180 | delete_attributes, parameters)) | ||
| 1181 | { | ||
| 1182 | STOREerr(STORE_F_STORE_MODIFY_ARBITRARY, | ||
| 1183 | STORE_R_FAILED_MODIFYING_ARBITRARY); | ||
| 1184 | return 0; | ||
| 1185 | } | ||
| 1186 | return 1; | ||
| 1187 | } | ||
| 1188 | |||
| 1189 | BUF_MEM *STORE_get_arbitrary(STORE *s, OPENSSL_ITEM attributes[], | ||
| 1190 | OPENSSL_ITEM parameters[]) | ||
| 1191 | { | ||
| 1192 | STORE_OBJECT *object; | ||
| 1193 | BUF_MEM *b; | ||
| 1194 | |||
| 1195 | check_store(s,STORE_F_STORE_GET_ARBITRARY, | ||
| 1196 | get_object,STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION); | ||
| 1197 | |||
| 1198 | object = s->meth->get_object(s, STORE_OBJECT_TYPE_ARBITRARY, | ||
| 1199 | attributes, parameters); | ||
| 1200 | if (!object || !object->data.arbitrary) | ||
| 1201 | { | ||
| 1202 | STOREerr(STORE_F_STORE_GET_ARBITRARY, | ||
| 1203 | STORE_R_FAILED_GETTING_ARBITRARY); | ||
| 1204 | return 0; | ||
| 1205 | } | ||
| 1206 | b = object->data.arbitrary; | ||
| 1207 | object->data.arbitrary = NULL; | ||
| 1208 | STORE_OBJECT_free(object); | ||
| 1209 | return b; | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | int STORE_delete_arbitrary(STORE *s, OPENSSL_ITEM attributes[], | ||
| 1213 | OPENSSL_ITEM parameters[]) | ||
| 1214 | { | ||
| 1215 | check_store(s,STORE_F_STORE_DELETE_ARBITRARY, | ||
| 1216 | delete_object,STORE_R_NO_DELETE_ARBITRARY_FUNCTION); | ||
| 1217 | |||
| 1218 | if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_ARBITRARY, attributes, | ||
| 1219 | parameters)) | ||
| 1220 | { | ||
| 1221 | STOREerr(STORE_F_STORE_DELETE_ARBITRARY, | ||
| 1222 | STORE_R_FAILED_DELETING_ARBITRARY); | ||
| 1223 | return 0; | ||
| 1224 | } | ||
| 1225 | return 1; | ||
| 1226 | } | ||
| 1227 | |||
| 1228 | STORE_OBJECT *STORE_OBJECT_new(void) | ||
| 1229 | { | ||
| 1230 | STORE_OBJECT *object = OPENSSL_malloc(sizeof(STORE_OBJECT)); | ||
| 1231 | if (object) memset(object, 0, sizeof(STORE_OBJECT)); | ||
| 1232 | return object; | ||
| 1233 | } | ||
| 1234 | void STORE_OBJECT_free(STORE_OBJECT *data) | ||
| 1235 | { | ||
| 1236 | if (!data) return; | ||
| 1237 | switch (data->type) | ||
| 1238 | { | ||
| 1239 | case STORE_OBJECT_TYPE_X509_CERTIFICATE: | ||
| 1240 | X509_free(data->data.x509.certificate); | ||
| 1241 | break; | ||
| 1242 | case STORE_OBJECT_TYPE_X509_CRL: | ||
| 1243 | X509_CRL_free(data->data.crl); | ||
| 1244 | break; | ||
| 1245 | case STORE_OBJECT_TYPE_PRIVATE_KEY: | ||
| 1246 | case STORE_OBJECT_TYPE_PUBLIC_KEY: | ||
| 1247 | EVP_PKEY_free(data->data.key); | ||
| 1248 | break; | ||
| 1249 | case STORE_OBJECT_TYPE_NUMBER: | ||
| 1250 | BN_free(data->data.number); | ||
| 1251 | break; | ||
| 1252 | case STORE_OBJECT_TYPE_ARBITRARY: | ||
| 1253 | BUF_MEM_free(data->data.arbitrary); | ||
| 1254 | break; | ||
| 1255 | } | ||
| 1256 | OPENSSL_free(data); | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | IMPLEMENT_STACK_OF(STORE_OBJECT*) | ||
| 1260 | |||
| 1261 | |||
| 1262 | struct STORE_attr_info_st | ||
| 1263 | { | ||
| 1264 | unsigned char set[(STORE_ATTR_TYPE_NUM + 8) / 8]; | ||
| 1265 | union | ||
| 1266 | { | ||
| 1267 | char *cstring; | ||
| 1268 | unsigned char *sha1string; | ||
| 1269 | X509_NAME *dn; | ||
| 1270 | BIGNUM *number; | ||
| 1271 | void *any; | ||
| 1272 | } values[STORE_ATTR_TYPE_NUM+1]; | ||
| 1273 | size_t value_sizes[STORE_ATTR_TYPE_NUM+1]; | ||
| 1274 | }; | ||
| 1275 | |||
| 1276 | #define ATTR_IS_SET(a,i) ((i) > 0 && (i) < STORE_ATTR_TYPE_NUM \ | ||
| 1277 | && ((a)->set[(i) / 8] & (1 << ((i) % 8)))) | ||
| 1278 | #define SET_ATTRBIT(a,i) ((a)->set[(i) / 8] |= (1 << ((i) % 8))) | ||
| 1279 | #define CLEAR_ATTRBIT(a,i) ((a)->set[(i) / 8] &= ~(1 << ((i) % 8))) | ||
| 1280 | |||
| 1281 | STORE_ATTR_INFO *STORE_ATTR_INFO_new(void) | ||
| 1282 | { | ||
| 1283 | return (STORE_ATTR_INFO *)OPENSSL_malloc(sizeof(STORE_ATTR_INFO)); | ||
| 1284 | } | ||
| 1285 | static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO *attrs, | ||
| 1286 | STORE_ATTR_TYPES code) | ||
| 1287 | { | ||
| 1288 | if (ATTR_IS_SET(attrs,code)) | ||
| 1289 | { | ||
| 1290 | switch(code) | ||
| 1291 | { | ||
| 1292 | case STORE_ATTR_FRIENDLYNAME: | ||
| 1293 | case STORE_ATTR_EMAIL: | ||
| 1294 | case STORE_ATTR_FILENAME: | ||
| 1295 | STORE_ATTR_INFO_modify_cstr(attrs, code, NULL, 0); | ||
| 1296 | break; | ||
| 1297 | case STORE_ATTR_KEYID: | ||
| 1298 | case STORE_ATTR_ISSUERKEYID: | ||
| 1299 | case STORE_ATTR_SUBJECTKEYID: | ||
| 1300 | case STORE_ATTR_ISSUERSERIALHASH: | ||
| 1301 | case STORE_ATTR_CERTHASH: | ||
| 1302 | STORE_ATTR_INFO_modify_sha1str(attrs, code, NULL, 0); | ||
| 1303 | break; | ||
| 1304 | case STORE_ATTR_ISSUER: | ||
| 1305 | case STORE_ATTR_SUBJECT: | ||
| 1306 | STORE_ATTR_INFO_modify_dn(attrs, code, NULL); | ||
| 1307 | break; | ||
| 1308 | case STORE_ATTR_SERIAL: | ||
| 1309 | STORE_ATTR_INFO_modify_number(attrs, code, NULL); | ||
| 1310 | break; | ||
| 1311 | default: | ||
| 1312 | break; | ||
| 1313 | } | ||
| 1314 | } | ||
| 1315 | } | ||
| 1316 | int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs) | ||
| 1317 | { | ||
| 1318 | if (attrs) | ||
| 1319 | { | ||
| 1320 | STORE_ATTR_TYPES i; | ||
| 1321 | for(i = 0; i++ < STORE_ATTR_TYPE_NUM;) | ||
| 1322 | STORE_ATTR_INFO_attr_free(attrs, i); | ||
| 1323 | OPENSSL_free(attrs); | ||
| 1324 | } | ||
| 1325 | return 1; | ||
| 1326 | } | ||
| 1327 | char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code) | ||
| 1328 | { | ||
| 1329 | if (!attrs) | ||
| 1330 | { | ||
| 1331 | STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR, | ||
| 1332 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1333 | return NULL; | ||
| 1334 | } | ||
| 1335 | if (ATTR_IS_SET(attrs,code)) | ||
| 1336 | return attrs->values[code].cstring; | ||
| 1337 | STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR, | ||
| 1338 | STORE_R_NO_VALUE); | ||
| 1339 | return NULL; | ||
| 1340 | } | ||
| 1341 | unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs, | ||
| 1342 | STORE_ATTR_TYPES code) | ||
| 1343 | { | ||
| 1344 | if (!attrs) | ||
| 1345 | { | ||
| 1346 | STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR, | ||
| 1347 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1348 | return NULL; | ||
| 1349 | } | ||
| 1350 | if (ATTR_IS_SET(attrs,code)) | ||
| 1351 | return attrs->values[code].sha1string; | ||
| 1352 | STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR, | ||
| 1353 | STORE_R_NO_VALUE); | ||
| 1354 | return NULL; | ||
| 1355 | } | ||
| 1356 | X509_NAME *STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code) | ||
| 1357 | { | ||
| 1358 | if (!attrs) | ||
| 1359 | { | ||
| 1360 | STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN, | ||
| 1361 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1362 | return NULL; | ||
| 1363 | } | ||
| 1364 | if (ATTR_IS_SET(attrs,code)) | ||
| 1365 | return attrs->values[code].dn; | ||
| 1366 | STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN, | ||
| 1367 | STORE_R_NO_VALUE); | ||
| 1368 | return NULL; | ||
| 1369 | } | ||
| 1370 | BIGNUM *STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code) | ||
| 1371 | { | ||
| 1372 | if (!attrs) | ||
| 1373 | { | ||
| 1374 | STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER, | ||
| 1375 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1376 | return NULL; | ||
| 1377 | } | ||
| 1378 | if (ATTR_IS_SET(attrs,code)) | ||
| 1379 | return attrs->values[code].number; | ||
| 1380 | STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER, | ||
| 1381 | STORE_R_NO_VALUE); | ||
| 1382 | return NULL; | ||
| 1383 | } | ||
| 1384 | int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 1385 | char *cstr, size_t cstr_size) | ||
| 1386 | { | ||
| 1387 | if (!attrs) | ||
| 1388 | { | ||
| 1389 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, | ||
| 1390 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1391 | return 0; | ||
| 1392 | } | ||
| 1393 | if (!ATTR_IS_SET(attrs,code)) | ||
| 1394 | { | ||
| 1395 | if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size))) | ||
| 1396 | return 1; | ||
| 1397 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, | ||
| 1398 | ERR_R_MALLOC_FAILURE); | ||
| 1399 | return 0; | ||
| 1400 | } | ||
| 1401 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, STORE_R_ALREADY_HAS_A_VALUE); | ||
| 1402 | return 0; | ||
| 1403 | } | ||
| 1404 | int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 1405 | unsigned char *sha1str, size_t sha1str_size) | ||
| 1406 | { | ||
| 1407 | if (!attrs) | ||
| 1408 | { | ||
| 1409 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, | ||
| 1410 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1411 | return 0; | ||
| 1412 | } | ||
| 1413 | if (!ATTR_IS_SET(attrs,code)) | ||
| 1414 | { | ||
| 1415 | if ((attrs->values[code].sha1string = | ||
| 1416 | (unsigned char *)BUF_memdup(sha1str, | ||
| 1417 | sha1str_size))) | ||
| 1418 | return 1; | ||
| 1419 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, | ||
| 1420 | ERR_R_MALLOC_FAILURE); | ||
| 1421 | return 0; | ||
| 1422 | } | ||
| 1423 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, STORE_R_ALREADY_HAS_A_VALUE); | ||
| 1424 | return 0; | ||
| 1425 | } | ||
| 1426 | int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 1427 | X509_NAME *dn) | ||
| 1428 | { | ||
| 1429 | if (!attrs) | ||
| 1430 | { | ||
| 1431 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, | ||
| 1432 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1433 | return 0; | ||
| 1434 | } | ||
| 1435 | if (!ATTR_IS_SET(attrs,code)) | ||
| 1436 | { | ||
| 1437 | if ((attrs->values[code].dn = X509_NAME_dup(dn))) | ||
| 1438 | return 1; | ||
| 1439 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, | ||
| 1440 | ERR_R_MALLOC_FAILURE); | ||
| 1441 | return 0; | ||
| 1442 | } | ||
| 1443 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, STORE_R_ALREADY_HAS_A_VALUE); | ||
| 1444 | return 0; | ||
| 1445 | } | ||
| 1446 | int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 1447 | BIGNUM *number) | ||
| 1448 | { | ||
| 1449 | if (!attrs) | ||
| 1450 | { | ||
| 1451 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, | ||
| 1452 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1453 | return 0; | ||
| 1454 | } | ||
| 1455 | if (!ATTR_IS_SET(attrs,code)) | ||
| 1456 | { | ||
| 1457 | if ((attrs->values[code].number = BN_dup(number))) | ||
| 1458 | return 1; | ||
| 1459 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, | ||
| 1460 | ERR_R_MALLOC_FAILURE); | ||
| 1461 | return 0; | ||
| 1462 | } | ||
| 1463 | STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, STORE_R_ALREADY_HAS_A_VALUE); | ||
| 1464 | return 0; | ||
| 1465 | } | ||
| 1466 | int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 1467 | char *cstr, size_t cstr_size) | ||
| 1468 | { | ||
| 1469 | if (!attrs) | ||
| 1470 | { | ||
| 1471 | STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_CSTR, | ||
| 1472 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1473 | return 0; | ||
| 1474 | } | ||
| 1475 | if (ATTR_IS_SET(attrs,code)) | ||
| 1476 | { | ||
| 1477 | OPENSSL_free(attrs->values[code].cstring); | ||
| 1478 | attrs->values[code].cstring = NULL; | ||
| 1479 | CLEAR_ATTRBIT(attrs, code); | ||
| 1480 | } | ||
| 1481 | return STORE_ATTR_INFO_set_cstr(attrs, code, cstr, cstr_size); | ||
| 1482 | } | ||
| 1483 | int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 1484 | unsigned char *sha1str, size_t sha1str_size) | ||
| 1485 | { | ||
| 1486 | if (!attrs) | ||
| 1487 | { | ||
| 1488 | STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR, | ||
| 1489 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1490 | return 0; | ||
| 1491 | } | ||
| 1492 | if (ATTR_IS_SET(attrs,code)) | ||
| 1493 | { | ||
| 1494 | OPENSSL_free(attrs->values[code].sha1string); | ||
| 1495 | attrs->values[code].sha1string = NULL; | ||
| 1496 | CLEAR_ATTRBIT(attrs, code); | ||
| 1497 | } | ||
| 1498 | return STORE_ATTR_INFO_set_sha1str(attrs, code, sha1str, sha1str_size); | ||
| 1499 | } | ||
| 1500 | int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 1501 | X509_NAME *dn) | ||
| 1502 | { | ||
| 1503 | if (!attrs) | ||
| 1504 | { | ||
| 1505 | STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_DN, | ||
| 1506 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1507 | return 0; | ||
| 1508 | } | ||
| 1509 | if (ATTR_IS_SET(attrs,code)) | ||
| 1510 | { | ||
| 1511 | OPENSSL_free(attrs->values[code].dn); | ||
| 1512 | attrs->values[code].dn = NULL; | ||
| 1513 | CLEAR_ATTRBIT(attrs, code); | ||
| 1514 | } | ||
| 1515 | return STORE_ATTR_INFO_set_dn(attrs, code, dn); | ||
| 1516 | } | ||
| 1517 | int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, | ||
| 1518 | BIGNUM *number) | ||
| 1519 | { | ||
| 1520 | if (!attrs) | ||
| 1521 | { | ||
| 1522 | STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER, | ||
| 1523 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 1524 | return 0; | ||
| 1525 | } | ||
| 1526 | if (ATTR_IS_SET(attrs,code)) | ||
| 1527 | { | ||
| 1528 | OPENSSL_free(attrs->values[code].number); | ||
| 1529 | attrs->values[code].number = NULL; | ||
| 1530 | CLEAR_ATTRBIT(attrs, code); | ||
| 1531 | } | ||
| 1532 | return STORE_ATTR_INFO_set_number(attrs, code, number); | ||
| 1533 | } | ||
| 1534 | |||
| 1535 | struct attr_list_ctx_st | ||
| 1536 | { | ||
| 1537 | OPENSSL_ITEM *attributes; | ||
| 1538 | }; | ||
| 1539 | void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes) | ||
| 1540 | { | ||
| 1541 | if (attributes) | ||
| 1542 | { | ||
| 1543 | struct attr_list_ctx_st *context = | ||
| 1544 | (struct attr_list_ctx_st *)OPENSSL_malloc(sizeof(struct attr_list_ctx_st)); | ||
| 1545 | if (context) | ||
| 1546 | context->attributes = attributes; | ||
| 1547 | else | ||
| 1548 | STOREerr(STORE_F_STORE_PARSE_ATTRS_START, | ||
| 1549 | ERR_R_MALLOC_FAILURE); | ||
| 1550 | return context; | ||
| 1551 | } | ||
| 1552 | STOREerr(STORE_F_STORE_PARSE_ATTRS_START, ERR_R_PASSED_NULL_PARAMETER); | ||
| 1553 | return 0; | ||
| 1554 | } | ||
| 1555 | STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle) | ||
| 1556 | { | ||
| 1557 | struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle; | ||
| 1558 | |||
| 1559 | if (context && context->attributes) | ||
| 1560 | { | ||
| 1561 | STORE_ATTR_INFO *attrs = NULL; | ||
| 1562 | |||
| 1563 | while(context->attributes | ||
| 1564 | && context->attributes->code != STORE_ATTR_OR | ||
| 1565 | && context->attributes->code != STORE_ATTR_END) | ||
| 1566 | { | ||
| 1567 | switch(context->attributes->code) | ||
| 1568 | { | ||
| 1569 | case STORE_ATTR_FRIENDLYNAME: | ||
| 1570 | case STORE_ATTR_EMAIL: | ||
| 1571 | case STORE_ATTR_FILENAME: | ||
| 1572 | if (!attrs) attrs = STORE_ATTR_INFO_new(); | ||
| 1573 | if (attrs == NULL) | ||
| 1574 | { | ||
| 1575 | STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, | ||
| 1576 | ERR_R_MALLOC_FAILURE); | ||
| 1577 | goto err; | ||
| 1578 | } | ||
| 1579 | STORE_ATTR_INFO_set_cstr(attrs, | ||
| 1580 | context->attributes->code, | ||
| 1581 | context->attributes->value, | ||
| 1582 | context->attributes->value_size); | ||
| 1583 | break; | ||
| 1584 | case STORE_ATTR_KEYID: | ||
| 1585 | case STORE_ATTR_ISSUERKEYID: | ||
| 1586 | case STORE_ATTR_SUBJECTKEYID: | ||
| 1587 | case STORE_ATTR_ISSUERSERIALHASH: | ||
| 1588 | case STORE_ATTR_CERTHASH: | ||
| 1589 | if (!attrs) attrs = STORE_ATTR_INFO_new(); | ||
| 1590 | if (attrs == NULL) | ||
| 1591 | { | ||
| 1592 | STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, | ||
| 1593 | ERR_R_MALLOC_FAILURE); | ||
| 1594 | goto err; | ||
| 1595 | } | ||
| 1596 | STORE_ATTR_INFO_set_sha1str(attrs, | ||
| 1597 | context->attributes->code, | ||
| 1598 | context->attributes->value, | ||
| 1599 | context->attributes->value_size); | ||
| 1600 | break; | ||
| 1601 | case STORE_ATTR_ISSUER: | ||
| 1602 | case STORE_ATTR_SUBJECT: | ||
| 1603 | if (!attrs) attrs = STORE_ATTR_INFO_new(); | ||
| 1604 | if (attrs == NULL) | ||
| 1605 | { | ||
| 1606 | STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, | ||
| 1607 | ERR_R_MALLOC_FAILURE); | ||
| 1608 | goto err; | ||
| 1609 | } | ||
| 1610 | STORE_ATTR_INFO_modify_dn(attrs, | ||
| 1611 | context->attributes->code, | ||
| 1612 | context->attributes->value); | ||
| 1613 | break; | ||
| 1614 | case STORE_ATTR_SERIAL: | ||
| 1615 | if (!attrs) attrs = STORE_ATTR_INFO_new(); | ||
| 1616 | if (attrs == NULL) | ||
| 1617 | { | ||
| 1618 | STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, | ||
| 1619 | ERR_R_MALLOC_FAILURE); | ||
| 1620 | goto err; | ||
| 1621 | } | ||
| 1622 | STORE_ATTR_INFO_modify_number(attrs, | ||
| 1623 | context->attributes->code, | ||
| 1624 | context->attributes->value); | ||
| 1625 | break; | ||
| 1626 | } | ||
| 1627 | context->attributes++; | ||
| 1628 | } | ||
| 1629 | if (context->attributes->code == STORE_ATTR_OR) | ||
| 1630 | context->attributes++; | ||
| 1631 | return attrs; | ||
| 1632 | err: | ||
| 1633 | while(context->attributes | ||
| 1634 | && context->attributes->code != STORE_ATTR_OR | ||
| 1635 | && context->attributes->code != STORE_ATTR_END) | ||
| 1636 | context->attributes++; | ||
| 1637 | if (context->attributes->code == STORE_ATTR_OR) | ||
| 1638 | context->attributes++; | ||
| 1639 | return NULL; | ||
| 1640 | } | ||
| 1641 | STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, ERR_R_PASSED_NULL_PARAMETER); | ||
| 1642 | return NULL; | ||
| 1643 | } | ||
| 1644 | int STORE_parse_attrs_end(void *handle) | ||
| 1645 | { | ||
| 1646 | struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle; | ||
| 1647 | |||
| 1648 | if (context && context->attributes) | ||
| 1649 | { | ||
| 1650 | #if 0 | ||
| 1651 | OPENSSL_ITEM *attributes = context->attributes; | ||
| 1652 | #endif | ||
| 1653 | OPENSSL_free(context); | ||
| 1654 | return 1; | ||
| 1655 | } | ||
| 1656 | STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER); | ||
| 1657 | return 0; | ||
| 1658 | } | ||
| 1659 | |||
| 1660 | int STORE_parse_attrs_endp(void *handle) | ||
| 1661 | { | ||
| 1662 | struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle; | ||
| 1663 | |||
| 1664 | if (context && context->attributes) | ||
| 1665 | { | ||
| 1666 | return context->attributes->code == STORE_ATTR_END; | ||
| 1667 | } | ||
| 1668 | STOREerr(STORE_F_STORE_PARSE_ATTRS_ENDP, ERR_R_PASSED_NULL_PARAMETER); | ||
| 1669 | return 0; | ||
| 1670 | } | ||
| 1671 | |||
| 1672 | static int attr_info_compare_compute_range( | ||
| 1673 | const unsigned char *abits, const unsigned char *bbits, | ||
| 1674 | unsigned int *alowp, unsigned int *ahighp, | ||
| 1675 | unsigned int *blowp, unsigned int *bhighp) | ||
| 1676 | { | ||
| 1677 | unsigned int alow = (unsigned int)-1, ahigh = 0; | ||
| 1678 | unsigned int blow = (unsigned int)-1, bhigh = 0; | ||
| 1679 | int i, res = 0; | ||
| 1680 | |||
| 1681 | for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++) | ||
| 1682 | { | ||
| 1683 | if (res == 0) | ||
| 1684 | { | ||
| 1685 | if (*abits < *bbits) res = -1; | ||
| 1686 | if (*abits > *bbits) res = 1; | ||
| 1687 | } | ||
| 1688 | if (*abits) | ||
| 1689 | { | ||
| 1690 | if (alow == (unsigned int)-1) | ||
| 1691 | { | ||
| 1692 | alow = i * 8; | ||
| 1693 | if (!(*abits & 0x01)) alow++; | ||
| 1694 | if (!(*abits & 0x02)) alow++; | ||
| 1695 | if (!(*abits & 0x04)) alow++; | ||
| 1696 | if (!(*abits & 0x08)) alow++; | ||
| 1697 | if (!(*abits & 0x10)) alow++; | ||
| 1698 | if (!(*abits & 0x20)) alow++; | ||
| 1699 | if (!(*abits & 0x40)) alow++; | ||
| 1700 | } | ||
| 1701 | ahigh = i * 8 + 7; | ||
| 1702 | if (!(*abits & 0x80)) ahigh++; | ||
| 1703 | if (!(*abits & 0x40)) ahigh++; | ||
| 1704 | if (!(*abits & 0x20)) ahigh++; | ||
| 1705 | if (!(*abits & 0x10)) ahigh++; | ||
| 1706 | if (!(*abits & 0x08)) ahigh++; | ||
| 1707 | if (!(*abits & 0x04)) ahigh++; | ||
| 1708 | if (!(*abits & 0x02)) ahigh++; | ||
| 1709 | } | ||
| 1710 | if (*bbits) | ||
| 1711 | { | ||
| 1712 | if (blow == (unsigned int)-1) | ||
| 1713 | { | ||
| 1714 | blow = i * 8; | ||
| 1715 | if (!(*bbits & 0x01)) blow++; | ||
| 1716 | if (!(*bbits & 0x02)) blow++; | ||
| 1717 | if (!(*bbits & 0x04)) blow++; | ||
| 1718 | if (!(*bbits & 0x08)) blow++; | ||
| 1719 | if (!(*bbits & 0x10)) blow++; | ||
| 1720 | if (!(*bbits & 0x20)) blow++; | ||
| 1721 | if (!(*bbits & 0x40)) blow++; | ||
| 1722 | } | ||
| 1723 | bhigh = i * 8 + 7; | ||
| 1724 | if (!(*bbits & 0x80)) bhigh++; | ||
| 1725 | if (!(*bbits & 0x40)) bhigh++; | ||
| 1726 | if (!(*bbits & 0x20)) bhigh++; | ||
| 1727 | if (!(*bbits & 0x10)) bhigh++; | ||
| 1728 | if (!(*bbits & 0x08)) bhigh++; | ||
| 1729 | if (!(*bbits & 0x04)) bhigh++; | ||
| 1730 | if (!(*bbits & 0x02)) bhigh++; | ||
| 1731 | } | ||
| 1732 | } | ||
| 1733 | if (ahigh + alow < bhigh + blow) res = -1; | ||
| 1734 | if (ahigh + alow > bhigh + blow) res = 1; | ||
| 1735 | if (alowp) *alowp = alow; | ||
| 1736 | if (ahighp) *ahighp = ahigh; | ||
| 1737 | if (blowp) *blowp = blow; | ||
| 1738 | if (bhighp) *bhighp = bhigh; | ||
| 1739 | return res; | ||
| 1740 | } | ||
| 1741 | |||
| 1742 | int STORE_ATTR_INFO_compare(const STORE_ATTR_INFO * const *a, | ||
| 1743 | const STORE_ATTR_INFO * const *b) | ||
| 1744 | { | ||
| 1745 | if (a == b) return 0; | ||
| 1746 | if (!a) return -1; | ||
| 1747 | if (!b) return 1; | ||
| 1748 | return attr_info_compare_compute_range((*a)->set, (*b)->set, 0, 0, 0, 0); | ||
| 1749 | } | ||
| 1750 | |||
| 1751 | int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b) | ||
| 1752 | { | ||
| 1753 | unsigned int alow, ahigh, blow, bhigh; | ||
| 1754 | |||
| 1755 | if (a == b) return 1; | ||
| 1756 | if (!a) return 0; | ||
| 1757 | if (!b) return 0; | ||
| 1758 | attr_info_compare_compute_range(a->set, b->set, | ||
| 1759 | &alow, &ahigh, &blow, &bhigh); | ||
| 1760 | if (alow >= blow && ahigh <= bhigh) | ||
| 1761 | return 1; | ||
| 1762 | return 0; | ||
| 1763 | } | ||
| 1764 | |||
| 1765 | int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b) | ||
| 1766 | { | ||
| 1767 | unsigned char *abits, *bbits; | ||
| 1768 | int i; | ||
| 1769 | |||
| 1770 | if (a == b) return 1; | ||
| 1771 | if (!a) return 0; | ||
| 1772 | if (!b) return 0; | ||
| 1773 | abits = a->set; | ||
| 1774 | bbits = b->set; | ||
| 1775 | for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++) | ||
| 1776 | { | ||
| 1777 | if (*abits && (*bbits & *abits) != *abits) | ||
| 1778 | return 0; | ||
| 1779 | } | ||
| 1780 | return 1; | ||
| 1781 | } | ||
| 1782 | |||
| 1783 | int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b) | ||
| 1784 | { | ||
| 1785 | STORE_ATTR_TYPES i; | ||
| 1786 | |||
| 1787 | if (a == b) return 1; | ||
| 1788 | if (!STORE_ATTR_INFO_in(a, b)) return 0; | ||
| 1789 | for (i = 1; i < STORE_ATTR_TYPE_NUM; i++) | ||
| 1790 | if (ATTR_IS_SET(a, i)) | ||
| 1791 | { | ||
| 1792 | switch(i) | ||
| 1793 | { | ||
| 1794 | case STORE_ATTR_FRIENDLYNAME: | ||
| 1795 | case STORE_ATTR_EMAIL: | ||
| 1796 | case STORE_ATTR_FILENAME: | ||
| 1797 | if (strcmp(a->values[i].cstring, | ||
| 1798 | b->values[i].cstring)) | ||
| 1799 | return 0; | ||
| 1800 | break; | ||
| 1801 | case STORE_ATTR_KEYID: | ||
| 1802 | case STORE_ATTR_ISSUERKEYID: | ||
| 1803 | case STORE_ATTR_SUBJECTKEYID: | ||
| 1804 | case STORE_ATTR_ISSUERSERIALHASH: | ||
| 1805 | case STORE_ATTR_CERTHASH: | ||
| 1806 | if (memcmp(a->values[i].sha1string, | ||
| 1807 | b->values[i].sha1string, | ||
| 1808 | a->value_sizes[i])) | ||
| 1809 | return 0; | ||
| 1810 | break; | ||
| 1811 | case STORE_ATTR_ISSUER: | ||
| 1812 | case STORE_ATTR_SUBJECT: | ||
| 1813 | if (X509_NAME_cmp(a->values[i].dn, | ||
| 1814 | b->values[i].dn)) | ||
| 1815 | return 0; | ||
| 1816 | break; | ||
| 1817 | case STORE_ATTR_SERIAL: | ||
| 1818 | if (BN_cmp(a->values[i].number, | ||
| 1819 | b->values[i].number)) | ||
| 1820 | return 0; | ||
| 1821 | break; | ||
| 1822 | default: | ||
| 1823 | break; | ||
| 1824 | } | ||
| 1825 | } | ||
| 1826 | |||
| 1827 | return 1; | ||
| 1828 | } | ||
diff --git a/src/lib/libssl/src/crypto/engine/hw_aep_err.h b/src/lib/libcrypto/store/str_locl.h index 8fe4cf921f..3f8cb75619 100644 --- a/src/lib/libssl/src/crypto/engine/hw_aep_err.h +++ b/src/lib/libcrypto/store/str_locl.h | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | /* crypto/store/str_locl.h -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | ||
| 3 | * project 2003. | ||
| 4 | */ | ||
| 1 | /* ==================================================================== | 5 | /* ==================================================================== |
| 2 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | 6 | * Copyright (c) 2003 The OpenSSL Project. All rights reserved. |
| 3 | * | 7 | * |
| 4 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions |
| @@ -52,50 +56,69 @@ | |||
| 52 | * | 56 | * |
| 53 | */ | 57 | */ |
| 54 | 58 | ||
| 55 | #ifndef HEADER_AEPHK_ERR_H | 59 | #ifndef HEADER_STORE_LOCL_H |
| 56 | #define HEADER_AEPHK_ERR_H | 60 | #define HEADER_STORE_LOCL_H |
| 57 | 61 | ||
| 58 | /* BEGIN ERROR CODES */ | 62 | #include <openssl/crypto.h> |
| 59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 63 | #include <openssl/store.h> |
| 60 | * made after this point may be overwritten when the script is next run. | 64 | |
| 61 | */ | 65 | #ifdef __cplusplus |
| 62 | static void ERR_load_AEPHK_strings(void); | 66 | extern "C" { |
| 63 | static void ERR_unload_AEPHK_strings(void); | 67 | #endif |
| 64 | static void ERR_AEPHK_error(int function, int reason, char *file, int line); | 68 | |
| 65 | #define AEPHKerr(f,r) ERR_AEPHK_error((f),(r),__FILE__,__LINE__) | 69 | struct store_method_st |
| 70 | { | ||
| 71 | char *name; | ||
| 66 | 72 | ||
| 67 | /* Error codes for the AEPHK functions. */ | 73 | /* All the functions return a positive integer or non-NULL for success |
| 74 | and 0, a negative integer or NULL for failure */ | ||
| 68 | 75 | ||
| 69 | /* Function codes. */ | 76 | /* Initialise the STORE with private data */ |
| 70 | #define AEPHK_F_AEP_CTRL 100 | 77 | STORE_INITIALISE_FUNC_PTR init; |
| 71 | #define AEPHK_F_AEP_FINISH 101 | 78 | /* Initialise the STORE with private data */ |
| 72 | #define AEPHK_F_AEP_GET_CONNECTION 102 | 79 | STORE_CLEANUP_FUNC_PTR clean; |
| 73 | #define AEPHK_F_AEP_INIT 103 | 80 | /* Generate an object of a given type */ |
| 74 | #define AEPHK_F_AEP_MOD_EXP 104 | 81 | STORE_GENERATE_OBJECT_FUNC_PTR generate_object; |
| 75 | #define AEPHK_F_AEP_MOD_EXP_CRT 105 | 82 | /* Get an object of a given type. This function isn't really very |
| 76 | #define AEPHK_F_AEP_RAND 106 | 83 | useful since the listing functions (below) can be used for the |
| 77 | #define AEPHK_F_AEP_RSA_MOD_EXP 107 | 84 | same purpose and are much more general. */ |
| 85 | STORE_GET_OBJECT_FUNC_PTR get_object; | ||
| 86 | /* Store an object of a given type. */ | ||
| 87 | STORE_STORE_OBJECT_FUNC_PTR store_object; | ||
| 88 | /* Modify the attributes bound to an object of a given type. */ | ||
| 89 | STORE_MODIFY_OBJECT_FUNC_PTR modify_object; | ||
| 90 | /* Revoke an object of a given type. */ | ||
| 91 | STORE_HANDLE_OBJECT_FUNC_PTR revoke_object; | ||
| 92 | /* Delete an object of a given type. */ | ||
| 93 | STORE_HANDLE_OBJECT_FUNC_PTR delete_object; | ||
| 94 | /* List a bunch of objects of a given type and with the associated | ||
| 95 | attributes. */ | ||
| 96 | STORE_START_OBJECT_FUNC_PTR list_object_start; | ||
| 97 | STORE_NEXT_OBJECT_FUNC_PTR list_object_next; | ||
| 98 | STORE_END_OBJECT_FUNC_PTR list_object_end; | ||
| 99 | STORE_END_OBJECT_FUNC_PTR list_object_endp; | ||
| 100 | /* Store-level function to make any necessary update operations. */ | ||
| 101 | STORE_GENERIC_FUNC_PTR update_store; | ||
| 102 | /* Store-level function to get exclusive access to the store. */ | ||
| 103 | STORE_GENERIC_FUNC_PTR lock_store; | ||
| 104 | /* Store-level function to release exclusive access to the store. */ | ||
| 105 | STORE_GENERIC_FUNC_PTR unlock_store; | ||
| 78 | 106 | ||
| 79 | /* Reason codes. */ | 107 | /* Generic control function */ |
| 80 | #define AEPHK_R_ALREADY_LOADED 100 | 108 | STORE_CTRL_FUNC_PTR ctrl; |
| 81 | #define AEPHK_R_CLOSE_HANDLES_FAILED 101 | 109 | }; |
| 82 | #define AEPHK_R_CONNECTIONS_IN_USE 102 | ||
| 83 | #define AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103 | ||
| 84 | #define AEPHK_R_FINALIZE_FAILED 104 | ||
| 85 | #define AEPHK_R_GET_HANDLE_FAILED 105 | ||
| 86 | #define AEPHK_R_GET_RANDOM_FAILED 106 | ||
| 87 | #define AEPHK_R_INIT_FAILURE 107 | ||
| 88 | #define AEPHK_R_MISSING_KEY_COMPONENTS 108 | ||
| 89 | #define AEPHK_R_MOD_EXP_CRT_FAILED 109 | ||
| 90 | #define AEPHK_R_MOD_EXP_FAILED 110 | ||
| 91 | #define AEPHK_R_NOT_LOADED 111 | ||
| 92 | #define AEPHK_R_OK 112 | ||
| 93 | #define AEPHK_R_RETURN_CONNECTION_FAILED 113 | ||
| 94 | #define AEPHK_R_SETBNCALLBACK_FAILURE 114 | ||
| 95 | #define AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL 116 | ||
| 96 | #define AEPHK_R_UNIT_FAILURE 115 | ||
| 97 | 110 | ||
| 111 | struct store_st | ||
| 112 | { | ||
| 113 | const STORE_METHOD *meth; | ||
| 114 | /* functional reference if 'meth' is ENGINE-provided */ | ||
| 115 | ENGINE *engine; | ||
| 116 | |||
| 117 | CRYPTO_EX_DATA ex_data; | ||
| 118 | int references; | ||
| 119 | }; | ||
| 98 | #ifdef __cplusplus | 120 | #ifdef __cplusplus |
| 99 | } | 121 | } |
| 100 | #endif | 122 | #endif |
| 123 | |||
| 101 | #endif | 124 | #endif |
diff --git a/src/lib/libcrypto/store/str_mem.c b/src/lib/libcrypto/store/str_mem.c new file mode 100644 index 0000000000..8ac4f7e55c --- /dev/null +++ b/src/lib/libcrypto/store/str_mem.c | |||
| @@ -0,0 +1,365 @@ | |||
| 1 | /* crypto/store/str_mem.c -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | ||
| 3 | * project 2003. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2003 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * openssl-core@openssl.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <string.h> | ||
| 60 | #include <openssl/err.h> | ||
| 61 | #include "str_locl.h" | ||
| 62 | |||
| 63 | /* The memory store is currently highly experimental. It's meant to become | ||
| 64 | a base store used by other stores for internal caching (for full caching | ||
| 65 | support, aging needs to be added). | ||
| 66 | |||
| 67 | The database use is meant to support as much attribute association as | ||
| 68 | possible, while providing for as small search ranges as possible. | ||
| 69 | This is currently provided for by sorting the entries by numbers that | ||
| 70 | are composed of bits set at the positions indicated by attribute type | ||
| 71 | codes. This provides for ranges determined by the highest attribute | ||
| 72 | type code value. A better idea might be to sort by values computed | ||
| 73 | from the range of attributes associated with the object (basically, | ||
| 74 | the difference between the highest and lowest attribute type code) | ||
| 75 | and it's distance from a base (basically, the lowest associated | ||
| 76 | attribute type code). | ||
| 77 | */ | ||
| 78 | |||
| 79 | typedef struct mem_object_data_st | ||
| 80 | { | ||
| 81 | STORE_OBJECT *object; | ||
| 82 | STORE_ATTR_INFO *attr_info; | ||
| 83 | int references; | ||
| 84 | } MEM_OBJECT_DATA; | ||
| 85 | |||
| 86 | DECLARE_STACK_OF(MEM_OBJECT_DATA) | ||
| 87 | struct mem_data_st | ||
| 88 | { | ||
| 89 | STACK_OF(MEM_OBJECT_DATA) *data; /* sorted with | ||
| 90 | * STORE_ATTR_INFO_compare(). */ | ||
| 91 | unsigned int compute_components : 1; /* Currently unused, but can | ||
| 92 | be used to add attributes | ||
| 93 | from parts of the data. */ | ||
| 94 | }; | ||
| 95 | |||
| 96 | DECLARE_STACK_OF(STORE_ATTR_INFO) | ||
| 97 | struct mem_ctx_st | ||
| 98 | { | ||
| 99 | int type; /* The type we're searching for */ | ||
| 100 | STACK_OF(STORE_ATTR_INFO) *search_attributes; /* Sets of | ||
| 101 | attributes to search for. Each | ||
| 102 | element is a STORE_ATTR_INFO. */ | ||
| 103 | int search_index; /* which of the search attributes we | ||
| 104 | found a match for, -1 when we still | ||
| 105 | haven't found any */ | ||
| 106 | int index; /* -1 as long as we're searching for | ||
| 107 | the first */ | ||
| 108 | }; | ||
| 109 | |||
| 110 | static int mem_init(STORE *s); | ||
| 111 | static void mem_clean(STORE *s); | ||
| 112 | static STORE_OBJECT *mem_generate(STORE *s, STORE_OBJECT_TYPES type, | ||
| 113 | OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); | ||
| 114 | static STORE_OBJECT *mem_get(STORE *s, STORE_OBJECT_TYPES type, | ||
| 115 | OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); | ||
| 116 | static int mem_store(STORE *s, STORE_OBJECT_TYPES type, | ||
| 117 | STORE_OBJECT *data, OPENSSL_ITEM attributes[], | ||
| 118 | OPENSSL_ITEM parameters[]); | ||
| 119 | static int mem_modify(STORE *s, STORE_OBJECT_TYPES type, | ||
| 120 | OPENSSL_ITEM search_attributes[], OPENSSL_ITEM add_attributes[], | ||
| 121 | OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[], | ||
| 122 | OPENSSL_ITEM parameters[]); | ||
| 123 | static int mem_delete(STORE *s, STORE_OBJECT_TYPES type, | ||
| 124 | OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); | ||
| 125 | static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type, | ||
| 126 | OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]); | ||
| 127 | static STORE_OBJECT *mem_list_next(STORE *s, void *handle); | ||
| 128 | static int mem_list_end(STORE *s, void *handle); | ||
| 129 | static int mem_list_endp(STORE *s, void *handle); | ||
| 130 | static int mem_lock(STORE *s, OPENSSL_ITEM attributes[], | ||
| 131 | OPENSSL_ITEM parameters[]); | ||
| 132 | static int mem_unlock(STORE *s, OPENSSL_ITEM attributes[], | ||
| 133 | OPENSSL_ITEM parameters[]); | ||
| 134 | static int mem_ctrl(STORE *s, int cmd, long l, void *p, void (*f)(void)); | ||
| 135 | |||
| 136 | static STORE_METHOD store_memory = | ||
| 137 | { | ||
| 138 | "OpenSSL memory store interface", | ||
| 139 | mem_init, | ||
| 140 | mem_clean, | ||
| 141 | mem_generate, | ||
| 142 | mem_get, | ||
| 143 | mem_store, | ||
| 144 | mem_modify, | ||
| 145 | NULL, /* revoke */ | ||
| 146 | mem_delete, | ||
| 147 | mem_list_start, | ||
| 148 | mem_list_next, | ||
| 149 | mem_list_end, | ||
| 150 | mem_list_endp, | ||
| 151 | NULL, /* update */ | ||
| 152 | mem_lock, | ||
| 153 | mem_unlock, | ||
| 154 | mem_ctrl | ||
| 155 | }; | ||
| 156 | |||
| 157 | const STORE_METHOD *STORE_Memory(void) | ||
| 158 | { | ||
| 159 | return &store_memory; | ||
| 160 | } | ||
| 161 | |||
| 162 | static int mem_init(STORE *s) | ||
| 163 | { | ||
| 164 | return 1; | ||
| 165 | } | ||
| 166 | |||
| 167 | static void mem_clean(STORE *s) | ||
| 168 | { | ||
| 169 | return; | ||
| 170 | } | ||
| 171 | |||
| 172 | static STORE_OBJECT *mem_generate(STORE *s, STORE_OBJECT_TYPES type, | ||
| 173 | OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]) | ||
| 174 | { | ||
| 175 | STOREerr(STORE_F_MEM_GENERATE, STORE_R_NOT_IMPLEMENTED); | ||
| 176 | return 0; | ||
| 177 | } | ||
| 178 | static STORE_OBJECT *mem_get(STORE *s, STORE_OBJECT_TYPES type, | ||
| 179 | OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]) | ||
| 180 | { | ||
| 181 | void *context = mem_list_start(s, type, attributes, parameters); | ||
| 182 | |||
| 183 | if (context) | ||
| 184 | { | ||
| 185 | STORE_OBJECT *object = mem_list_next(s, context); | ||
| 186 | |||
| 187 | if (mem_list_end(s, context)) | ||
| 188 | return object; | ||
| 189 | } | ||
| 190 | return NULL; | ||
| 191 | } | ||
| 192 | static int mem_store(STORE *s, STORE_OBJECT_TYPES type, | ||
| 193 | STORE_OBJECT *data, OPENSSL_ITEM attributes[], | ||
| 194 | OPENSSL_ITEM parameters[]) | ||
| 195 | { | ||
| 196 | STOREerr(STORE_F_MEM_STORE, STORE_R_NOT_IMPLEMENTED); | ||
| 197 | return 0; | ||
| 198 | } | ||
| 199 | static int mem_modify(STORE *s, STORE_OBJECT_TYPES type, | ||
| 200 | OPENSSL_ITEM search_attributes[], OPENSSL_ITEM add_attributes[], | ||
| 201 | OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[], | ||
| 202 | OPENSSL_ITEM parameters[]) | ||
| 203 | { | ||
| 204 | STOREerr(STORE_F_MEM_MODIFY, STORE_R_NOT_IMPLEMENTED); | ||
| 205 | return 0; | ||
| 206 | } | ||
| 207 | static int mem_delete(STORE *s, STORE_OBJECT_TYPES type, | ||
| 208 | OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]) | ||
| 209 | { | ||
| 210 | STOREerr(STORE_F_MEM_DELETE, STORE_R_NOT_IMPLEMENTED); | ||
| 211 | return 0; | ||
| 212 | } | ||
| 213 | |||
| 214 | /* The list functions may be the hardest to understand. Basically, | ||
| 215 | mem_list_start compiles a stack of attribute info elements, and | ||
| 216 | puts that stack into the context to be returned. mem_list_next | ||
| 217 | will then find the first matching element in the store, and then | ||
| 218 | walk all the way to the end of the store (since any combination | ||
| 219 | of attribute bits above the starting point may match the searched | ||
| 220 | for bit pattern...). */ | ||
| 221 | static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type, | ||
| 222 | OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]) | ||
| 223 | { | ||
| 224 | struct mem_ctx_st *context = | ||
| 225 | (struct mem_ctx_st *)OPENSSL_malloc(sizeof(struct mem_ctx_st)); | ||
| 226 | void *attribute_context = NULL; | ||
| 227 | STORE_ATTR_INFO *attrs = NULL; | ||
| 228 | |||
| 229 | if (!context) | ||
| 230 | { | ||
| 231 | STOREerr(STORE_F_MEM_LIST_START, ERR_R_MALLOC_FAILURE); | ||
| 232 | return 0; | ||
| 233 | } | ||
| 234 | memset(context, 0, sizeof(struct mem_ctx_st)); | ||
| 235 | |||
| 236 | attribute_context = STORE_parse_attrs_start(attributes); | ||
| 237 | if (!attribute_context) | ||
| 238 | { | ||
| 239 | STOREerr(STORE_F_MEM_LIST_START, ERR_R_STORE_LIB); | ||
| 240 | goto err; | ||
| 241 | } | ||
| 242 | |||
| 243 | while((attrs = STORE_parse_attrs_next(attribute_context))) | ||
| 244 | { | ||
| 245 | if (context->search_attributes == NULL) | ||
| 246 | { | ||
| 247 | context->search_attributes = | ||
| 248 | sk_STORE_ATTR_INFO_new(STORE_ATTR_INFO_compare); | ||
| 249 | if (!context->search_attributes) | ||
| 250 | { | ||
| 251 | STOREerr(STORE_F_MEM_LIST_START, | ||
| 252 | ERR_R_MALLOC_FAILURE); | ||
| 253 | goto err; | ||
| 254 | } | ||
| 255 | } | ||
| 256 | sk_STORE_ATTR_INFO_push(context->search_attributes,attrs); | ||
| 257 | } | ||
| 258 | if (!STORE_parse_attrs_endp(attribute_context)) | ||
| 259 | goto err; | ||
| 260 | STORE_parse_attrs_end(attribute_context); | ||
| 261 | context->search_index = -1; | ||
| 262 | context->index = -1; | ||
| 263 | return context; | ||
| 264 | err: | ||
| 265 | if (attribute_context) STORE_parse_attrs_end(attribute_context); | ||
| 266 | mem_list_end(s, context); | ||
| 267 | return NULL; | ||
| 268 | } | ||
| 269 | static STORE_OBJECT *mem_list_next(STORE *s, void *handle) | ||
| 270 | { | ||
| 271 | int i; | ||
| 272 | struct mem_ctx_st *context = (struct mem_ctx_st *)handle; | ||
| 273 | struct mem_object_data_st key = { 0, 0, 1 }; | ||
| 274 | struct mem_data_st *store = | ||
| 275 | (struct mem_data_st *)STORE_get_ex_data(s, 1); | ||
| 276 | int srch; | ||
| 277 | int cres = 0; | ||
| 278 | |||
| 279 | if (!context) | ||
| 280 | { | ||
| 281 | STOREerr(STORE_F_MEM_LIST_NEXT, ERR_R_PASSED_NULL_PARAMETER); | ||
| 282 | return NULL; | ||
| 283 | } | ||
| 284 | if (!store) | ||
| 285 | { | ||
| 286 | STOREerr(STORE_F_MEM_LIST_NEXT, STORE_R_NO_STORE); | ||
| 287 | return NULL; | ||
| 288 | } | ||
| 289 | |||
| 290 | if (context->search_index == -1) | ||
| 291 | { | ||
| 292 | for (i = 0; | ||
| 293 | i < sk_STORE_ATTR_INFO_num(context->search_attributes); | ||
| 294 | i++) | ||
| 295 | { | ||
| 296 | key.attr_info | ||
| 297 | = sk_STORE_ATTR_INFO_value(context->search_attributes, | ||
| 298 | i); | ||
| 299 | srch = sk_MEM_OBJECT_DATA_find_ex(store->data, &key); | ||
| 300 | |||
| 301 | if (srch >= 0) | ||
| 302 | { | ||
| 303 | context->search_index = srch; | ||
| 304 | break; | ||
| 305 | } | ||
| 306 | } | ||
| 307 | } | ||
| 308 | if (context->search_index < 0) | ||
| 309 | return NULL; | ||
| 310 | |||
| 311 | key.attr_info = | ||
| 312 | sk_STORE_ATTR_INFO_value(context->search_attributes, | ||
| 313 | context->search_index); | ||
| 314 | for(srch = context->search_index; | ||
| 315 | srch < sk_MEM_OBJECT_DATA_num(store->data) | ||
| 316 | && STORE_ATTR_INFO_in_range(key.attr_info, | ||
| 317 | sk_MEM_OBJECT_DATA_value(store->data, srch)->attr_info) | ||
| 318 | && !(cres = STORE_ATTR_INFO_in_ex(key.attr_info, | ||
| 319 | sk_MEM_OBJECT_DATA_value(store->data, srch)->attr_info)); | ||
| 320 | srch++) | ||
| 321 | ; | ||
| 322 | |||
| 323 | context->search_index = srch; | ||
| 324 | if (cres) | ||
| 325 | return (sk_MEM_OBJECT_DATA_value(store->data, srch))->object; | ||
| 326 | return NULL; | ||
| 327 | } | ||
| 328 | static int mem_list_end(STORE *s, void *handle) | ||
| 329 | { | ||
| 330 | struct mem_ctx_st *context = (struct mem_ctx_st *)handle; | ||
| 331 | |||
| 332 | if (!context) | ||
| 333 | { | ||
| 334 | STOREerr(STORE_F_MEM_LIST_END, ERR_R_PASSED_NULL_PARAMETER); | ||
| 335 | return 0; | ||
| 336 | } | ||
| 337 | if (context && context->search_attributes) | ||
| 338 | sk_STORE_ATTR_INFO_free(context->search_attributes); | ||
| 339 | if (context) OPENSSL_free(context); | ||
| 340 | return 1; | ||
| 341 | } | ||
| 342 | static int mem_list_endp(STORE *s, void *handle) | ||
| 343 | { | ||
| 344 | struct mem_ctx_st *context = (struct mem_ctx_st *)handle; | ||
| 345 | |||
| 346 | if (!context | ||
| 347 | || context->search_index | ||
| 348 | == sk_STORE_ATTR_INFO_num(context->search_attributes)) | ||
| 349 | return 1; | ||
| 350 | return 0; | ||
| 351 | } | ||
| 352 | static int mem_lock(STORE *s, OPENSSL_ITEM attributes[], | ||
| 353 | OPENSSL_ITEM parameters[]) | ||
| 354 | { | ||
| 355 | return 1; | ||
| 356 | } | ||
| 357 | static int mem_unlock(STORE *s, OPENSSL_ITEM attributes[], | ||
| 358 | OPENSSL_ITEM parameters[]) | ||
| 359 | { | ||
| 360 | return 1; | ||
| 361 | } | ||
| 362 | static int mem_ctrl(STORE *s, int cmd, long l, void *p, void (*f)(void)) | ||
| 363 | { | ||
| 364 | return 1; | ||
| 365 | } | ||
diff --git a/src/lib/libcrypto/store/str_meth.c b/src/lib/libcrypto/store/str_meth.c new file mode 100644 index 0000000000..a46de03a26 --- /dev/null +++ b/src/lib/libcrypto/store/str_meth.c | |||
| @@ -0,0 +1,250 @@ | |||
| 1 | /* crypto/store/str_meth.c -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | ||
| 3 | * project 2003. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2003 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * openssl-core@openssl.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <string.h> | ||
| 60 | #include <openssl/buffer.h> | ||
| 61 | #include "str_locl.h" | ||
| 62 | |||
| 63 | STORE_METHOD *STORE_create_method(char *name) | ||
| 64 | { | ||
| 65 | STORE_METHOD *store_method = (STORE_METHOD *)OPENSSL_malloc(sizeof(STORE_METHOD)); | ||
| 66 | |||
| 67 | if (store_method) | ||
| 68 | { | ||
| 69 | memset(store_method, 0, sizeof(*store_method)); | ||
| 70 | store_method->name = BUF_strdup(name); | ||
| 71 | } | ||
| 72 | return store_method; | ||
| 73 | } | ||
| 74 | |||
| 75 | /* BIG FSCKING WARNING!!!! If you use this on a statically allocated method | ||
| 76 | (that is, it hasn't been allocated using STORE_create_method(), you deserve | ||
| 77 | anything Murphy can throw at you and more! You have been warned. */ | ||
| 78 | void STORE_destroy_method(STORE_METHOD *store_method) | ||
| 79 | { | ||
| 80 | if (!store_method) return; | ||
| 81 | OPENSSL_free(store_method->name); | ||
| 82 | store_method->name = NULL; | ||
| 83 | OPENSSL_free(store_method); | ||
| 84 | } | ||
| 85 | |||
| 86 | int STORE_method_set_initialise_function(STORE_METHOD *sm, STORE_INITIALISE_FUNC_PTR init_f) | ||
| 87 | { | ||
| 88 | sm->init = init_f; | ||
| 89 | return 1; | ||
| 90 | } | ||
| 91 | |||
| 92 | int STORE_method_set_cleanup_function(STORE_METHOD *sm, STORE_CLEANUP_FUNC_PTR clean_f) | ||
| 93 | { | ||
| 94 | sm->clean = clean_f; | ||
| 95 | return 1; | ||
| 96 | } | ||
| 97 | |||
| 98 | int STORE_method_set_generate_function(STORE_METHOD *sm, STORE_GENERATE_OBJECT_FUNC_PTR generate_f) | ||
| 99 | { | ||
| 100 | sm->generate_object = generate_f; | ||
| 101 | return 1; | ||
| 102 | } | ||
| 103 | |||
| 104 | int STORE_method_set_get_function(STORE_METHOD *sm, STORE_GET_OBJECT_FUNC_PTR get_f) | ||
| 105 | { | ||
| 106 | sm->get_object = get_f; | ||
| 107 | return 1; | ||
| 108 | } | ||
| 109 | |||
| 110 | int STORE_method_set_store_function(STORE_METHOD *sm, STORE_STORE_OBJECT_FUNC_PTR store_f) | ||
| 111 | { | ||
| 112 | sm->store_object = store_f; | ||
| 113 | return 1; | ||
| 114 | } | ||
| 115 | |||
| 116 | int STORE_method_set_modify_function(STORE_METHOD *sm, STORE_MODIFY_OBJECT_FUNC_PTR modify_f) | ||
| 117 | { | ||
| 118 | sm->modify_object = modify_f; | ||
| 119 | return 1; | ||
| 120 | } | ||
| 121 | |||
| 122 | int STORE_method_set_revoke_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR revoke_f) | ||
| 123 | { | ||
| 124 | sm->revoke_object = revoke_f; | ||
| 125 | return 1; | ||
| 126 | } | ||
| 127 | |||
| 128 | int STORE_method_set_delete_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR delete_f) | ||
| 129 | { | ||
| 130 | sm->delete_object = delete_f; | ||
| 131 | return 1; | ||
| 132 | } | ||
| 133 | |||
| 134 | int STORE_method_set_list_start_function(STORE_METHOD *sm, STORE_START_OBJECT_FUNC_PTR list_start_f) | ||
| 135 | { | ||
| 136 | sm->list_object_start = list_start_f; | ||
| 137 | return 1; | ||
| 138 | } | ||
| 139 | |||
| 140 | int STORE_method_set_list_next_function(STORE_METHOD *sm, STORE_NEXT_OBJECT_FUNC_PTR list_next_f) | ||
| 141 | { | ||
| 142 | sm->list_object_next = list_next_f; | ||
| 143 | return 1; | ||
| 144 | } | ||
| 145 | |||
| 146 | int STORE_method_set_list_end_function(STORE_METHOD *sm, STORE_END_OBJECT_FUNC_PTR list_end_f) | ||
| 147 | { | ||
| 148 | sm->list_object_end = list_end_f; | ||
| 149 | return 1; | ||
| 150 | } | ||
| 151 | |||
| 152 | int STORE_method_set_update_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR update_f) | ||
| 153 | { | ||
| 154 | sm->update_store = update_f; | ||
| 155 | return 1; | ||
| 156 | } | ||
| 157 | |||
| 158 | int STORE_method_set_lock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR lock_f) | ||
| 159 | { | ||
| 160 | sm->lock_store = lock_f; | ||
| 161 | return 1; | ||
| 162 | } | ||
| 163 | |||
| 164 | int STORE_method_set_unlock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR unlock_f) | ||
| 165 | { | ||
| 166 | sm->unlock_store = unlock_f; | ||
| 167 | return 1; | ||
| 168 | } | ||
| 169 | |||
| 170 | int STORE_method_set_ctrl_function(STORE_METHOD *sm, STORE_CTRL_FUNC_PTR ctrl_f) | ||
| 171 | { | ||
| 172 | sm->ctrl = ctrl_f; | ||
| 173 | return 1; | ||
| 174 | } | ||
| 175 | |||
| 176 | STORE_INITIALISE_FUNC_PTR STORE_method_get_initialise_function(STORE_METHOD *sm) | ||
| 177 | { | ||
| 178 | return sm->init; | ||
| 179 | } | ||
| 180 | |||
| 181 | STORE_CLEANUP_FUNC_PTR STORE_method_get_cleanup_function(STORE_METHOD *sm) | ||
| 182 | { | ||
| 183 | return sm->clean; | ||
| 184 | } | ||
| 185 | |||
| 186 | STORE_GENERATE_OBJECT_FUNC_PTR STORE_method_get_generate_function(STORE_METHOD *sm) | ||
| 187 | { | ||
| 188 | return sm->generate_object; | ||
| 189 | } | ||
| 190 | |||
| 191 | STORE_GET_OBJECT_FUNC_PTR STORE_method_get_get_function(STORE_METHOD *sm) | ||
| 192 | { | ||
| 193 | return sm->get_object; | ||
| 194 | } | ||
| 195 | |||
| 196 | STORE_STORE_OBJECT_FUNC_PTR STORE_method_get_store_function(STORE_METHOD *sm) | ||
| 197 | { | ||
| 198 | return sm->store_object; | ||
| 199 | } | ||
| 200 | |||
| 201 | STORE_MODIFY_OBJECT_FUNC_PTR STORE_method_get_modify_function(STORE_METHOD *sm) | ||
| 202 | { | ||
| 203 | return sm->modify_object; | ||
| 204 | } | ||
| 205 | |||
| 206 | STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_revoke_function(STORE_METHOD *sm) | ||
| 207 | { | ||
| 208 | return sm->revoke_object; | ||
| 209 | } | ||
| 210 | |||
| 211 | STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_delete_function(STORE_METHOD *sm) | ||
| 212 | { | ||
| 213 | return sm->delete_object; | ||
| 214 | } | ||
| 215 | |||
| 216 | STORE_START_OBJECT_FUNC_PTR STORE_method_get_list_start_function(STORE_METHOD *sm) | ||
| 217 | { | ||
| 218 | return sm->list_object_start; | ||
| 219 | } | ||
| 220 | |||
| 221 | STORE_NEXT_OBJECT_FUNC_PTR STORE_method_get_list_next_function(STORE_METHOD *sm) | ||
| 222 | { | ||
| 223 | return sm->list_object_next; | ||
| 224 | } | ||
| 225 | |||
| 226 | STORE_END_OBJECT_FUNC_PTR STORE_method_get_list_end_function(STORE_METHOD *sm) | ||
| 227 | { | ||
| 228 | return sm->list_object_end; | ||
| 229 | } | ||
| 230 | |||
| 231 | STORE_GENERIC_FUNC_PTR STORE_method_get_update_store_function(STORE_METHOD *sm) | ||
| 232 | { | ||
| 233 | return sm->update_store; | ||
| 234 | } | ||
| 235 | |||
| 236 | STORE_GENERIC_FUNC_PTR STORE_method_get_lock_store_function(STORE_METHOD *sm) | ||
| 237 | { | ||
| 238 | return sm->lock_store; | ||
| 239 | } | ||
| 240 | |||
| 241 | STORE_GENERIC_FUNC_PTR STORE_method_get_unlock_store_function(STORE_METHOD *sm) | ||
| 242 | { | ||
| 243 | return sm->unlock_store; | ||
| 244 | } | ||
| 245 | |||
| 246 | STORE_CTRL_FUNC_PTR STORE_method_get_ctrl_function(STORE_METHOD *sm) | ||
| 247 | { | ||
| 248 | return sm->ctrl; | ||
| 249 | } | ||
| 250 | |||
diff --git a/src/lib/libcrypto/threads/netware.bat b/src/lib/libcrypto/threads/netware.bat new file mode 100644 index 0000000000..0b3eca3caf --- /dev/null +++ b/src/lib/libcrypto/threads/netware.bat | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | @echo off | ||
| 2 | rem batch file to build multi-thread test ( mttest.nlm ) | ||
| 3 | |||
| 4 | rem command line arguments: | ||
| 5 | rem debug => build using debug settings | ||
| 6 | |||
| 7 | rem | ||
| 8 | rem After building, copy mttest.nlm to the server and run it, you'll probably | ||
| 9 | rem want to redirect stdout and stderr. An example command line would be | ||
| 10 | rem "mttest.nlm -thread 20 -loops 10 -CAfile \openssl\apps\server.pem >mttest.out 2>mttest.err" | ||
| 11 | rem | ||
| 12 | |||
| 13 | del mttest.nlm | ||
| 14 | |||
| 15 | set BLD_DEBUG= | ||
| 16 | set CFLAGS= | ||
| 17 | set LFLAGS= | ||
| 18 | set LIBS= | ||
| 19 | |||
| 20 | if "%1" == "DEBUG" set BLD_DEBUG=YES | ||
| 21 | if "%1" == "debug" set BLD_DEBUG=YES | ||
| 22 | |||
| 23 | if "%MWCIncludes%" == "" goto inc_error | ||
| 24 | if "%PRELUDE%" == "" goto prelude_error | ||
| 25 | if "%IMPORTS%" == "" goto imports_error | ||
| 26 | |||
| 27 | set CFLAGS=-c -I..\..\outinc_nw -nosyspath -DOPENSSL_SYS_NETWARE -opt off -g -sym internal -maxerrors 20 | ||
| 28 | |||
| 29 | if "%BLD_DEBUG%" == "YES" set LIBS=..\..\out_nw.dbg\ssl.lib ..\..\out_nw.dbg\crypto.lib | ||
| 30 | if "%BLD_DEBUG%" == "" set LIBS=..\..\out_nw\ssl.lib ..\..\out_nw\crypto.lib | ||
| 31 | |||
| 32 | set LFLAGS=-msgstyle gcc -zerobss -stacksize 32768 -nostdlib -sym internal | ||
| 33 | |||
| 34 | rem generate command file for metrowerks | ||
| 35 | echo. | ||
| 36 | echo Generating Metrowerks command file: mttest.def | ||
| 37 | echo # dynamically generated command file for metrowerks build > mttest.def | ||
| 38 | echo IMPORT @%IMPORTS%\clib.imp >> mttest.def | ||
| 39 | echo IMPORT @%IMPORTS%\threads.imp >> mttest.def | ||
| 40 | echo IMPORT @%IMPORTS%\ws2nlm.imp >> mttest.def | ||
| 41 | echo IMPORT GetProcessSwitchCount >> mttest.def | ||
| 42 | echo MODULE clib >> mttest.def | ||
| 43 | |||
| 44 | rem compile | ||
| 45 | echo. | ||
| 46 | echo Compiling mttest.c | ||
| 47 | mwccnlm.exe mttest.c %CFLAGS% | ||
| 48 | if errorlevel 1 goto end | ||
| 49 | |||
| 50 | rem link | ||
| 51 | echo. | ||
| 52 | echo Linking mttest.nlm | ||
| 53 | mwldnlm.exe %LFLAGS% -screenname mttest -commandfile mttest.def mttest.o "%PRELUDE%" %LIBS% -o mttest.nlm | ||
| 54 | if errorlevel 1 goto end | ||
| 55 | |||
| 56 | goto end | ||
| 57 | |||
| 58 | :inc_error | ||
| 59 | echo. | ||
| 60 | echo Environment variable MWCIncludes is not set - see install.nw | ||
| 61 | goto end | ||
| 62 | |||
| 63 | :prelude_error | ||
| 64 | echo. | ||
| 65 | echo Environment variable PRELUDE is not set - see install.nw | ||
| 66 | goto end | ||
| 67 | |||
| 68 | :imports_error | ||
| 69 | echo. | ||
| 70 | echo Environment variable IMPORTS is not set - see install.nw | ||
| 71 | goto end | ||
| 72 | |||
| 73 | |||
| 74 | :end | ||
| 75 | set BLD_DEBUG= | ||
| 76 | set CFLAGS= | ||
| 77 | set LFLAGS= | ||
| 78 | set LIBS= | ||
| 79 | |||
diff --git a/src/lib/libcrypto/tmdiff.c b/src/lib/libcrypto/tmdiff.c deleted file mode 100644 index 1c6e052ac9..0000000000 --- a/src/lib/libcrypto/tmdiff.c +++ /dev/null | |||
| @@ -1,260 +0,0 @@ | |||
| 1 | /* crypto/tmdiff.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | #include <stdio.h> | ||
| 59 | #include <stdlib.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/tmdiff.h> | ||
| 62 | #if !defined(OPENSSL_SYS_MSDOS) | ||
| 63 | #include OPENSSL_UNISTD | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #ifdef TIMEB | ||
| 67 | #undef OPENSSL_SYS_WIN32 | ||
| 68 | #undef TIMES | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32) && !(defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX_RHAPSODY) && !defined(OPENSSL_SYS_VXWORKS) | ||
| 72 | # define TIMES | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #ifdef OPENSSL_SYS_NETWARE | ||
| 76 | #undef TIMES | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #if !defined(_IRIX) || defined (OPENSSL_SYS_NETWARE) | ||
| 80 | # include <time.h> | ||
| 81 | #endif | ||
| 82 | #ifdef TIMES | ||
| 83 | # include <sys/types.h> | ||
| 84 | # include <sys/times.h> | ||
| 85 | #endif | ||
| 86 | |||
| 87 | /* Depending on the VMS version, the tms structure is perhaps defined. | ||
| 88 | The __TMS macro will show if it was. If it wasn't defined, we should | ||
| 89 | undefine TIMES, since that tells the rest of the program how things | ||
| 90 | should be handled. -- Richard Levitte */ | ||
| 91 | #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS) | ||
| 92 | #undef TIMES | ||
| 93 | #endif | ||
| 94 | |||
| 95 | #if defined(sun) || defined(__ultrix) | ||
| 96 | #define _POSIX_SOURCE | ||
| 97 | #include <limits.h> | ||
| 98 | #include <sys/param.h> | ||
| 99 | #endif | ||
| 100 | |||
| 101 | #if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE) | ||
| 102 | #include <sys/timeb.h> | ||
| 103 | #endif | ||
| 104 | |||
| 105 | #ifdef OPENSSL_SYS_WIN32 | ||
| 106 | #include <windows.h> | ||
| 107 | #endif | ||
| 108 | |||
| 109 | /* The following if from times(3) man page. It may need to be changed */ | ||
| 110 | #ifndef HZ | ||
| 111 | # if defined(_SC_CLK_TCK) \ | ||
| 112 | && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000) | ||
| 113 | /* # define HZ ((double)sysconf(_SC_CLK_TCK)) */ | ||
| 114 | # define HZ sysconf(_SC_CLK_TCK) | ||
| 115 | # else | ||
| 116 | # ifndef CLK_TCK | ||
| 117 | # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ | ||
| 118 | # define HZ 100.0 | ||
| 119 | # else /* _BSD_CLK_TCK_ */ | ||
| 120 | # define HZ ((double)_BSD_CLK_TCK_) | ||
| 121 | # endif | ||
| 122 | # else /* CLK_TCK */ | ||
| 123 | # define HZ ((double)CLK_TCK) | ||
| 124 | # endif | ||
| 125 | # endif | ||
| 126 | #endif | ||
| 127 | |||
| 128 | struct ms_tm | ||
| 129 | { | ||
| 130 | #ifdef TIMES | ||
| 131 | struct tms ms_tms; | ||
| 132 | #else | ||
| 133 | # ifdef OPENSSL_SYS_WIN32 | ||
| 134 | HANDLE thread_id; | ||
| 135 | FILETIME ms_win32; | ||
| 136 | # elif defined (OPENSSL_SYS_NETWARE) | ||
| 137 | clock_t ms_clock; | ||
| 138 | # else | ||
| 139 | # ifdef OPENSSL_SYS_VXWORKS | ||
| 140 | unsigned long ticks; | ||
| 141 | # else | ||
| 142 | struct timeb ms_timeb; | ||
| 143 | # endif | ||
| 144 | # endif | ||
| 145 | #endif | ||
| 146 | }; | ||
| 147 | |||
| 148 | MS_TM *ms_time_new(void) | ||
| 149 | { | ||
| 150 | MS_TM *ret; | ||
| 151 | |||
| 152 | ret=(MS_TM *)OPENSSL_malloc(sizeof(MS_TM)); | ||
| 153 | if (ret == NULL) | ||
| 154 | return(NULL); | ||
| 155 | memset(ret,0,sizeof(MS_TM)); | ||
| 156 | #ifdef OPENSSL_SYS_WIN32 | ||
| 157 | ret->thread_id=GetCurrentThread(); | ||
| 158 | #endif | ||
| 159 | return ret; | ||
| 160 | } | ||
| 161 | |||
| 162 | void ms_time_free(MS_TM *a) | ||
| 163 | { | ||
| 164 | if (a != NULL) | ||
| 165 | OPENSSL_free(a); | ||
| 166 | } | ||
| 167 | |||
| 168 | void ms_time_get(MS_TM *tm) | ||
| 169 | { | ||
| 170 | #ifdef OPENSSL_SYS_WIN32 | ||
| 171 | FILETIME tmpa,tmpb,tmpc; | ||
| 172 | #endif | ||
| 173 | |||
| 174 | #ifdef TIMES | ||
| 175 | times(&tm->ms_tms); | ||
| 176 | #else | ||
| 177 | # ifdef OPENSSL_SYS_WIN32 | ||
| 178 | GetThreadTimes(tm->thread_id,&tmpa,&tmpb,&tmpc,&(tm->ms_win32)); | ||
| 179 | # elif defined (OPENSSL_SYS_NETWARE) | ||
| 180 | tm->ms_clock = clock(); | ||
| 181 | # else | ||
| 182 | # ifdef OPENSSL_SYS_VXWORKS | ||
| 183 | tm->ticks = tickGet(); | ||
| 184 | # else | ||
| 185 | ftime(&tm->ms_timeb); | ||
| 186 | # endif | ||
| 187 | # endif | ||
| 188 | #endif | ||
| 189 | } | ||
| 190 | |||
| 191 | double ms_time_diff(MS_TM *a, MS_TM *b) | ||
| 192 | { | ||
| 193 | double ret; | ||
| 194 | |||
| 195 | #ifdef TIMES | ||
| 196 | ret = HZ; | ||
| 197 | ret = (b->ms_tms.tms_utime-a->ms_tms.tms_utime) / ret; | ||
| 198 | #else | ||
| 199 | # ifdef OPENSSL_SYS_WIN32 | ||
| 200 | { | ||
| 201 | #ifdef __GNUC__ | ||
| 202 | signed long long la,lb; | ||
| 203 | #else | ||
| 204 | signed _int64 la,lb; | ||
| 205 | #endif | ||
| 206 | la=a->ms_win32.dwHighDateTime; | ||
| 207 | lb=b->ms_win32.dwHighDateTime; | ||
| 208 | la<<=32; | ||
| 209 | lb<<=32; | ||
| 210 | la+=a->ms_win32.dwLowDateTime; | ||
| 211 | lb+=b->ms_win32.dwLowDateTime; | ||
| 212 | ret=((double)(lb-la))/1e7; | ||
| 213 | } | ||
| 214 | # elif defined (OPENSSL_SYS_NETWARE) | ||
| 215 | ret= (double)(b->ms_clock - a->ms_clock); | ||
| 216 | # else | ||
| 217 | # ifdef OPENSSL_SYS_VXWORKS | ||
| 218 | ret = (double)(b->ticks - a->ticks) / (double)sysClkRateGet(); | ||
| 219 | # else | ||
| 220 | ret= (double)(b->ms_timeb.time-a->ms_timeb.time)+ | ||
| 221 | (((double)b->ms_timeb.millitm)- | ||
| 222 | ((double)a->ms_timeb.millitm))/1000.0; | ||
| 223 | # endif | ||
| 224 | # endif | ||
| 225 | #endif | ||
| 226 | return((ret < 0.0000001)?0.0000001:ret); | ||
| 227 | } | ||
| 228 | |||
| 229 | int ms_time_cmp(const MS_TM *a, const MS_TM *b) | ||
| 230 | { | ||
| 231 | double d; | ||
| 232 | int ret; | ||
| 233 | |||
| 234 | #ifdef TIMES | ||
| 235 | d = HZ; | ||
| 236 | d = (b->ms_tms.tms_utime-a->ms_tms.tms_utime) / d; | ||
| 237 | #else | ||
| 238 | # ifdef OPENSSL_SYS_WIN32 | ||
| 239 | d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7; | ||
| 240 | d-=(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7; | ||
| 241 | # elif defined (OPENSSL_SYS_NETWARE) | ||
| 242 | d= (double)(b->ms_clock - a->ms_clock); | ||
| 243 | # else | ||
| 244 | # ifdef OPENSSL_SYS_VXWORKS | ||
| 245 | d = (b->ticks - a->ticks); | ||
| 246 | # else | ||
| 247 | d= (double)(b->ms_timeb.time-a->ms_timeb.time)+ | ||
| 248 | (((double)b->ms_timeb.millitm)-(double)a->ms_timeb.millitm)/1000.0; | ||
| 249 | # endif | ||
| 250 | # endif | ||
| 251 | #endif | ||
| 252 | if (d == 0.0) | ||
| 253 | ret=0; | ||
| 254 | else if (d < 0) | ||
| 255 | ret= -1; | ||
| 256 | else | ||
| 257 | ret=1; | ||
| 258 | return(ret); | ||
| 259 | } | ||
| 260 | |||
diff --git a/src/lib/libcrypto/tmdiff.h b/src/lib/libcrypto/tmdiff.h deleted file mode 100644 index af5c41c649..0000000000 --- a/src/lib/libcrypto/tmdiff.h +++ /dev/null | |||
| @@ -1,93 +0,0 @@ | |||
| 1 | /* crypto/tmdiff.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* Header for dynamic hash table routines | ||
| 60 | * Author - Eric Young | ||
| 61 | */ | ||
| 62 | /* ... erm yeah, "dynamic hash tables" you say? | ||
| 63 | * | ||
| 64 | * And what would dynamic hash tables have to do with any of this code *now*? | ||
| 65 | * AFAICS, this code is only referenced by crypto/bn/exp.c which is an unused | ||
| 66 | * file that I doubt compiles any more. speed.c is the only thing that could | ||
| 67 | * use this (and it has nothing to do with hash tables), yet it instead has its | ||
| 68 | * own duplication of all this stuff and looks, if anything, more complete. See | ||
| 69 | * the corresponding note in apps/speed.c. | ||
| 70 | * The Bemused - Geoff | ||
| 71 | */ | ||
| 72 | |||
| 73 | #ifndef HEADER_TMDIFF_H | ||
| 74 | #define HEADER_TMDIFF_H | ||
| 75 | |||
| 76 | #ifdef __cplusplus | ||
| 77 | extern "C" { | ||
| 78 | #endif | ||
| 79 | |||
| 80 | typedef struct ms_tm MS_TM; | ||
| 81 | |||
| 82 | MS_TM *ms_time_new(void ); | ||
| 83 | void ms_time_free(MS_TM *a); | ||
| 84 | void ms_time_get(MS_TM *a); | ||
| 85 | double ms_time_diff(MS_TM *start, MS_TM *end); | ||
| 86 | int ms_time_cmp(const MS_TM *ap, const MS_TM *bp); | ||
| 87 | |||
| 88 | #ifdef __cplusplus | ||
| 89 | } | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #endif | ||
| 93 | |||
diff --git a/src/lib/libcrypto/ts/Makefile b/src/lib/libcrypto/ts/Makefile new file mode 100644 index 0000000000..c18234555b --- /dev/null +++ b/src/lib/libcrypto/ts/Makefile | |||
| @@ -0,0 +1,269 @@ | |||
| 1 | # | ||
| 2 | # SSLeay/crypto/ts/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= ts | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | INCLUDES= -I.. -I../../include | ||
| 9 | CFLAG = -g | ||
| 10 | INSTALL_PREFIX= | ||
| 11 | OPENSSLDIR= /usr/local/ssl | ||
| 12 | INSTALLTOP=/usr/local/ssl | ||
| 13 | MAKEDEPPROG= makedepend | ||
| 14 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
| 15 | MAKEFILE= Makefile | ||
| 16 | AR= ar r | ||
| 17 | |||
| 18 | PEX_LIBS= | ||
| 19 | EX_LIBS= | ||
| 20 | |||
| 21 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 22 | |||
| 23 | GENERAL= Makefile | ||
| 24 | TEST= | ||
| 25 | APPS= | ||
| 26 | |||
| 27 | LIB=$(TOP)/libcrypto.a | ||
| 28 | LIBSRC= ts_err.c ts_req_utils.c ts_req_print.c ts_rsp_utils.c ts_rsp_print.c \ | ||
| 29 | ts_rsp_sign.c ts_rsp_verify.c ts_verify_ctx.c ts_lib.c ts_conf.c \ | ||
| 30 | ts_asn1.c | ||
| 31 | LIBOBJ= ts_err.o ts_req_utils.o ts_req_print.o ts_rsp_utils.o ts_rsp_print.o \ | ||
| 32 | ts_rsp_sign.o ts_rsp_verify.o ts_verify_ctx.o ts_lib.o ts_conf.o \ | ||
| 33 | ts_asn1.o | ||
| 34 | |||
| 35 | SRC= $(LIBSRC) | ||
| 36 | |||
| 37 | EXHEADER= ts.h | ||
| 38 | HEADER= $(EXHEADER) | ||
| 39 | |||
| 40 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 41 | |||
| 42 | top: | ||
| 43 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 44 | |||
| 45 | test: | ||
| 46 | |||
| 47 | all: lib | ||
| 48 | |||
| 49 | lib: $(LIBOBJ) | ||
| 50 | $(AR) $(LIB) $(LIBOBJ) | ||
| 51 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 52 | @touch lib | ||
| 53 | |||
| 54 | files: | ||
| 55 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 56 | |||
| 57 | links: | ||
| 58 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 59 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 60 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 61 | |||
| 62 | install: | ||
| 63 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 64 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 65 | do \ | ||
| 66 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 67 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 68 | done; | ||
| 69 | |||
| 70 | tags: | ||
| 71 | ctags $(SRC) | ||
| 72 | |||
| 73 | lint: | ||
| 74 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 75 | |||
| 76 | depend: | ||
| 77 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC) | ||
| 78 | |||
| 79 | dclean: | ||
| 80 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 81 | mv -f Makefile.new $(MAKEFILE) | ||
| 82 | |||
| 83 | clean: | ||
| 84 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff enc dec sign verify | ||
| 85 | |||
| 86 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 87 | |||
| 88 | ts_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
| 89 | ts_asn1.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 90 | ts_asn1.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 91 | ts_asn1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 92 | ts_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 93 | ts_asn1.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 94 | ts_asn1.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 95 | ts_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 96 | ts_asn1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 97 | ts_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 98 | ts_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h | ||
| 99 | ts_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 100 | ts_asn1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 101 | ts_asn1.o: ../../include/openssl/ts.h ../../include/openssl/x509.h | ||
| 102 | ts_asn1.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 103 | ts_asn1.o: ts_asn1.c | ||
| 104 | ts_conf.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 105 | ts_conf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 106 | ts_conf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 107 | ts_conf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 108 | ts_conf.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 109 | ts_conf.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 110 | ts_conf.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
| 111 | ts_conf.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 112 | ts_conf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 113 | ts_conf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 114 | ts_conf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
| 115 | ts_conf.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h | ||
| 116 | ts_conf.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 117 | ts_conf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 118 | ts_conf.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h | ||
| 119 | ts_conf.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 120 | ts_conf.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_conf.c | ||
| 121 | ts_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 122 | ts_err.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h | ||
| 123 | ts_err.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
| 124 | ts_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 125 | ts_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 126 | ts_err.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 127 | ts_err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 128 | ts_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 129 | ts_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 130 | ts_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 131 | ts_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 132 | ts_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 133 | ts_err.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h | ||
| 134 | ts_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 135 | ts_err.o: ../../include/openssl/x509v3.h ts_err.c | ||
| 136 | ts_lib.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 137 | ts_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 138 | ts_lib.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 139 | ts_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 140 | ts_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 141 | ts_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 142 | ts_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 143 | ts_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 144 | ts_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 145 | ts_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 146 | ts_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h | ||
| 147 | ts_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 148 | ts_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 149 | ts_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 150 | ts_lib.o: ../../include/openssl/x509v3.h ../cryptlib.h ts.h ts_lib.c | ||
| 151 | ts_req_print.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 152 | ts_req_print.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 153 | ts_req_print.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h | ||
| 154 | ts_req_print.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
| 155 | ts_req_print.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 156 | ts_req_print.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 157 | ts_req_print.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 158 | ts_req_print.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 159 | ts_req_print.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 160 | ts_req_print.o: ../../include/openssl/opensslconf.h | ||
| 161 | ts_req_print.o: ../../include/openssl/opensslv.h | ||
| 162 | ts_req_print.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 163 | ts_req_print.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 164 | ts_req_print.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 165 | ts_req_print.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h | ||
| 166 | ts_req_print.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 167 | ts_req_print.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_req_print.c | ||
| 168 | ts_req_utils.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 169 | ts_req_utils.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 170 | ts_req_utils.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 171 | ts_req_utils.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 172 | ts_req_utils.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 173 | ts_req_utils.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 174 | ts_req_utils.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 175 | ts_req_utils.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 176 | ts_req_utils.o: ../../include/openssl/objects.h | ||
| 177 | ts_req_utils.o: ../../include/openssl/opensslconf.h | ||
| 178 | ts_req_utils.o: ../../include/openssl/opensslv.h | ||
| 179 | ts_req_utils.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 180 | ts_req_utils.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 181 | ts_req_utils.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 182 | ts_req_utils.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h | ||
| 183 | ts_req_utils.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 184 | ts_req_utils.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_req_utils.c | ||
| 185 | ts_rsp_print.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 186 | ts_rsp_print.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 187 | ts_rsp_print.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h | ||
| 188 | ts_rsp_print.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
| 189 | ts_rsp_print.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
| 190 | ts_rsp_print.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
| 191 | ts_rsp_print.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
| 192 | ts_rsp_print.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
| 193 | ts_rsp_print.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 194 | ts_rsp_print.o: ../../include/openssl/opensslconf.h | ||
| 195 | ts_rsp_print.o: ../../include/openssl/opensslv.h | ||
| 196 | ts_rsp_print.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 197 | ts_rsp_print.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 198 | ts_rsp_print.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 199 | ts_rsp_print.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
| 200 | ts_rsp_print.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
| 201 | ts_rsp_print.o: ../cryptlib.h ts.h ts_rsp_print.c | ||
| 202 | ts_rsp_sign.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 203 | ts_rsp_sign.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 204 | ts_rsp_sign.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 205 | ts_rsp_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 206 | ts_rsp_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 207 | ts_rsp_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 208 | ts_rsp_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 209 | ts_rsp_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 210 | ts_rsp_sign.o: ../../include/openssl/objects.h | ||
| 211 | ts_rsp_sign.o: ../../include/openssl/opensslconf.h | ||
| 212 | ts_rsp_sign.o: ../../include/openssl/opensslv.h | ||
| 213 | ts_rsp_sign.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 214 | ts_rsp_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 215 | ts_rsp_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 216 | ts_rsp_sign.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h | ||
| 217 | ts_rsp_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 218 | ts_rsp_sign.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_rsp_sign.c | ||
| 219 | ts_rsp_utils.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 220 | ts_rsp_utils.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 221 | ts_rsp_utils.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 222 | ts_rsp_utils.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 223 | ts_rsp_utils.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 224 | ts_rsp_utils.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 225 | ts_rsp_utils.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 226 | ts_rsp_utils.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 227 | ts_rsp_utils.o: ../../include/openssl/objects.h | ||
| 228 | ts_rsp_utils.o: ../../include/openssl/opensslconf.h | ||
| 229 | ts_rsp_utils.o: ../../include/openssl/opensslv.h | ||
| 230 | ts_rsp_utils.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 231 | ts_rsp_utils.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 232 | ts_rsp_utils.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 233 | ts_rsp_utils.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h | ||
| 234 | ts_rsp_utils.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 235 | ts_rsp_utils.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_rsp_utils.c | ||
| 236 | ts_rsp_verify.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 237 | ts_rsp_verify.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 238 | ts_rsp_verify.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 239 | ts_rsp_verify.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 240 | ts_rsp_verify.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 241 | ts_rsp_verify.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 242 | ts_rsp_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 243 | ts_rsp_verify.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 244 | ts_rsp_verify.o: ../../include/openssl/objects.h | ||
| 245 | ts_rsp_verify.o: ../../include/openssl/opensslconf.h | ||
| 246 | ts_rsp_verify.o: ../../include/openssl/opensslv.h | ||
| 247 | ts_rsp_verify.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 248 | ts_rsp_verify.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 249 | ts_rsp_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 250 | ts_rsp_verify.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h | ||
| 251 | ts_rsp_verify.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 252 | ts_rsp_verify.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_rsp_verify.c | ||
| 253 | ts_verify_ctx.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 254 | ts_verify_ctx.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
| 255 | ts_verify_ctx.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h | ||
| 256 | ts_verify_ctx.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 257 | ts_verify_ctx.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h | ||
| 258 | ts_verify_ctx.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h | ||
| 259 | ts_verify_ctx.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
| 260 | ts_verify_ctx.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
| 261 | ts_verify_ctx.o: ../../include/openssl/objects.h | ||
| 262 | ts_verify_ctx.o: ../../include/openssl/opensslconf.h | ||
| 263 | ts_verify_ctx.o: ../../include/openssl/opensslv.h | ||
| 264 | ts_verify_ctx.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
| 265 | ts_verify_ctx.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
| 266 | ts_verify_ctx.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 267 | ts_verify_ctx.o: ../../include/openssl/symhacks.h ../../include/openssl/ts.h | ||
| 268 | ts_verify_ctx.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
| 269 | ts_verify_ctx.o: ../../include/openssl/x509v3.h ../cryptlib.h ts_verify_ctx.c | ||
diff --git a/src/lib/libcrypto/util/arx.pl b/src/lib/libcrypto/util/arx.pl deleted file mode 100644 index ce62625c33..0000000000 --- a/src/lib/libcrypto/util/arx.pl +++ /dev/null | |||
| @@ -1,15 +0,0 @@ | |||
| 1 | #!/bin/perl | ||
| 2 | |||
| 3 | # Simple perl script to wrap round "ar" program and exclude any | ||
| 4 | # object files in the environment variable EXCL_OBJ | ||
| 5 | |||
| 6 | map { s/^.*\/([^\/]*)$/$1/ ; $EXCL{$_} = 1} split(' ', $ENV{EXCL_OBJ}); | ||
| 7 | |||
| 8 | #my @ks = keys %EXCL; | ||
| 9 | #print STDERR "Excluding: @ks \n"; | ||
| 10 | |||
| 11 | my @ARGS = grep { !exists $EXCL{$_} } @ARGV; | ||
| 12 | |||
| 13 | system @ARGS; | ||
| 14 | |||
| 15 | exit $? >> 8; | ||
diff --git a/src/lib/libcrypto/util/checkhash.pl b/src/lib/libcrypto/util/checkhash.pl deleted file mode 100644 index c61fa72178..0000000000 --- a/src/lib/libcrypto/util/checkhash.pl +++ /dev/null | |||
| @@ -1,222 +0,0 @@ | |||
| 1 | #!/usr/bin/env perl -w | ||
| 2 | |||
| 3 | my $package = caller; | ||
| 4 | |||
| 5 | if (!(defined $package)) | ||
| 6 | { | ||
| 7 | my $retval = check_hashes(@ARGV); | ||
| 8 | exit $retval; | ||
| 9 | } | ||
| 10 | |||
| 11 | 1; | ||
| 12 | |||
| 13 | sub check_hashes | ||
| 14 | { | ||
| 15 | |||
| 16 | my @args = @_; | ||
| 17 | |||
| 18 | my $change_dir = ""; | ||
| 19 | my $check_program = "sha/fips_standalone_sha1"; | ||
| 20 | |||
| 21 | my $verbose = 0; | ||
| 22 | my $badfiles = 0; | ||
| 23 | my $rebuild = 0; | ||
| 24 | my $force_rewrite = 0; | ||
| 25 | my $hash_file = "fipshashes.c"; | ||
| 26 | my $recurse = 0; | ||
| 27 | |||
| 28 | my @fingerprint_files; | ||
| 29 | |||
| 30 | while (@args) | ||
| 31 | { | ||
| 32 | my $arg = $args[0]; | ||
| 33 | if ($arg eq "-chdir") | ||
| 34 | { | ||
| 35 | shift @args; | ||
| 36 | $change_dir = shift @args; | ||
| 37 | } | ||
| 38 | elsif ($arg eq "-rebuild") | ||
| 39 | { | ||
| 40 | shift @args; | ||
| 41 | $rebuild = 1; | ||
| 42 | } | ||
| 43 | elsif ($arg eq "-verbose") | ||
| 44 | { | ||
| 45 | shift @args; | ||
| 46 | $verbose = 1; | ||
| 47 | } | ||
| 48 | elsif ($arg eq "-force-rewrite") | ||
| 49 | { | ||
| 50 | shift @args; | ||
| 51 | $force_rewrite = 1; | ||
| 52 | } | ||
| 53 | elsif ($arg eq "-hash_file") | ||
| 54 | { | ||
| 55 | shift @args; | ||
| 56 | $hash_file = shift @args; | ||
| 57 | } | ||
| 58 | elsif ($arg eq "-recurse") | ||
| 59 | { | ||
| 60 | shift @args; | ||
| 61 | $recurse = 1; | ||
| 62 | } | ||
| 63 | elsif ($arg eq "-program_path") | ||
| 64 | { | ||
| 65 | shift @args; | ||
| 66 | $check_program = shift @args; | ||
| 67 | } | ||
| 68 | else | ||
| 69 | { | ||
| 70 | print STDERR "Unknown Option $arg"; | ||
| 71 | return 1; | ||
| 72 | } | ||
| 73 | |||
| 74 | } | ||
| 75 | |||
| 76 | chdir $change_dir if $change_dir ne ""; | ||
| 77 | |||
| 78 | if ($recurse) | ||
| 79 | { | ||
| 80 | @fingerprint_files = ("fingerprint.sha1", | ||
| 81 | <*/fingerprint.sha1>); | ||
| 82 | } | ||
| 83 | else | ||
| 84 | { | ||
| 85 | push @fingerprint_files, $hash_file; | ||
| 86 | } | ||
| 87 | |||
| 88 | foreach $fp (@fingerprint_files) | ||
| 89 | { | ||
| 90 | if (!open(IN, "$fp")) | ||
| 91 | { | ||
| 92 | print STDERR "Can't open file $fp"; | ||
| 93 | return 1; | ||
| 94 | } | ||
| 95 | print STDERR "Opening Fingerprint file $fp\n" if $verbose; | ||
| 96 | my $dir = $fp; | ||
| 97 | $dir =~ s/[^\/]*$//; | ||
| 98 | while (<IN>) | ||
| 99 | { | ||
| 100 | chomp; | ||
| 101 | if (!(($file, $hash) = /^\"HMAC-SHA1\((.*)\)\s*=\s*(\w*)\",$/)) | ||
| 102 | { | ||
| 103 | /^\"/ || next; | ||
| 104 | print STDERR "FATAL: Invalid syntax in file $fp\n"; | ||
| 105 | print STDERR "Line:\n$_\n"; | ||
| 106 | fatal_error(); | ||
| 107 | return 1; | ||
| 108 | } | ||
| 109 | if (!$rebuild && length($hash) != 40) | ||
| 110 | { | ||
| 111 | print STDERR "FATAL: Invalid hash length in $fp for file $file\n"; | ||
| 112 | fatal_error(); | ||
| 113 | return 1; | ||
| 114 | } | ||
| 115 | push @hashed_files, "$dir$file"; | ||
| 116 | if (exists $hashes{"$dir$file"}) | ||
| 117 | { | ||
| 118 | print STDERR "FATAL: Duplicate Hash file $dir$file\n"; | ||
| 119 | fatal_error(); | ||
| 120 | return 1; | ||
| 121 | } | ||
| 122 | if (! -r "$dir$file") | ||
| 123 | { | ||
| 124 | print STDERR "FATAL: Can't access $dir$file\n"; | ||
| 125 | fatal_error(); | ||
| 126 | return 1; | ||
| 127 | } | ||
| 128 | $hashes{"$dir$file"} = $hash; | ||
| 129 | } | ||
| 130 | close IN; | ||
| 131 | } | ||
| 132 | |||
| 133 | @checked_hashes = `$check_program @hashed_files`; | ||
| 134 | |||
| 135 | if ($? != 0) | ||
| 136 | { | ||
| 137 | print STDERR "Error running hash program $check_program\n"; | ||
| 138 | fatal_error(); | ||
| 139 | return 1; | ||
| 140 | } | ||
| 141 | |||
| 142 | if (@checked_hashes != @hashed_files) | ||
| 143 | { | ||
| 144 | print STDERR "FATAL: hash count incorrect\n"; | ||
| 145 | fatal_error(); | ||
| 146 | return 1; | ||
| 147 | } | ||
| 148 | |||
| 149 | foreach (@checked_hashes) | ||
| 150 | { | ||
| 151 | chomp; | ||
| 152 | if (!(($file, $hash) = /^HMAC-SHA1\((.*)\)\s*=\s*(\w*)$/)) | ||
| 153 | { | ||
| 154 | print STDERR "FATAL: Invalid syntax in file $fp\n"; | ||
| 155 | print STDERR "Line:\n$_\n"; | ||
| 156 | fatal_error(); | ||
| 157 | return 1; | ||
| 158 | } | ||
| 159 | if (length($hash) != 40) | ||
| 160 | { | ||
| 161 | print STDERR "FATAL: Invalid hash length for file $file\n"; | ||
| 162 | fatal_error(); | ||
| 163 | return 1; | ||
| 164 | } | ||
| 165 | if ($hash ne $hashes{$file}) | ||
| 166 | { | ||
| 167 | if ($rebuild) | ||
| 168 | { | ||
| 169 | print STDERR "Updating hash on file $file\n"; | ||
| 170 | $hashes{$file} = $hash; | ||
| 171 | } | ||
| 172 | else | ||
| 173 | { | ||
| 174 | print STDERR "Hash check failed for file $file\n"; | ||
| 175 | } | ||
| 176 | $badfiles++; | ||
| 177 | } | ||
| 178 | elsif ($verbose) | ||
| 179 | { print "Hash Check OK for $file\n";} | ||
| 180 | } | ||
| 181 | |||
| 182 | |||
| 183 | if ($badfiles && !$rebuild) | ||
| 184 | { | ||
| 185 | print STDERR "FATAL: hash mismatch on $badfiles files\n"; | ||
| 186 | fatal_error(); | ||
| 187 | return 1; | ||
| 188 | } | ||
| 189 | |||
| 190 | if ($badfiles || $force_rewrite) | ||
| 191 | { | ||
| 192 | print "Updating Hash file $hash_file\n"; | ||
| 193 | if (!open(OUT, ">$hash_file")) | ||
| 194 | { | ||
| 195 | print STDERR "Error rewriting $hash_file"; | ||
| 196 | return 1; | ||
| 197 | } | ||
| 198 | print OUT "const char * const FIPS_source_hashes[] = {\n"; | ||
| 199 | foreach (@hashed_files) | ||
| 200 | { | ||
| 201 | print OUT "\"HMAC-SHA1($_)= $hashes{$_}\",\n"; | ||
| 202 | } | ||
| 203 | print OUT "};\n"; | ||
| 204 | close OUT; | ||
| 205 | } | ||
| 206 | |||
| 207 | if (!$badfiles) | ||
| 208 | { | ||
| 209 | print "FIPS hash check successful\n"; | ||
| 210 | } | ||
| 211 | |||
| 212 | return 0; | ||
| 213 | |||
| 214 | } | ||
| 215 | |||
| 216 | |||
| 217 | sub fatal_error | ||
| 218 | { | ||
| 219 | print STDERR "*** Your source code does not match the FIPS validated source ***\n"; | ||
| 220 | } | ||
| 221 | |||
| 222 | |||
diff --git a/src/lib/libcrypto/util/copy.pl b/src/lib/libcrypto/util/copy.pl new file mode 100644 index 0000000000..e20b45530a --- /dev/null +++ b/src/lib/libcrypto/util/copy.pl | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | use Fcntl; | ||
| 4 | |||
| 5 | |||
| 6 | # copy.pl | ||
| 7 | |||
| 8 | # Perl script 'copy' comment. On Windows the built in "copy" command also | ||
| 9 | # copies timestamps: this messes up Makefile dependencies. | ||
| 10 | |||
| 11 | my $arg; | ||
| 12 | |||
| 13 | foreach $arg (@ARGV) { | ||
| 14 | $arg =~ s|\\|/|g; # compensate for bug/feature in cygwin glob... | ||
| 15 | foreach (glob $arg) | ||
| 16 | { | ||
| 17 | push @filelist, $_; | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | $fnum = @filelist; | ||
| 22 | |||
| 23 | if ($fnum <= 1) | ||
| 24 | { | ||
| 25 | die "Need at least two filenames"; | ||
| 26 | } | ||
| 27 | |||
| 28 | $dest = pop @filelist; | ||
| 29 | |||
| 30 | if ($fnum > 2 && ! -d $dest) | ||
| 31 | { | ||
| 32 | die "Destination must be a directory"; | ||
| 33 | } | ||
| 34 | |||
| 35 | foreach (@filelist) | ||
| 36 | { | ||
| 37 | if (-d $dest) | ||
| 38 | { | ||
| 39 | $dfile = $_; | ||
| 40 | $dfile =~ s|^.*[/\\]([^/\\]*)$|$1|; | ||
| 41 | $dfile = "$dest/$dfile"; | ||
| 42 | } | ||
| 43 | else | ||
| 44 | { | ||
| 45 | $dfile = $dest; | ||
| 46 | } | ||
| 47 | sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_"; | ||
| 48 | sysopen(OUT, $dfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY) | ||
| 49 | || die "Can't Open $dfile"; | ||
| 50 | while (sysread IN, $buf, 10240) | ||
| 51 | { | ||
| 52 | syswrite(OUT, $buf, length($buf)); | ||
| 53 | } | ||
| 54 | close(IN); | ||
| 55 | close(OUT); | ||
| 56 | print "Copying: $_ to $dfile\n"; | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
diff --git a/src/lib/libcrypto/util/extract-section.pl b/src/lib/libcrypto/util/extract-section.pl new file mode 100644 index 0000000000..7a0ba4f69a --- /dev/null +++ b/src/lib/libcrypto/util/extract-section.pl | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | while(<STDIN>) { | ||
| 4 | if (/=for\s+comment\s+openssl_manual_section:(\S+)/) | ||
| 5 | { | ||
| 6 | print "$1\n"; | ||
| 7 | exit 0; | ||
| 8 | } | ||
| 9 | } | ||
| 10 | |||
| 11 | print "$ARGV[0]\n"; | ||
| 12 | |||
diff --git a/src/lib/libcrypto/util/fipslink.pl b/src/lib/libcrypto/util/fipslink.pl deleted file mode 100644 index 3597bc1740..0000000000 --- a/src/lib/libcrypto/util/fipslink.pl +++ /dev/null | |||
| @@ -1,78 +0,0 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | sub check_env | ||
| 4 | { | ||
| 5 | my @ret; | ||
| 6 | foreach (@_) | ||
| 7 | { | ||
| 8 | die "Environment variable $_ not defined!\n" unless exists $ENV{$_}; | ||
| 9 | push @ret, $ENV{$_}; | ||
| 10 | } | ||
| 11 | return @ret; | ||
| 12 | } | ||
| 13 | |||
| 14 | |||
| 15 | my ($fips_cc,$fips_cc_args, $fips_link,$fips_target, $fips_libdir, $sha1_exe) | ||
| 16 | = check_env("FIPS_CC", "FIPS_CC_ARGS", "FIPS_LINK", "FIPS_TARGET", | ||
| 17 | "FIPSLIB_D", "FIPS_SHA1_EXE"); | ||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | if (exists $ENV{"PREMAIN_DSO_EXE"}) | ||
| 22 | { | ||
| 23 | $fips_premain_dso = $ENV{"PREMAIN_DSO_EXE"}; | ||
| 24 | } | ||
| 25 | else | ||
| 26 | { | ||
| 27 | $fips_premain_dso = ""; | ||
| 28 | } | ||
| 29 | |||
| 30 | check_hash($sha1_exe, "fips_premain.c"); | ||
| 31 | check_hash($sha1_exe, "fipscanister.lib"); | ||
| 32 | |||
| 33 | |||
| 34 | print "Integrity check OK\n"; | ||
| 35 | |||
| 36 | print "$fips_cc $fips_cc_args $fips_libdir/fips_premain.c\n"; | ||
| 37 | system "$fips_cc $fips_cc_args $fips_libdir/fips_premain.c"; | ||
| 38 | die "First stage Compile failure" if $? != 0; | ||
| 39 | |||
| 40 | print "$fips_link @ARGV\n"; | ||
| 41 | system "$fips_link @ARGV"; | ||
| 42 | die "First stage Link failure" if $? != 0; | ||
| 43 | |||
| 44 | |||
| 45 | print "$fips_premain_dso $fips_target\n"; | ||
| 46 | $fips_hash=`$fips_premain_dso $fips_target`; | ||
| 47 | chomp $fips_hash; | ||
| 48 | die "Get hash failure" if $? != 0; | ||
| 49 | |||
| 50 | |||
| 51 | print "$fips_cc -DHMAC_SHA1_SIG=\\\"$fips_hash\\\" $fips_cc_args $fips_libdir/fips_premain.c\n"; | ||
| 52 | system "$fips_cc -DHMAC_SHA1_SIG=\\\"$fips_hash\\\" $fips_cc_args $fips_libdir/fips_premain.c"; | ||
| 53 | die "Second stage Compile failure" if $? != 0; | ||
| 54 | |||
| 55 | |||
| 56 | print "$fips_link @ARGV\n"; | ||
| 57 | system "$fips_link @ARGV"; | ||
| 58 | die "Second stage Link failure" if $? != 0; | ||
| 59 | |||
| 60 | sub check_hash | ||
| 61 | { | ||
| 62 | my ($sha1_exe, $filename) = @_; | ||
| 63 | my ($hashfile, $hashval); | ||
| 64 | |||
| 65 | open(IN, "${fips_libdir}/${filename}.sha1") || die "Cannot open file hash file ${fips_libdir}/${filename}.sha1"; | ||
| 66 | $hashfile = <IN>; | ||
| 67 | close IN; | ||
| 68 | $hashval = `$sha1_exe ${fips_libdir}/$filename`; | ||
| 69 | chomp $hashfile; | ||
| 70 | chomp $hashval; | ||
| 71 | $hashfile =~ s/^.*=\s+//; | ||
| 72 | $hashval =~ s/^.*=\s+//; | ||
| 73 | die "Invalid hash syntax in file" if (length($hashfile) != 40); | ||
| 74 | die "Invalid hash received for file" if (length($hashval) != 40); | ||
| 75 | die "***HASH VALUE MISMATCH FOR FILE $filename ***" if ($hashval ne $hashfile); | ||
| 76 | } | ||
| 77 | |||
| 78 | |||
diff --git a/src/lib/libcrypto/util/mkrc.pl b/src/lib/libcrypto/util/mkrc.pl new file mode 100755 index 0000000000..0ceadcf8d1 --- /dev/null +++ b/src/lib/libcrypto/util/mkrc.pl | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | #!/bin/env perl | ||
| 2 | # | ||
| 3 | open FD,"crypto/opensslv.h"; | ||
| 4 | while(<FD>) { | ||
| 5 | if (/OPENSSL_VERSION_NUMBER\s+(0x[0-9a-f]+)/i) { | ||
| 6 | $ver = hex($1); | ||
| 7 | $v1 = ($ver>>28); | ||
| 8 | $v2 = ($ver>>20)&0xff; | ||
| 9 | $v3 = ($ver>>12)&0xff; | ||
| 10 | $v4 = ($ver>> 4)&0xff; | ||
| 11 | $beta = $ver&0xf; | ||
| 12 | $version = "$v1.$v2.$v3"; | ||
| 13 | if ($beta==0xf) { $version .= chr(ord('a')+$v4-1) if ($v4); } | ||
| 14 | elsif ($beta==0){ $version .= "-dev"; } | ||
| 15 | else { $version .= "-beta$beta"; } | ||
| 16 | last; | ||
| 17 | } | ||
| 18 | } | ||
| 19 | close(FD); | ||
| 20 | |||
| 21 | $filename = $ARGV[0]; $filename =~ /(.*)\.([^.]+)$/; | ||
| 22 | $basename = $1; | ||
| 23 | $extname = $2; | ||
| 24 | |||
| 25 | if ($extname =~ /dll/i) { $description = "OpenSSL shared library"; } | ||
| 26 | else { $description = "OpenSSL application"; } | ||
| 27 | |||
| 28 | print <<___; | ||
| 29 | #include <winver.h> | ||
| 30 | |||
| 31 | LANGUAGE 0x09,0x01 | ||
| 32 | |||
| 33 | 1 VERSIONINFO | ||
| 34 | FILEVERSION $v1,$v2,$v3,$v4 | ||
| 35 | PRODUCTVERSION $v1,$v2,$v3,$v4 | ||
| 36 | FILEFLAGSMASK 0x3fL | ||
| 37 | #ifdef _DEBUG | ||
| 38 | FILEFLAGS 0x01L | ||
| 39 | #else | ||
| 40 | FILEFLAGS 0x00L | ||
| 41 | #endif | ||
| 42 | FILEOS VOS__WINDOWS32 | ||
| 43 | FILETYPE VFT_DLL | ||
| 44 | FILESUBTYPE 0x0L | ||
| 45 | BEGIN | ||
| 46 | BLOCK "StringFileInfo" | ||
| 47 | BEGIN | ||
| 48 | BLOCK "040904b0" | ||
| 49 | BEGIN | ||
| 50 | // Required: | ||
| 51 | VALUE "CompanyName", "The OpenSSL Project, http://www.openssl.org/\\0" | ||
| 52 | VALUE "FileDescription", "$description\\0" | ||
| 53 | VALUE "FileVersion", "$version\\0" | ||
| 54 | VALUE "InternalName", "$basename\\0" | ||
| 55 | VALUE "OriginalFilename", "$filename\\0" | ||
| 56 | VALUE "ProductName", "The OpenSSL Toolkit\\0" | ||
| 57 | VALUE "ProductVersion", "$version\\0" | ||
| 58 | // Optional: | ||
| 59 | //VALUE "Comments", "\\0" | ||
| 60 | VALUE "LegalCopyright", "Copyright © 1998-2006 The OpenSSL Project. Copyright © 1995-1998 Eric A. Young, Tim J. Hudson. All rights reserved.\\0" | ||
| 61 | //VALUE "LegalTrademarks", "\\0" | ||
| 62 | //VALUE "PrivateBuild", "\\0" | ||
| 63 | //VALUE "SpecialBuild", "\\0" | ||
| 64 | END | ||
| 65 | END | ||
| 66 | BLOCK "VarFileInfo" | ||
| 67 | BEGIN | ||
| 68 | VALUE "Translation", 0x409, 0x4b0 | ||
| 69 | END | ||
| 70 | END | ||
| 71 | ___ | ||
diff --git a/src/lib/libcrypto/util/mksdef.pl b/src/lib/libcrypto/util/mksdef.pl deleted file mode 100644 index 065dc675f1..0000000000 --- a/src/lib/libcrypto/util/mksdef.pl +++ /dev/null | |||
| @@ -1,87 +0,0 @@ | |||
| 1 | |||
| 2 | # Perl script to split libeay32.def into two distinct DEF files for use in | ||
| 3 | # fipdso mode. It works out symbols in each case by running "link" command and | ||
| 4 | # parsing the output to find the list of missing symbols then splitting | ||
| 5 | # libeay32.def based on the result. | ||
| 6 | |||
| 7 | |||
| 8 | # Get list of unknown symbols | ||
| 9 | |||
| 10 | my @deferr = `link @ARGV`; | ||
| 11 | |||
| 12 | my $preamble = ""; | ||
| 13 | my @fipsdll; | ||
| 14 | my @fipsrest; | ||
| 15 | my %nosym; | ||
| 16 | |||
| 17 | # Add symbols to a hash for easy lookup | ||
| 18 | |||
| 19 | foreach (@deferr) | ||
| 20 | { | ||
| 21 | if (/^.*symbol (\S+)$/) | ||
| 22 | { | ||
| 23 | $nosym{$1} = 1; | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | open (IN, "ms/libeay32.def") || die "Can't Open DEF file for spliting"; | ||
| 28 | |||
| 29 | my $started = 0; | ||
| 30 | |||
| 31 | # Parse libeay32.def into two arrays depending on whether the symbol matches | ||
| 32 | # the missing list. | ||
| 33 | |||
| 34 | |||
| 35 | foreach (<IN>) | ||
| 36 | { | ||
| 37 | if (/^\s*(\S+)\s*(\@\S+)\s*$/) | ||
| 38 | { | ||
| 39 | $started = 1; | ||
| 40 | if (exists $nosym{$1}) | ||
| 41 | { | ||
| 42 | push @fipsrest, $_; | ||
| 43 | } | ||
| 44 | else | ||
| 45 | { | ||
| 46 | my $imptmp = sprintf " %-39s %s\n", | ||
| 47 | "$1=libosslfips.$1", $2; | ||
| 48 | push @fipsrest, $imptmp; | ||
| 49 | push @fipsdll, "\t$1\n"; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | $preamble .= $_ unless $started; | ||
| 53 | } | ||
| 54 | |||
| 55 | close IN; | ||
| 56 | |||
| 57 | # Hack! Add some additional exports needed for libcryptofips.dll | ||
| 58 | # | ||
| 59 | |||
| 60 | push @fipsdll, "\tOPENSSL_showfatal\n"; | ||
| 61 | push @fipsdll, "\tOPENSSL_cpuid_setup\n"; | ||
| 62 | |||
| 63 | # Write out DEF files for each array | ||
| 64 | |||
| 65 | write_def("ms/libosslfips.def", "LIBOSSLFIPS", $preamble, \@fipsdll); | ||
| 66 | write_def("ms/libeayfips.def", "", $preamble, \@fipsrest); | ||
| 67 | |||
| 68 | |||
| 69 | sub write_def | ||
| 70 | { | ||
| 71 | my ($fnam, $defname, $preamble, $rdefs) = @_; | ||
| 72 | open (OUT, ">$fnam") || die "Can't Open DEF file $fnam for Writing\n"; | ||
| 73 | |||
| 74 | if ($defname ne "") | ||
| 75 | { | ||
| 76 | $preamble =~ s/LIBEAY32/$defname/g; | ||
| 77 | $preamble =~ s/LIBEAY/$defname/g; | ||
| 78 | } | ||
| 79 | print OUT $preamble; | ||
| 80 | foreach (@$rdefs) | ||
| 81 | { | ||
| 82 | print OUT $_; | ||
| 83 | } | ||
| 84 | close OUT; | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
diff --git a/src/lib/libcrypto/util/pl/BC-16.pl b/src/lib/libcrypto/util/pl/BC-16.pl deleted file mode 100644 index 8030653daa..0000000000 --- a/src/lib/libcrypto/util/pl/BC-16.pl +++ /dev/null | |||
| @@ -1,151 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries | ||
| 3 | # | ||
| 4 | |||
| 5 | $o='\\'; | ||
| 6 | $cp='copy'; | ||
| 7 | $rm='del'; | ||
| 8 | |||
| 9 | # C compiler stuff | ||
| 10 | $cc='bcc'; | ||
| 11 | |||
| 12 | if ($debug) | ||
| 13 | { $op="-v "; } | ||
| 14 | else { $op="-O "; } | ||
| 15 | |||
| 16 | $cflags="-d -ml $op -DL_ENDIAN"; | ||
| 17 | # I add the stack opt | ||
| 18 | $base_lflags="/c /C"; | ||
| 19 | $lflags="$base_lflags"; | ||
| 20 | |||
| 21 | if ($win16) | ||
| 22 | { | ||
| 23 | $shlib=1; | ||
| 24 | $cflags.=" -DOPENSSL_SYSNAME_WIN16"; | ||
| 25 | $app_cflag="-W"; | ||
| 26 | $lib_cflag="-WD"; | ||
| 27 | $lflags.="/Twe"; | ||
| 28 | } | ||
| 29 | else | ||
| 30 | { | ||
| 31 | $cflags.=" -DOENSSL_SYSNAME_MSDOS"; | ||
| 32 | $lflags.=" /Tde"; | ||
| 33 | } | ||
| 34 | |||
| 35 | if ($shlib) | ||
| 36 | { | ||
| 37 | $mlflags=" /Twd $base_lflags"; # stack if defined in .def file | ||
| 38 | $libs="libw ldllcew"; | ||
| 39 | $no_asm=1; | ||
| 40 | } | ||
| 41 | else | ||
| 42 | { $mlflags=''; } | ||
| 43 | |||
| 44 | $obj='.obj'; | ||
| 45 | $ofile="-o"; | ||
| 46 | |||
| 47 | # EXE linking stuff | ||
| 48 | $link="tlink"; | ||
| 49 | $efile=""; | ||
| 50 | $exep='.exe'; | ||
| 51 | $ex_libs="CL"; | ||
| 52 | $ex_libs.=$no_sock?"":" winsock.lib"; | ||
| 53 | |||
| 54 | $app_ex_obj="C0L.obj "; | ||
| 55 | $shlib_ex_obj="" if ($shlib); | ||
| 56 | |||
| 57 | # static library stuff | ||
| 58 | $mklib='tlib'; | ||
| 59 | $ranlib='echo no ranlib'; | ||
| 60 | $plib=""; | ||
| 61 | $libp=".lib"; | ||
| 62 | $shlibp=($shlib)?".dll":".lib"; | ||
| 63 | $lfile=''; | ||
| 64 | |||
| 65 | $asm='bcc -c -B -Tml'; | ||
| 66 | $afile='/o'; | ||
| 67 | if ($no_asm || $fips) | ||
| 68 | { | ||
| 69 | $bn_asm_obj=''; | ||
| 70 | $bn_asm_src=''; | ||
| 71 | } | ||
| 72 | elsif ($asmbits == 32) | ||
| 73 | { | ||
| 74 | $bn_asm_obj='crypto\bn\asm\x86w32.obj'; | ||
| 75 | $bn_asm_src='crypto\bn\asm\x86w32.asm'; | ||
| 76 | } | ||
| 77 | else | ||
| 78 | { | ||
| 79 | $bn_asm_obj='crypto\bn\asm\x86w16.obj'; | ||
| 80 | $bn_asm_src='crypto\bn\asm\x86w16.asm'; | ||
| 81 | } | ||
| 82 | |||
| 83 | sub do_lib_rule | ||
| 84 | { | ||
| 85 | local($target,$name,$shlib)=@_; | ||
| 86 | local($ret,$Name); | ||
| 87 | |||
| 88 | $taget =~ s/\//$o/g if $o ne '/'; | ||
| 89 | ($Name=$name) =~ tr/a-z/A-Z/; | ||
| 90 | |||
| 91 | $ret.="$target: \$(${Name}OBJ)\n"; | ||
| 92 | $ret.="\t\$(RM) \$(O_$Name)\n"; | ||
| 93 | |||
| 94 | # Due to a pathetic line length limit, I unwrap the args. | ||
| 95 | local($lib_names)=""; | ||
| 96 | local($dll_names)=""; | ||
| 97 | foreach $_ (sort split(/\s+/,$Vars{"${Name}OBJ"})) | ||
| 98 | { | ||
| 99 | $lib_names.=" +$_ &\n"; | ||
| 100 | $dll_names.=" $_\n"; | ||
| 101 | } | ||
| 102 | |||
| 103 | if (!$shlib) | ||
| 104 | { | ||
| 105 | $ret.="\t\$(MKLIB) $target & <<|\n$lib_names\n,\n|\n"; | ||
| 106 | } | ||
| 107 | else | ||
| 108 | { | ||
| 109 | local($ex)=($Name eq "SSL")?' $(L_CRYPTO) winsock':""; | ||
| 110 | $ret.="\t\$(LINK) \$(MLFLAGS) @&&|\n"; | ||
| 111 | $ret.=$dll_names; | ||
| 112 | $ret.="\n $target\n\n $ex $libs\nms$o${name}16.def;\n|\n"; | ||
| 113 | ($out_lib=$target) =~ s/O_/L_/; | ||
| 114 | $ret.="\timplib /nowep $out_lib $target\n\n"; | ||
| 115 | } | ||
| 116 | $ret.="\n"; | ||
| 117 | return($ret); | ||
| 118 | } | ||
| 119 | |||
| 120 | sub do_link_rule | ||
| 121 | { | ||
| 122 | local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_; | ||
| 123 | local($ret,$f,$_,@f); | ||
| 124 | |||
| 125 | $file =~ s/\//$o/g if $o ne '/'; | ||
| 126 | $n=&bname($target); | ||
| 127 | $ret.="$target: $files $dep_libs\n"; | ||
| 128 | $ret.=" \$(LINK) @&&|"; | ||
| 129 | |||
| 130 | # Due to a pathetic line length limit, I have to unwrap the args. | ||
| 131 | $ret.=" \$(LFLAGS) "; | ||
| 132 | if ($files =~ /\(([^)]*)\)$/) | ||
| 133 | { | ||
| 134 | $ret.=" \$(APP_EX_OBJ)"; | ||
| 135 | foreach $_ (sort split(/\s+/,$Vars{$1})) | ||
| 136 | { $ret.="\n $r $_ +"; } | ||
| 137 | chop($ret); | ||
| 138 | $ret.="\n"; | ||
| 139 | } | ||
| 140 | else | ||
| 141 | { $ret.="\n $r \$(APP_EX_OBJ) $files\n"; } | ||
| 142 | $ret.=" $target\n\n $libs\n\n|\n"; | ||
| 143 | if (defined $sha1file) | ||
| 144 | { | ||
| 145 | $ret.=" $openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file"; | ||
| 146 | } | ||
| 147 | $ret.="\n"; | ||
| 148 | return($ret); | ||
| 149 | } | ||
| 150 | |||
| 151 | 1; | ||
diff --git a/src/lib/libcrypto/util/pl/VC-16.pl b/src/lib/libcrypto/util/pl/VC-16.pl deleted file mode 100644 index 564ba3fd08..0000000000 --- a/src/lib/libcrypto/util/pl/VC-16.pl +++ /dev/null | |||
| @@ -1,177 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries | ||
| 3 | # | ||
| 4 | |||
| 5 | $ssl= "ssleay16"; | ||
| 6 | $crypto="libeay16"; | ||
| 7 | |||
| 8 | $o='\\'; | ||
| 9 | $cp='copy'; | ||
| 10 | $rm='del'; | ||
| 11 | |||
| 12 | # C compiler stuff | ||
| 13 | $cc='cl'; | ||
| 14 | |||
| 15 | $out_def="out16"; | ||
| 16 | $tmp_def="tmp16"; | ||
| 17 | $inc_def="inc16"; | ||
| 18 | |||
| 19 | if ($debug) | ||
| 20 | { | ||
| 21 | $op="/Od /Zi /Zd"; | ||
| 22 | $base_lflags="/CO"; | ||
| 23 | } | ||
| 24 | else { | ||
| 25 | $op="/G2 /f- /Ocgnotb2"; | ||
| 26 | } | ||
| 27 | $base_lflags.=" /FARCALL /NOLOGO /NOD /SEG:1024 /ONERROR:NOEXE /NOE /PACKC:60000"; | ||
| 28 | if ($win16) { $base_lflags.=" /PACKD:60000"; } | ||
| 29 | |||
| 30 | $cflags="/ALw /Gx- /Gt256 /Gf $op /W3 /WX -DL_ENDIAN /nologo"; | ||
| 31 | # I add the stack opt | ||
| 32 | $lflags="$base_lflags /STACK:20000"; | ||
| 33 | |||
| 34 | if ($win16) | ||
| 35 | { | ||
| 36 | $cflags.=" -DOPENSSL_SYSNAME_WIN16"; | ||
| 37 | $app_cflag="/Gw /FPi87"; | ||
| 38 | $lib_cflag="/Gw"; | ||
| 39 | $lib_cflag.=" -D_WINDLL -D_DLL" if $shlib; | ||
| 40 | $lib_cflag.=" -DWIN16TTY" if !$shlib; | ||
| 41 | $lflags.=" /ALIGN:256"; | ||
| 42 | $ex_libs.="oldnames llibcewq libw"; | ||
| 43 | } | ||
| 44 | else | ||
| 45 | { | ||
| 46 | $no_sock=1; | ||
| 47 | $cflags.=" -DMSDOS"; | ||
| 48 | $lflags.=" /EXEPACK"; | ||
| 49 | $ex_libs.="oldnames.lib llibce.lib"; | ||
| 50 | } | ||
| 51 | |||
| 52 | if ($shlib) | ||
| 53 | { | ||
| 54 | $mlflags="$base_lflags"; | ||
| 55 | $libs="oldnames ldllcew libw"; | ||
| 56 | $shlib_ex_obj=""; | ||
| 57 | # $no_asm=1; | ||
| 58 | $out_def="out16dll"; | ||
| 59 | $tmp_def="tmp16dll"; | ||
| 60 | } | ||
| 61 | else | ||
| 62 | { $mlflags=''; } | ||
| 63 | |||
| 64 | $app_ex_obj=""; | ||
| 65 | |||
| 66 | $obj='.obj'; | ||
| 67 | $ofile="/Fo"; | ||
| 68 | |||
| 69 | # EXE linking stuff | ||
| 70 | $link="link"; | ||
| 71 | $efile=""; | ||
| 72 | $exep='.exe'; | ||
| 73 | $ex_libs.=$no_sock?"":" winsock"; | ||
| 74 | |||
| 75 | # static library stuff | ||
| 76 | $mklib='lib /PAGESIZE:1024'; | ||
| 77 | $ranlib=''; | ||
| 78 | $plib=""; | ||
| 79 | $libp=".lib"; | ||
| 80 | $shlibp=($shlib)?".dll":".lib"; | ||
| 81 | $lfile=''; | ||
| 82 | |||
| 83 | $asm='ml /Cp /c /Cx'; | ||
| 84 | $afile='/Fo'; | ||
| 85 | |||
| 86 | $bn_asm_obj=''; | ||
| 87 | $bn_asm_src=''; | ||
| 88 | $des_enc_obj=''; | ||
| 89 | $des_enc_src=''; | ||
| 90 | $bf_enc_obj=''; | ||
| 91 | $bf_enc_src=''; | ||
| 92 | |||
| 93 | if (!$no_asm && !$fips) | ||
| 94 | { | ||
| 95 | if ($asmbits == 32) | ||
| 96 | { | ||
| 97 | $bn_asm_obj='crypto\bn\asm\x86w32.obj'; | ||
| 98 | $bn_asm_src='crypto\bn\asm\x86w32.asm'; | ||
| 99 | } | ||
| 100 | else | ||
| 101 | { | ||
| 102 | $bn_asm_obj='crypto\bn\asm\x86w16.obj'; | ||
| 103 | $bn_asm_src='crypto\bn\asm\x86w16.asm'; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | sub do_lib_rule | ||
| 108 | { | ||
| 109 | local($objs,$target,$name,$shlib)=@_; | ||
| 110 | local($ret,$Name); | ||
| 111 | |||
| 112 | $taget =~ s/\//$o/g if $o ne '/'; | ||
| 113 | ($Name=$name) =~ tr/a-z/A-Z/; | ||
| 114 | |||
| 115 | # $target="\$(LIB_D)$o$target"; | ||
| 116 | $ret.="$target: $objs\n"; | ||
| 117 | # $ret.="\t\$(RM) \$(O_$Name)\n"; | ||
| 118 | |||
| 119 | # Due to a pathetic line length limit, I unwrap the args. | ||
| 120 | local($lib_names)=""; | ||
| 121 | local($dll_names)=" \$(SHLIB_EX_OBJ) +\n"; | ||
| 122 | ($obj)= ($objs =~ /\((.*)\)/); | ||
| 123 | foreach $_ (sort split(/\s+/,$Vars{$obj})) | ||
| 124 | { | ||
| 125 | $lib_names.="+$_ &\n"; | ||
| 126 | $dll_names.=" $_ +\n"; | ||
| 127 | } | ||
| 128 | |||
| 129 | if (!$shlib) | ||
| 130 | { | ||
| 131 | $ret.="\tdel $target\n"; | ||
| 132 | $ret.="\t\$(MKLIB) @<<\n$target\ny\n$lib_names\n\n<<\n"; | ||
| 133 | } | ||
| 134 | else | ||
| 135 | { | ||
| 136 | local($ex)=($target =~ /O_SSL/)?'$(L_CRYPTO)':""; | ||
| 137 | $ex.=' winsock'; | ||
| 138 | $ret.="\t\$(LINK) \$(MLFLAGS) @<<\n"; | ||
| 139 | $ret.=$dll_names; | ||
| 140 | $ret.="\n $target\n\n $ex $libs\nms$o${name}.def;\n<<\n"; | ||
| 141 | ($out_lib=$target) =~ s/O_/L_/; | ||
| 142 | $ret.="\timplib /noignorecase /nowep $out_lib $target\n"; | ||
| 143 | } | ||
| 144 | $ret.="\n"; | ||
| 145 | return($ret); | ||
| 146 | } | ||
| 147 | |||
| 148 | sub do_link_rule | ||
| 149 | { | ||
| 150 | local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_; | ||
| 151 | local($ret,$f,$_,@f); | ||
| 152 | |||
| 153 | $file =~ s/\//$o/g if $o ne '/'; | ||
| 154 | $n=&bname($targer); | ||
| 155 | $ret.="$target: $files $dep_libs\n"; | ||
| 156 | $ret.=" \$(LINK) \$(LFLAGS) @<<\n"; | ||
| 157 | |||
| 158 | # Due to a pathetic line length limit, I have to unwrap the args. | ||
| 159 | if ($files =~ /\(([^)]*)\)$/) | ||
| 160 | { | ||
| 161 | @a=('$(APP_EX_OBJ)'); | ||
| 162 | push(@a,sort split(/\s+/,$Vars{$1})); | ||
| 163 | for $_ (@a) | ||
| 164 | { $ret.=" $_ +\n"; } | ||
| 165 | } | ||
| 166 | else | ||
| 167 | { $ret.=" \$(APP_EX_OBJ) $files"; } | ||
| 168 | $ret.="\n $target\n\n $libs\n\n<<\n"; | ||
| 169 | if (defined $sha1file) | ||
| 170 | { | ||
| 171 | $ret.=" $openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file"; | ||
| 172 | } | ||
| 173 | $ret.="\n"; | ||
| 174 | return($ret); | ||
| 175 | } | ||
| 176 | |||
| 177 | 1; | ||
diff --git a/src/lib/libcrypto/util/pl/VC-32-GMAKE.pl b/src/lib/libcrypto/util/pl/VC-32-GMAKE.pl deleted file mode 100644 index b5bbcac6c2..0000000000 --- a/src/lib/libcrypto/util/pl/VC-32-GMAKE.pl +++ /dev/null | |||
| @@ -1,222 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # VCw32lib.pl - the file for Visual C++ 4.[01] for windows NT, static libraries | ||
| 3 | # | ||
| 4 | |||
| 5 | |||
| 6 | if ($fips && !$shlib) | ||
| 7 | { | ||
| 8 | $crypto="libeayfips32"; | ||
| 9 | $crypto_compat = "libeaycompat32.lib"; | ||
| 10 | } | ||
| 11 | else | ||
| 12 | { | ||
| 13 | $crypto="libeay32"; | ||
| 14 | } | ||
| 15 | $ssl= "ssleay32"; | ||
| 16 | |||
| 17 | $o='/'; | ||
| 18 | #$cp='copy nul+'; # Timestamps get stuffed otherwise | ||
| 19 | #$rm='del'; | ||
| 20 | |||
| 21 | $cp='cp'; | ||
| 22 | $rm='rm'; | ||
| 23 | |||
| 24 | $zlib_lib="zlib1.lib"; | ||
| 25 | |||
| 26 | # C compiler stuff | ||
| 27 | $cc='cl'; | ||
| 28 | $cflags=' -MD -W3 -WX -Ox -O2 -Ob2 -Gs0 -GF -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32'; | ||
| 29 | $cflags.=' -D_CRT_SECURE_NO_DEPRECATE'; # shut up VC8 | ||
| 30 | $cflags.=' -D_CRT_NONSTDC_NO_DEPRECATE'; # shut up VC8 | ||
| 31 | $lflags="-nologo -subsystem:console -machine:I386 -opt:ref"; | ||
| 32 | $mlflags=''; | ||
| 33 | |||
| 34 | $out_def="gmout32"; | ||
| 35 | $tmp_def="gmtmp32"; | ||
| 36 | $inc_def="gminc32"; | ||
| 37 | |||
| 38 | if ($debug) | ||
| 39 | { | ||
| 40 | $cflags=" -MDd -W3 -WX -Zi -Yd -Od -nologo -DOPENSSL_SYSNAME_WIN32 -D_DEBUG -DL_ENDIAN -DWIN32_LEAN_AND_MEAN -DDEBUG -DDSO_WIN32"; | ||
| 41 | $lflags.=" -debug"; | ||
| 42 | $mlflags.=' -debug'; | ||
| 43 | } | ||
| 44 | $cflags .= " -DOPENSSL_SYSNAME_WINNT" if $NT == 1; | ||
| 45 | |||
| 46 | $obj='.obj'; | ||
| 47 | $ofile="-Fo"; | ||
| 48 | |||
| 49 | # EXE linking stuff | ||
| 50 | $link="link"; | ||
| 51 | $efile="-out:"; | ||
| 52 | $exep='.exe'; | ||
| 53 | if ($no_sock) | ||
| 54 | { $ex_libs=""; } | ||
| 55 | else { $ex_libs="wsock32.lib user32.lib gdi32.lib"; } | ||
| 56 | |||
| 57 | # static library stuff | ||
| 58 | $mklib='lib'; | ||
| 59 | $ranlib=''; | ||
| 60 | $plib=""; | ||
| 61 | $libp=".lib"; | ||
| 62 | $shlibp=($shlib)?".dll":".lib"; | ||
| 63 | $lfile='-out:'; | ||
| 64 | |||
| 65 | $shlib_ex_obj=""; | ||
| 66 | $app_ex_obj="setargv.obj"; | ||
| 67 | if ($nasm) { | ||
| 68 | $asm='nasmw -f win32'; | ||
| 69 | $afile='-o '; | ||
| 70 | } else { | ||
| 71 | $asm='ml -Cp -coff -c -Cx'; | ||
| 72 | $asm.=" -Zi" if $debug; | ||
| 73 | $afile='-Fo'; | ||
| 74 | } | ||
| 75 | |||
| 76 | $bn_asm_obj=''; | ||
| 77 | $bn_asm_src=''; | ||
| 78 | $des_enc_obj=''; | ||
| 79 | $des_enc_src=''; | ||
| 80 | $bf_enc_obj=''; | ||
| 81 | $bf_enc_src=''; | ||
| 82 | |||
| 83 | if (!$no_asm && !$fips) | ||
| 84 | { | ||
| 85 | $bn_asm_obj='crypto/bn/asm/bn_win32.obj'; | ||
| 86 | $bn_asm_src='crypto/bn/asm/bn_win32.asm'; | ||
| 87 | $des_enc_obj='crypto/des/asm/d_win32.obj crypto/des/asm/y_win32.obj'; | ||
| 88 | $des_enc_src='crypto/des/asm/d_win32.asm crypto/des/asm/y_win32.asm'; | ||
| 89 | $bf_enc_obj='crypto/bf/asm/b_win32.obj'; | ||
| 90 | $bf_enc_src='crypto/bf/asm/b_win32.asm'; | ||
| 91 | $cast_enc_obj='crypto/cast/asm/c_win32.obj'; | ||
| 92 | $cast_enc_src='crypto/cast/asm/c_win32.asm'; | ||
| 93 | $rc4_enc_obj='crypto/rc4/asm/r4_win32.obj'; | ||
| 94 | $rc4_enc_src='crypto/rc4/asm/r4_win32.asm'; | ||
| 95 | $rc5_enc_obj='crypto/rc5/asm/r5_win32.obj'; | ||
| 96 | $rc5_enc_src='crypto/rc5/asm/r5_win32.asm'; | ||
| 97 | $md5_asm_obj='crypto/md5/asm/m5_win32.obj'; | ||
| 98 | $md5_asm_src='crypto/md5/asm/m5_win32.asm'; | ||
| 99 | $sha1_asm_obj='crypto/sha/asm/s1_win32.obj'; | ||
| 100 | $sha1_asm_src='crypto/sha/asm/s1_win32.asm'; | ||
| 101 | $rmd160_asm_obj='crypto/ripemd/asm/rm_win32.obj'; | ||
| 102 | $rmd160_asm_src='crypto/ripemd/asm/rm_win32.asm'; | ||
| 103 | $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM"; | ||
| 104 | } | ||
| 105 | |||
| 106 | if ($shlib) | ||
| 107 | { | ||
| 108 | $mlflags.=" $lflags -dll"; | ||
| 109 | # $cflags =~ s| -MD| -MT|; | ||
| 110 | $lib_cflag=" -D_WINDLL"; | ||
| 111 | $out_def="gmout32dll"; | ||
| 112 | $tmp_def="gmtmp32dll"; | ||
| 113 | } | ||
| 114 | |||
| 115 | $cflags.=" -Fd$out_def"; | ||
| 116 | |||
| 117 | sub do_lib_rule | ||
| 118 | { | ||
| 119 | local($objs,$target,$name,$shlib,$ign,$base_addr, $fips_get_sig, $fips_premain_src)=@_; | ||
| 120 | local($ret,$Name); | ||
| 121 | |||
| 122 | $taget =~ s/\//$o/g if $o ne '/'; | ||
| 123 | ($Name=$name) =~ tr/a-z/A-Z/; | ||
| 124 | my $base_arg; | ||
| 125 | if ($base_addr ne "") | ||
| 126 | { | ||
| 127 | $base_arg= " -base:$base_addr"; | ||
| 128 | } | ||
| 129 | else | ||
| 130 | { | ||
| 131 | $base_arg = ""; | ||
| 132 | } | ||
| 133 | |||
| 134 | |||
| 135 | # $target="\$(LIB_D)$o$target"; | ||
| 136 | if (!$shlib) | ||
| 137 | { | ||
| 138 | # $ret.="\t\$(RM) \$(O_$Name)\n"; | ||
| 139 | $ret.="$target: $objs\n"; | ||
| 140 | $ex =' advapi32.lib'; | ||
| 141 | $ret.="\t\$(MKLIB) $lfile$target $objs $ex\n\n"; | ||
| 142 | } | ||
| 143 | else | ||
| 144 | { | ||
| 145 | local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':''; | ||
| 146 | $ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib'; | ||
| 147 | $ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/; | ||
| 148 | if (defined $fips_get_sig) | ||
| 149 | { | ||
| 150 | $ret.="$target: \$(O_FIPSCANISTER) $objs $fips_get_sig\n"; | ||
| 151 | $ret.="\tFIPS_LINK=\$(LINK) "; | ||
| 152 | $ret.="FIPS_CC=\$(CC) "; | ||
| 153 | $ret.="FIPS_CC_ARGS=\"-Fo\$(OBJ_D)${o}fips_premain.obj \$(SHLIB_CFLAGS) -c\" "; | ||
| 154 | $ret.="FIPS_PREMAIN_DSO=$fips_get_sig "; | ||
| 155 | $ret.="FIPS_TARGET=$target "; | ||
| 156 | $ret.="FIPS_LIBDIR=\$(FIPSLIB_D) "; | ||
| 157 | $ret.="\$(FIPSLINK) \$(MLFLAGS) $base_arg $efile$target "; | ||
| 158 | $ret.="-def:ms/${Name}.def \$(SHLIB_EX_OBJ) $objs "; | ||
| 159 | $ret.="\$(OBJ_D)${o}fips_premain.obj $ex\n\n"; | ||
| 160 | } | ||
| 161 | else | ||
| 162 | { | ||
| 163 | $ret.="$target: $objs\n"; | ||
| 164 | $ret.="\t\$(LINK) \$(MLFLAGS) $base_arg $efile$target /def:ms/${Name}.def \$(SHLIB_EX_OBJ) $objs $ex\n\n"; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | $ret.="\n"; | ||
| 168 | return($ret); | ||
| 169 | } | ||
| 170 | |||
| 171 | sub do_link_rule | ||
| 172 | { | ||
| 173 | local($target,$files,$dep_libs,$libs,$standalone)=@_; | ||
| 174 | local($ret,$_); | ||
| 175 | $file =~ s/\//$o/g if $o ne '/'; | ||
| 176 | $n=&bname($targer); | ||
| 177 | if ($standalone) | ||
| 178 | { | ||
| 179 | $ret.="$target: $files $dep_libs\n"; | ||
| 180 | $ret.="\t\$(LINK) \$(LFLAGS) $efile$target "; | ||
| 181 | $ret.="$files $libs\n\n"; | ||
| 182 | } | ||
| 183 | elsif ($fips && !$shlib) | ||
| 184 | { | ||
| 185 | $ret.="$target: \$(O_FIPSCANISTER) $files $dep_libs\n"; | ||
| 186 | $ret.="\tFIPS_LINK=\$(LINK) "; | ||
| 187 | $ret.="FIPS_CC=\$(CC) "; | ||
| 188 | $ret.="FIPS_CC_ARGS=\"-Fo\$(OBJ_D)${o}fips_premain.obj \$(SHLIB_CFLAGS) -c\" "; | ||
| 189 | $ret.="FIPS_PREMAIN_DSO= "; | ||
| 190 | $ret.="FIPS_TARGET=$target "; | ||
| 191 | $ret.="FIPS_LIBDIR=\$(FIPSLIB_D) "; | ||
| 192 | $ret.=" \$(FIPSLINK) \$(LFLAGS) $efile$target "; | ||
| 193 | $ret.="\$(APP_EX_OBJ) $files \$(OBJ_D)${o}fips_premain.obj $libs\n\n"; | ||
| 194 | } | ||
| 195 | else | ||
| 196 | { | ||
| 197 | $ret.="$target: $files $dep_libs\n"; | ||
| 198 | $ret.="\t\$(LINK) \$(LFLAGS) $efile$target "; | ||
| 199 | $ret.="\$(APP_EX_OBJ) $files $libs\n\n"; | ||
| 200 | } | ||
| 201 | $ret.="\n"; | ||
| 202 | return($ret); | ||
| 203 | } | ||
| 204 | |||
| 205 | sub do_rlink_rule | ||
| 206 | { | ||
| 207 | local($target,$files,$check_hash, $deps)=@_; | ||
| 208 | local($ret,$_); | ||
| 209 | |||
| 210 | $file =~ s/\//$o/g if $o ne '/'; | ||
| 211 | $n=&bname($targer); | ||
| 212 | $ret.="$target: $check_hash $files $deps\n"; | ||
| 213 | $ret.="\t\$(PERL) util${o}checkhash.pl -chdir fips-1.0 -program_path ..$o$check_hash\n"; | ||
| 214 | $ret.="\t\$(MKCANISTER) $target $files\n"; | ||
| 215 | $ret.="\t$check_hash $target > $target.sha1\n"; | ||
| 216 | $ret.="\t\$(CP) fips-1.0${o}fips_premain.c \$(FIPSLIB_D)\n"; | ||
| 217 | $ret.="\t$check_hash \$(FIPSLIB_D)${o}fips_premain.c > \$(FIPSLIB_D)${o}fips_premain.c.sha1\n\n"; | ||
| 218 | return($ret); | ||
| 219 | } | ||
| 220 | |||
| 221 | |||
| 222 | 1; | ||
diff --git a/src/lib/libcrypto/util/pl/VC-CE.pl b/src/lib/libcrypto/util/pl/VC-CE.pl deleted file mode 100644 index 2fd0c4dd32..0000000000 --- a/src/lib/libcrypto/util/pl/VC-CE.pl +++ /dev/null | |||
| @@ -1,116 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # VC-CE.pl - the file for eMbedded Visual C++ 3.0 for windows CE, static libraries | ||
| 3 | # | ||
| 4 | |||
| 5 | $ssl= "ssleay32"; | ||
| 6 | $crypto="libeay32"; | ||
| 7 | $RSAref="RSAref32"; | ||
| 8 | |||
| 9 | $o='\\'; | ||
| 10 | $cp='copy nul+'; # Timestamps get stuffed otherwise | ||
| 11 | $rm='del'; | ||
| 12 | |||
| 13 | # C compiler stuff | ||
| 14 | $cc='$(CC)'; | ||
| 15 | $cflags=' /W3 /WX /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo $(WCETARGETDEFS) -DUNICODE -D_UNICODE -DWIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DNO_CHMOD -I$(WCECOMPAT)/include'; | ||
| 16 | $lflags='/nologo /subsystem:windowsce,$(WCELDVERSION) /machine:$(WCELDMACHINE) /opt:ref'; | ||
| 17 | $mlflags=''; | ||
| 18 | |||
| 19 | $out_def='out32_$(TARGETCPU)'; | ||
| 20 | $tmp_def='tmp32_$(TARGETCPU)'; | ||
| 21 | $inc_def="inc32"; | ||
| 22 | |||
| 23 | if ($debug) | ||
| 24 | { | ||
| 25 | $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DWIN32 -D_DEBUG -DL_ENDIAN -DWIN32_LEAN_AND_MEAN -DDEBUG -DDSO_WIN32"; | ||
| 26 | $lflags.=" /debug"; | ||
| 27 | $mlflags.=' /debug'; | ||
| 28 | } | ||
| 29 | |||
| 30 | $obj='.obj'; | ||
| 31 | $ofile="/Fo"; | ||
| 32 | |||
| 33 | # EXE linking stuff | ||
| 34 | $link="link"; | ||
| 35 | $efile="/out:"; | ||
| 36 | $exep='.exe'; | ||
| 37 | if ($no_sock) | ||
| 38 | { $ex_libs=""; } | ||
| 39 | else { $ex_libs='winsock.lib $(WCECOMPAT)/lib/wcecompatex.lib $(WCELDFLAGS)'; } | ||
| 40 | |||
| 41 | # static library stuff | ||
| 42 | $mklib='lib'; | ||
| 43 | $ranlib=''; | ||
| 44 | $plib=""; | ||
| 45 | $libp=".lib"; | ||
| 46 | $shlibp=($shlib)?".dll":".lib"; | ||
| 47 | $lfile='/out:'; | ||
| 48 | |||
| 49 | $shlib_ex_obj=""; | ||
| 50 | $app_ex_obj=""; | ||
| 51 | $app_ex_obj=""; | ||
| 52 | |||
| 53 | $bn_asm_obj=''; | ||
| 54 | $bn_asm_src=''; | ||
| 55 | $des_enc_obj=''; | ||
| 56 | $des_enc_src=''; | ||
| 57 | $bf_enc_obj=''; | ||
| 58 | $bf_enc_src=''; | ||
| 59 | |||
| 60 | if ($shlib) | ||
| 61 | { | ||
| 62 | $mlflags.=" $lflags /dll"; | ||
| 63 | # $cflags =~ s| /MD| /MT|; | ||
| 64 | $lib_cflag=" -D_WINDLL -D_DLL"; | ||
| 65 | $out_def='out32dll_$(TARGETCPU)'; | ||
| 66 | $tmp_def='tmp32dll_$(TARGETCPU)'; | ||
| 67 | } | ||
| 68 | |||
| 69 | $cflags.=" /Fd$out_def"; | ||
| 70 | |||
| 71 | sub do_lib_rule | ||
| 72 | { | ||
| 73 | local($objs,$target,$name,$shlib)=@_; | ||
| 74 | local($ret,$Name); | ||
| 75 | |||
| 76 | $taget =~ s/\//$o/g if $o ne '/'; | ||
| 77 | ($Name=$name) =~ tr/a-z/A-Z/; | ||
| 78 | |||
| 79 | # $target="\$(LIB_D)$o$target"; | ||
| 80 | $ret.="$target: $objs\n"; | ||
| 81 | if (!$shlib) | ||
| 82 | { | ||
| 83 | # $ret.="\t\$(RM) \$(O_$Name)\n"; | ||
| 84 | $ex =' '; | ||
| 85 | $ret.="\t\$(MKLIB) $lfile$target @<<\n $objs $ex\n<<\n"; | ||
| 86 | } | ||
| 87 | else | ||
| 88 | { | ||
| 89 | local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':''; | ||
| 90 | # $ex.=' winsock.lib coredll.lib $(WCECOMPAT)/lib/wcecompatex.lib'; | ||
| 91 | $ex.=' winsock.lib $(WCECOMPAT)/lib/wcecompatex.lib'; | ||
| 92 | $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n"; | ||
| 93 | } | ||
| 94 | $ret.="\n"; | ||
| 95 | return($ret); | ||
| 96 | } | ||
| 97 | |||
| 98 | sub do_link_rule | ||
| 99 | { | ||
| 100 | local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_; | ||
| 101 | local($ret,$_); | ||
| 102 | |||
| 103 | $file =~ s/\//$o/g if $o ne '/'; | ||
| 104 | $n=&bname($targer); | ||
| 105 | $ret.="$target: $files $dep_libs\n"; | ||
| 106 | $ret.=" \$(LINK) \$(LFLAGS) $efile$target @<<\n"; | ||
| 107 | $ret.=" \$(APP_EX_OBJ) $files $libs\n<<\n"; | ||
| 108 | if (defined $sha1file) | ||
| 109 | { | ||
| 110 | $ret.=" $openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file"; | ||
| 111 | } | ||
| 112 | $ret.="\n"; | ||
| 113 | return($ret); | ||
| 114 | } | ||
| 115 | |||
| 116 | 1; | ||
diff --git a/src/lib/libcrypto/util/pl/netware.pl b/src/lib/libcrypto/util/pl/netware.pl new file mode 100644 index 0000000000..c78bcfc874 --- /dev/null +++ b/src/lib/libcrypto/util/pl/netware.pl | |||
| @@ -0,0 +1,532 @@ | |||
| 1 | # Metrowerks Codewarrior or gcc / nlmconv for NetWare | ||
| 2 | # | ||
| 3 | |||
| 4 | $version_header = "crypto/opensslv.h"; | ||
| 5 | open(IN, "$version_header") or die "Couldn't open $version_header: $!"; | ||
| 6 | while (<IN>) { | ||
| 7 | if (/^#define[\s\t]+OPENSSL_VERSION_NUMBER[\s\t]+0x(\d)(\d{2})(\d{2})(\d{2})/) | ||
| 8 | { | ||
| 9 | # die "OpenSSL version detected: $1.$2.$3.$4\n"; | ||
| 10 | #$nlmvernum = "$1,$2,$3"; | ||
| 11 | $nlmvernum = "$1,".($2*10+$3).",".($4*1); | ||
| 12 | #$nlmverstr = "$1.".($2*1).".".($3*1).($4?(chr(96+$4)):""); | ||
| 13 | break; | ||
| 14 | } | ||
| 15 | } | ||
| 16 | close(IN) or die "Couldn't close $version_header: $!"; | ||
| 17 | |||
| 18 | $readme_file = "README"; | ||
| 19 | open(IN, $readme_file) or die "Couldn't open $readme_file: $!"; | ||
| 20 | while (<IN>) { | ||
| 21 | if (/^[\s\t]+OpenSSL[\s\t]+(\d)\.(\d{1,2})\.(\d{1,2})([a-z])(.*)/) | ||
| 22 | { | ||
| 23 | #$nlmvernum = "$1,$2,$3"; | ||
| 24 | #$nlmvernum = "$1,".($2*10+$3).",".($4*1); | ||
| 25 | $nlmverstr = "$1.$2.$3$4$5"; | ||
| 26 | } | ||
| 27 | elsif (/^[\s\t]+(Copyright \(c\) \d{4}\-\d{4} The OpenSSL Project)$/) | ||
| 28 | { | ||
| 29 | $nlmcpystr = $1; | ||
| 30 | } | ||
| 31 | break if ($nlmvernum && $nlmcpystr); | ||
| 32 | } | ||
| 33 | close(IN) or die "Couldn't close $readme_file: $!"; | ||
| 34 | |||
| 35 | # Define stacksize here | ||
| 36 | $nlmstack = "32768"; | ||
| 37 | |||
| 38 | # some default settings here in case we failed to find them in README | ||
| 39 | $nlmvernum = "1,0,0" if (!$nlmvernum); | ||
| 40 | $nlmverstr = "OpenSSL" if (!$nlmverstr); | ||
| 41 | $nlmcpystr = "Copyright (c) 1998-now The OpenSSL Project" if (!$nlmcpystr); | ||
| 42 | |||
| 43 | # die "OpenSSL copyright: $nlmcpystr\nOpenSSL verstring: $nlmverstr\nOpenSSL vernumber: $nlmvernum\n"; | ||
| 44 | |||
| 45 | # The import files and other misc imports needed to link | ||
| 46 | @misc_imports = ("GetProcessSwitchCount", "RunningProcess", | ||
| 47 | "GetSuperHighResolutionTimer"); | ||
| 48 | if ($LIBC) | ||
| 49 | { | ||
| 50 | @import_files = ("libc.imp"); | ||
| 51 | @module_files = ("libc"); | ||
| 52 | $libarch = "LIBC"; | ||
| 53 | } | ||
| 54 | else | ||
| 55 | { | ||
| 56 | # clib build | ||
| 57 | @import_files = ("clib.imp"); | ||
| 58 | push(@import_files, "socklib.imp") if ($BSDSOCK); | ||
| 59 | @module_files = ("clib"); | ||
| 60 | # push(@misc_imports, "_rt_modu64%16", "_rt_divu64%16"); | ||
| 61 | $libarch = "CLIB"; | ||
| 62 | } | ||
| 63 | if ($BSDSOCK) | ||
| 64 | { | ||
| 65 | $libarch .= "-BSD"; | ||
| 66 | } | ||
| 67 | else | ||
| 68 | { | ||
| 69 | $libarch .= "-WS2"; | ||
| 70 | push(@import_files, "ws2nlm.imp"); | ||
| 71 | } | ||
| 72 | |||
| 73 | # The "IMPORTS" environment variable must be set and point to the location | ||
| 74 | # where import files (*.imp) can be found. | ||
| 75 | # Example: set IMPORTS=c:\ndk\nwsdk\imports | ||
| 76 | $import_path = $ENV{"IMPORTS"} || die ("IMPORTS environment variable not set\n"); | ||
| 77 | |||
| 78 | |||
| 79 | # The "PRELUDE" environment variable must be set and point to the location | ||
| 80 | # and name of the prelude source to link with ( nwpre.obj is recommended ). | ||
| 81 | # Example: set PRELUDE=c:\codewar\novell support\metrowerks support\libraries\runtime\nwpre.obj | ||
| 82 | $prelude = $ENV{"PRELUDE"} || die ("PRELUDE environment variable not set\n"); | ||
| 83 | |||
| 84 | # The "INCLUDES" environment variable must be set and point to the location | ||
| 85 | # where import files (*.imp) can be found. | ||
| 86 | $include_path = $ENV{"INCLUDE"} || die ("INCLUDES environment variable not set\n"); | ||
| 87 | $include_path =~ s/\\/\//g; | ||
| 88 | $include_path = join(" -I", split(/;/, $include_path)); | ||
| 89 | |||
| 90 | # check for gcc compiler | ||
| 91 | $gnuc = $ENV{"GNUC"}; | ||
| 92 | |||
| 93 | #$ssl= "ssleay32"; | ||
| 94 | #$crypto="libeay32"; | ||
| 95 | |||
| 96 | if ($gnuc) | ||
| 97 | { | ||
| 98 | # C compiler | ||
| 99 | $cc='gcc'; | ||
| 100 | # Linker | ||
| 101 | $link='nlmconv'; | ||
| 102 | # librarian | ||
| 103 | $mklib='ar'; | ||
| 104 | $o='/'; | ||
| 105 | # cp command | ||
| 106 | $cp='cp -af'; | ||
| 107 | # rm command | ||
| 108 | $rm='rm -f'; | ||
| 109 | # mv command | ||
| 110 | $mv='mv -f'; | ||
| 111 | # mkdir command | ||
| 112 | $mkdir='gmkdir'; | ||
| 113 | #$ranlib='ranlib'; | ||
| 114 | } | ||
| 115 | else | ||
| 116 | { | ||
| 117 | # C compiler | ||
| 118 | $cc='mwccnlm'; | ||
| 119 | # Linker | ||
| 120 | $link='mwldnlm'; | ||
| 121 | # librarian | ||
| 122 | $mklib='mwldnlm'; | ||
| 123 | # Path separator | ||
| 124 | $o='\\'; | ||
| 125 | # cp command | ||
| 126 | $cp='copy >nul:'; | ||
| 127 | # rm command | ||
| 128 | $rm='del /f /q'; | ||
| 129 | } | ||
| 130 | |||
| 131 | # assembler | ||
| 132 | if ($nw_nasm) | ||
| 133 | { | ||
| 134 | $asm=(`nasm -v 2>NUL` gt `nasmw -v 2>NUL`?"nasm":"nasmw"); | ||
| 135 | if ($gnuc) | ||
| 136 | { | ||
| 137 | $asm.=" -s -f elf"; | ||
| 138 | } | ||
| 139 | else | ||
| 140 | { | ||
| 141 | $asm.=" -s -f coff -d __coff__"; | ||
| 142 | } | ||
| 143 | $afile="-o "; | ||
| 144 | $asm.=" -g" if $debug; | ||
| 145 | } | ||
| 146 | elsif ($nw_mwasm) | ||
| 147 | { | ||
| 148 | $asm="mwasmnlm -maxerrors 20"; | ||
| 149 | $afile="-o "; | ||
| 150 | $asm.=" -g" if $debug; | ||
| 151 | } | ||
| 152 | elsif ($nw_masm) | ||
| 153 | { | ||
| 154 | # masm assembly settings - it should be possible to use masm but haven't | ||
| 155 | # got it working. | ||
| 156 | # $asm='ml /Cp /coff /c /Cx'; | ||
| 157 | # $asm.=" /Zi" if $debug; | ||
| 158 | # $afile='/Fo'; | ||
| 159 | die("Support for masm assembler not yet functional\n"); | ||
| 160 | } | ||
| 161 | else | ||
| 162 | { | ||
| 163 | $asm=""; | ||
| 164 | $afile=""; | ||
| 165 | } | ||
| 166 | |||
| 167 | |||
| 168 | |||
| 169 | if ($gnuc) | ||
| 170 | { | ||
| 171 | # compile flags for GNUC | ||
| 172 | # additional flags based upon debug | non-debug | ||
| 173 | if ($debug) | ||
| 174 | { | ||
| 175 | $cflags="-g -DDEBUG"; | ||
| 176 | } | ||
| 177 | else | ||
| 178 | { | ||
| 179 | $cflags="-O2"; | ||
| 180 | } | ||
| 181 | $cflags.=" -nostdinc -I$include_path \\ | ||
| 182 | -fno-builtin -fpcc-struct-return -fno-strict-aliasing \\ | ||
| 183 | -funsigned-char -Wall -Wno-unused -Wno-uninitialized"; | ||
| 184 | |||
| 185 | # link flags | ||
| 186 | $lflags="-T"; | ||
| 187 | } | ||
| 188 | else | ||
| 189 | { | ||
| 190 | # compile flags for CodeWarrior | ||
| 191 | # additional flags based upon debug | non-debug | ||
| 192 | if ($debug) | ||
| 193 | { | ||
| 194 | $cflags="-opt off -g -sym internal -DDEBUG"; | ||
| 195 | } | ||
| 196 | else | ||
| 197 | { | ||
| 198 | # CodeWarrior compiler has a problem with optimizations for floating | ||
| 199 | # points - no optimizations until further investigation | ||
| 200 | # $cflags="-opt all"; | ||
| 201 | } | ||
| 202 | |||
| 203 | # NOTES: Several c files in the crypto subdirectory include headers from | ||
| 204 | # their local directories. Metrowerks wouldn't find these h files | ||
| 205 | # without adding individual include directives as compile flags | ||
| 206 | # or modifying the c files. Instead of adding individual include | ||
| 207 | # paths for each subdirectory a recursive include directive | ||
| 208 | # is used ( -ir crypto ). | ||
| 209 | # | ||
| 210 | # A similar issue exists for the engines and apps subdirectories. | ||
| 211 | # | ||
| 212 | # Turned off the "possible" warnings ( -w nopossible ). Metrowerks | ||
| 213 | # complained a lot about various stuff. May want to turn back | ||
| 214 | # on for further development. | ||
| 215 | $cflags.=" -nostdinc -ir crypto -ir engines -ir apps -I$include_path \\ | ||
| 216 | -msgstyle gcc -align 4 -processor pentium -char unsigned \\ | ||
| 217 | -w on -w nolargeargs -w nopossible -w nounusedarg -w nounusedexpr \\ | ||
| 218 | -w noimplicitconv -relax_pointers -nosyspath -maxerrors 20"; | ||
| 219 | |||
| 220 | # link flags | ||
| 221 | $lflags="-msgstyle gcc -zerobss -nostdlib -sym internal -commandfile"; | ||
| 222 | } | ||
| 223 | |||
| 224 | # common defines | ||
| 225 | $cflags.=" -DL_ENDIAN -DOPENSSL_SYSNAME_NETWARE -U_WIN32"; | ||
| 226 | |||
| 227 | # If LibC build add in NKS_LIBC define and set the entry/exit | ||
| 228 | # routines - The default entry/exit routines are for CLib and don't exist | ||
| 229 | # in LibC | ||
| 230 | if ($LIBC) | ||
| 231 | { | ||
| 232 | $cflags.=" -DNETWARE_LIBC"; | ||
| 233 | $nlmstart = "_LibCPrelude"; | ||
| 234 | $nlmexit = "_LibCPostlude"; | ||
| 235 | @nlm_flags = ("pseudopreemption", "flag_on 64"); | ||
| 236 | } | ||
| 237 | else | ||
| 238 | { | ||
| 239 | $cflags.=" -DNETWARE_CLIB"; | ||
| 240 | $nlmstart = "_Prelude"; | ||
| 241 | $nlmexit = "_Stop"; | ||
| 242 | } | ||
| 243 | |||
| 244 | # If BSD Socket support is requested, set a define for the compiler | ||
| 245 | if ($BSDSOCK) | ||
| 246 | { | ||
| 247 | $cflags.=" -DNETWARE_BSDSOCK"; | ||
| 248 | if (!$LIBC) | ||
| 249 | { | ||
| 250 | $cflags.=" -DNETDB_USE_INTERNET"; | ||
| 251 | } | ||
| 252 | } | ||
| 253 | |||
| 254 | |||
| 255 | # linking stuff | ||
| 256 | # for the output directories use the mk1mf.pl values with "_nw" appended | ||
| 257 | if ($shlib) | ||
| 258 | { | ||
| 259 | if ($LIBC) | ||
| 260 | { | ||
| 261 | $out_def.="_nw_libc_nlm"; | ||
| 262 | $tmp_def.="_nw_libc_nlm"; | ||
| 263 | $inc_def.="_nw_libc_nlm"; | ||
| 264 | } | ||
| 265 | else # NETWARE_CLIB | ||
| 266 | { | ||
| 267 | $out_def.="_nw_clib_nlm"; | ||
| 268 | $tmp_def.="_nw_clib_nlm"; | ||
| 269 | $inc_def.="_nw_clib_nlm"; | ||
| 270 | } | ||
| 271 | } | ||
| 272 | else | ||
| 273 | { | ||
| 274 | if ($gnuc) # GNUC Tools | ||
| 275 | { | ||
| 276 | $libp=".a"; | ||
| 277 | $shlibp=".a"; | ||
| 278 | $lib_flags="-cr"; | ||
| 279 | } | ||
| 280 | else # CodeWarrior | ||
| 281 | { | ||
| 282 | $libp=".lib"; | ||
| 283 | $shlibp=".lib"; | ||
| 284 | $lib_flags="-nodefaults -type library -o"; | ||
| 285 | } | ||
| 286 | if ($LIBC) | ||
| 287 | { | ||
| 288 | $out_def.="_nw_libc"; | ||
| 289 | $tmp_def.="_nw_libc"; | ||
| 290 | $inc_def.="_nw_libc"; | ||
| 291 | } | ||
| 292 | else # NETWARE_CLIB | ||
| 293 | { | ||
| 294 | $out_def.="_nw_clib"; | ||
| 295 | $tmp_def.="_nw_clib"; | ||
| 296 | $inc_def.="_nw_clib"; | ||
| 297 | } | ||
| 298 | } | ||
| 299 | |||
| 300 | # used by mk1mf.pl | ||
| 301 | $obj='.o'; | ||
| 302 | $ofile='-o '; | ||
| 303 | $efile=''; | ||
| 304 | $exep='.nlm'; | ||
| 305 | $ex_libs=''; | ||
| 306 | |||
| 307 | if (!$no_asm) | ||
| 308 | { | ||
| 309 | $bn_asm_obj="\$(OBJ_D)${o}bn-nw${obj}"; | ||
| 310 | $bn_asm_src="crypto${o}bn${o}asm${o}bn-nw.asm"; | ||
| 311 | $bnco_asm_obj="\$(OBJ_D)${o}co-nw${obj}"; | ||
| 312 | $bnco_asm_src="crypto${o}bn${o}asm${o}co-nw.asm"; | ||
| 313 | $aes_asm_obj="\$(OBJ_D)${o}a-nw${obj}"; | ||
| 314 | $aes_asm_src="crypto${o}aes${o}asm${o}a-nw.asm"; | ||
| 315 | $des_enc_obj="\$(OBJ_D)${o}d-nw${obj} \$(OBJ_D)${o}y-nw${obj}"; | ||
| 316 | $des_enc_src="crypto${o}des${o}asm${o}d-nw.asm crypto${o}des${o}asm${o}y-nw.asm"; | ||
| 317 | $bf_enc_obj="\$(OBJ_D)${o}b-nw${obj}"; | ||
| 318 | $bf_enc_src="crypto${o}bf${o}asm${o}b-nw.asm"; | ||
| 319 | $cast_enc_obj="\$(OBJ_D)${o}c-nw${obj}"; | ||
| 320 | $cast_enc_src="crypto${o}cast${o}asm${o}c-nw.asm"; | ||
| 321 | $rc4_enc_obj="\$(OBJ_D)${o}r4-nw${obj}"; | ||
| 322 | $rc4_enc_src="crypto${o}rc4${o}asm${o}r4-nw.asm"; | ||
| 323 | $rc5_enc_obj="\$(OBJ_D)${o}r5-nw${obj}"; | ||
| 324 | $rc5_enc_src="crypto${o}rc5${o}asm${o}r5-nw.asm"; | ||
| 325 | $md5_asm_obj="\$(OBJ_D)${o}m5-nw${obj}"; | ||
| 326 | $md5_asm_src="crypto${o}md5${o}asm${o}m5-nw.asm"; | ||
| 327 | $sha1_asm_obj="\$(OBJ_D)${o}s1-nw${obj} \$(OBJ_D)${o}sha256-nw${obj} \$(OBJ_D)${o}sha512-nw${obj}"; | ||
| 328 | $sha1_asm_src="crypto${o}sha${o}asm${o}s1-nw.asm crypto${o}sha${o}asm${o}sha256-nw.asm crypto${o}sha${o}asm${o}sha512-nw.asm"; | ||
| 329 | $rmd160_asm_obj="\$(OBJ_D)${o}rm-nw${obj}"; | ||
| 330 | $rmd160_asm_src="crypto${o}ripemd${o}asm${o}rm-nw.asm"; | ||
| 331 | $whirlpool_asm_obj="\$(OBJ_D)${o}wp-nw${obj}"; | ||
| 332 | $whirlpool_asm_src="crypto${o}whrlpool${o}asm${o}wp-nw.asm"; | ||
| 333 | $cpuid_asm_obj="\$(OBJ_D)${o}x86cpuid-nw${obj}"; | ||
| 334 | $cpuid_asm_src="crypto${o}x86cpuid-nw.asm"; | ||
| 335 | $cflags.=" -DOPENSSL_CPUID_OBJ -DBN_ASM -DOPENSSL_BN_ASM_PART_WORDS -DMD5_ASM -DWHIRLPOOL_ASM"; | ||
| 336 | $cflags.=" -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM"; | ||
| 337 | $cflags.=" -DAES_ASM -DRMD160_ASM"; | ||
| 338 | } | ||
| 339 | else | ||
| 340 | { | ||
| 341 | $bn_asm_obj=''; | ||
| 342 | $bn_asm_src=''; | ||
| 343 | $bnco_asm_obj=''; | ||
| 344 | $bnco_asm_src=''; | ||
| 345 | $aes_asm_obj=''; | ||
| 346 | $aes_asm_src=''; | ||
| 347 | $des_enc_obj=''; | ||
| 348 | $des_enc_src=''; | ||
| 349 | $bf_enc_obj=''; | ||
| 350 | $bf_enc_src=''; | ||
| 351 | $cast_enc_obj=''; | ||
| 352 | $cast_enc_src=''; | ||
| 353 | $rc4_enc_obj=''; | ||
| 354 | $rc4_enc_src=''; | ||
| 355 | $rc5_enc_obj=''; | ||
| 356 | $rc5_enc_src=''; | ||
| 357 | $md5_asm_obj=''; | ||
| 358 | $md5_asm_src=''; | ||
| 359 | $sha1_asm_obj=''; | ||
| 360 | $sha1_asm_src=''; | ||
| 361 | $rmd160_asm_obj=''; | ||
| 362 | $rmd160_asm_src=''; | ||
| 363 | $whirlpool_asm_obj=''; | ||
| 364 | $whirlpool_asm_src=''; | ||
| 365 | $cpuid_asm_obj=''; | ||
| 366 | $cpuid_asm_src=''; | ||
| 367 | } | ||
| 368 | |||
| 369 | # create the *.def linker command files in \openssl\netware\ directory | ||
| 370 | sub do_def_file | ||
| 371 | { | ||
| 372 | # strip off the leading path | ||
| 373 | my($target) = bname(shift); | ||
| 374 | my($i); | ||
| 375 | |||
| 376 | if ($target =~ /(.*).nlm/) | ||
| 377 | { | ||
| 378 | $target = $1; | ||
| 379 | } | ||
| 380 | |||
| 381 | # special case for openssl - the mk1mf.pl defines E_EXE = openssl | ||
| 382 | if ($target =~ /E_EXE/) | ||
| 383 | { | ||
| 384 | $target =~ s/\$\(E_EXE\)/openssl/; | ||
| 385 | } | ||
| 386 | |||
| 387 | # Note: originally tried to use full path ( \openssl\netware\$target.def ) | ||
| 388 | # Metrowerks linker choked on this with an assertion failure. bug??? | ||
| 389 | # | ||
| 390 | my($def_file) = "netware${o}$target.def"; | ||
| 391 | |||
| 392 | open(DEF_OUT, ">$def_file") || die("unable to open file $def_file\n"); | ||
| 393 | |||
| 394 | print( DEF_OUT "# command file generated by netware.pl for NLM target.\n" ); | ||
| 395 | print( DEF_OUT "# do not edit this file - all your changes will be lost!!\n" ); | ||
| 396 | print( DEF_OUT "#\n"); | ||
| 397 | print( DEF_OUT "DESCRIPTION \"$target ($libarch) - OpenSSL $nlmverstr\"\n"); | ||
| 398 | print( DEF_OUT "COPYRIGHT \"$nlmcpystr\"\n"); | ||
| 399 | print( DEF_OUT "VERSION $nlmvernum\n"); | ||
| 400 | print( DEF_OUT "STACK $nlmstack\n"); | ||
| 401 | print( DEF_OUT "START $nlmstart\n"); | ||
| 402 | print( DEF_OUT "EXIT $nlmexit\n"); | ||
| 403 | |||
| 404 | # special case for openssl | ||
| 405 | if ($target eq "openssl") | ||
| 406 | { | ||
| 407 | print( DEF_OUT "SCREENNAME \"OpenSSL $nlmverstr\"\n"); | ||
| 408 | } | ||
| 409 | else | ||
| 410 | { | ||
| 411 | print( DEF_OUT "SCREENNAME \"DEFAULT\"\n"); | ||
| 412 | } | ||
| 413 | |||
| 414 | foreach $i (@misc_imports) | ||
| 415 | { | ||
| 416 | print( DEF_OUT "IMPORT $i\n"); | ||
| 417 | } | ||
| 418 | |||
| 419 | foreach $i (@import_files) | ||
| 420 | { | ||
| 421 | print( DEF_OUT "IMPORT \@$import_path${o}$i\n"); | ||
| 422 | } | ||
| 423 | |||
| 424 | foreach $i (@module_files) | ||
| 425 | { | ||
| 426 | print( DEF_OUT "MODULE $i\n"); | ||
| 427 | } | ||
| 428 | |||
| 429 | foreach $i (@nlm_flags) | ||
| 430 | { | ||
| 431 | print( DEF_OUT "$i\n"); | ||
| 432 | } | ||
| 433 | |||
| 434 | if ($gnuc) | ||
| 435 | { | ||
| 436 | if ($target =~ /openssl/) | ||
| 437 | { | ||
| 438 | print( DEF_OUT "INPUT ${tmp_def}${o}openssl${obj}\n"); | ||
| 439 | print( DEF_OUT "INPUT ${tmp_def}${o}openssl${libp}\n"); | ||
| 440 | } | ||
| 441 | else | ||
| 442 | { | ||
| 443 | print( DEF_OUT "INPUT ${tmp_def}${o}${target}${obj}\n"); | ||
| 444 | } | ||
| 445 | print( DEF_OUT "INPUT $prelude\n"); | ||
| 446 | print( DEF_OUT "INPUT ${out_def}${o}${ssl}${libp} ${out_def}${o}${crypto}${libp}\n"); | ||
| 447 | print( DEF_OUT "OUTPUT $target.nlm\n"); | ||
| 448 | } | ||
| 449 | |||
| 450 | close(DEF_OUT); | ||
| 451 | return($def_file); | ||
| 452 | } | ||
| 453 | |||
| 454 | sub do_lib_rule | ||
| 455 | { | ||
| 456 | my($objs,$target,$name,$shlib)=@_; | ||
| 457 | my($ret); | ||
| 458 | |||
| 459 | $ret.="$target: $objs\n"; | ||
| 460 | if (!$shlib) | ||
| 461 | { | ||
| 462 | $ret.="\t\@echo Building Lib: $name\n"; | ||
| 463 | $ret.="\t\$(MKLIB) $lib_flags $target $objs\n"; | ||
| 464 | $ret.="\t\@echo .\n" | ||
| 465 | } | ||
| 466 | else | ||
| 467 | { | ||
| 468 | die( "Building as NLM not currently supported!" ); | ||
| 469 | } | ||
| 470 | |||
| 471 | $ret.="\n"; | ||
| 472 | return($ret); | ||
| 473 | } | ||
| 474 | |||
| 475 | sub do_link_rule | ||
| 476 | { | ||
| 477 | my($target,$files,$dep_libs,$libs)=@_; | ||
| 478 | my($ret); | ||
| 479 | my($def_file) = do_def_file($target); | ||
| 480 | |||
| 481 | $ret.="$target: $files $dep_libs\n"; | ||
| 482 | |||
| 483 | # NOTE: When building the test nlms no screen name is given | ||
| 484 | # which causes the console screen to be used. By using the console | ||
| 485 | # screen there is no "<press any key to continue>" message which | ||
| 486 | # requires user interaction. The test script ( do_tests.pl ) needs | ||
| 487 | # to be able to run the tests without requiring user interaction. | ||
| 488 | # | ||
| 489 | # However, the sample program "openssl.nlm" is used by the tests and is | ||
| 490 | # a interactive sample so a screen is desired when not be run by the | ||
| 491 | # tests. To solve the problem, two versions of the program are built: | ||
| 492 | # openssl2 - no screen used by tests | ||
| 493 | # openssl - default screen - use for normal interactive modes | ||
| 494 | # | ||
| 495 | |||
| 496 | # special case for openssl - the mk1mf.pl defines E_EXE = openssl | ||
| 497 | if ($target =~ /E_EXE/) | ||
| 498 | { | ||
| 499 | my($target2) = $target; | ||
| 500 | |||
| 501 | $target2 =~ s/\(E_EXE\)/\(E_EXE\)2/; | ||
| 502 | |||
| 503 | # openssl2 | ||
| 504 | my($def_file2) = do_def_file($target2); | ||
| 505 | |||
| 506 | if ($gnuc) | ||
| 507 | { | ||
| 508 | $ret.="\t\$(MKLIB) $lib_flags \$(TMP_D)${o}\$(E_EXE).a \$(filter-out \$(TMP_D)${o}\$(E_EXE)${obj},$files)\n"; | ||
| 509 | $ret.="\t\$(LINK) \$(LFLAGS) $def_file2\n"; | ||
| 510 | $ret.="\t\@$mv \$(E_EXE)2.nlm \$(TEST_D)\n"; | ||
| 511 | } | ||
| 512 | else | ||
| 513 | { | ||
| 514 | $ret.="\t\$(LINK) \$(LFLAGS) $def_file2 $files \"$prelude\" $libs -o $target2\n"; | ||
| 515 | } | ||
| 516 | } | ||
| 517 | if ($gnuc) | ||
| 518 | { | ||
| 519 | $ret.="\t\$(LINK) \$(LFLAGS) $def_file\n"; | ||
| 520 | $ret.="\t\@$mv \$(\@F) \$(TEST_D)\n"; | ||
| 521 | } | ||
| 522 | else | ||
| 523 | { | ||
| 524 | $ret.="\t\$(LINK) \$(LFLAGS) $def_file $files \"$prelude\" $libs -o $target\n"; | ||
| 525 | } | ||
| 526 | |||
| 527 | $ret.="\n"; | ||
| 528 | return($ret); | ||
| 529 | |||
| 530 | } | ||
| 531 | |||
| 532 | 1; | ||
diff --git a/src/lib/libcrypto/whrlpool/Makefile b/src/lib/libcrypto/whrlpool/Makefile new file mode 100644 index 0000000000..566b996290 --- /dev/null +++ b/src/lib/libcrypto/whrlpool/Makefile | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | # | ||
| 2 | # crypto/whrlpool/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= whrlpool | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | CPP= $(CC) -E | ||
| 9 | INCLUDES= | ||
| 10 | CFLAG=-g | ||
| 11 | MAKEFILE= Makefile | ||
| 12 | AR= ar r | ||
| 13 | |||
| 14 | WP_ASM_OBJ=wp_block.o | ||
| 15 | |||
| 16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 17 | ASFLAGS= $(INCLUDES) $(ASFLAG) | ||
| 18 | AFLAGS= $(ASFLAGS) | ||
| 19 | |||
| 20 | GENERAL=Makefile | ||
| 21 | TEST=wp_test.c | ||
| 22 | APPS= | ||
| 23 | |||
| 24 | LIB=$(TOP)/libcrypto.a | ||
| 25 | LIBSRC=wp_dgst.c wp_block.c | ||
| 26 | LIBOBJ=wp_dgst.o $(WP_ASM_OBJ) | ||
| 27 | |||
| 28 | SRC= $(LIBSRC) | ||
| 29 | |||
| 30 | EXHEADER= whrlpool.h | ||
| 31 | HEADER= wp_locl.h $(EXHEADER) | ||
| 32 | |||
| 33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 34 | |||
| 35 | top: | ||
| 36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 37 | |||
| 38 | all: lib | ||
| 39 | |||
| 40 | lib: $(LIBOBJ) | ||
| 41 | $(AR) $(LIB) $(LIBOBJ) | ||
| 42 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 43 | @touch lib | ||
| 44 | |||
| 45 | wp-mmx.s: asm/wp-mmx.pl ../perlasm/x86asm.pl | ||
| 46 | $(PERL) asm/wp-mmx.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@ | ||
| 47 | |||
| 48 | wp-x86_64.s: asm/wp-x86_64.pl | ||
| 49 | $(PERL) asm/wp-x86_64.pl $(PERLASM_SCHEME) > $@ | ||
| 50 | |||
| 51 | $(LIBOBJ): $(LIBSRC) | ||
| 52 | |||
| 53 | files: | ||
| 54 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 55 | |||
| 56 | links: | ||
| 57 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 58 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 59 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 60 | |||
| 61 | install: | ||
| 62 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 63 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 64 | do \ | ||
| 65 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 66 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 67 | done; | ||
| 68 | |||
| 69 | tags: | ||
| 70 | ctags $(SRC) | ||
| 71 | |||
| 72 | tests: | ||
| 73 | |||
| 74 | lint: | ||
| 75 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 76 | |||
| 77 | depend: | ||
| 78 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 79 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 80 | |||
| 81 | dclean: | ||
| 82 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 83 | mv -f Makefile.new $(MAKEFILE) | ||
| 84 | |||
| 85 | clean: | ||
| 86 | rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 87 | |||
| 88 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 89 | |||
| 90 | wp_block.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | ||
| 91 | wp_block.o: ../../include/openssl/whrlpool.h wp_block.c wp_locl.h | ||
| 92 | wp_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | ||
| 93 | wp_dgst.o: ../../include/openssl/whrlpool.h wp_dgst.c wp_locl.h | ||
diff --git a/src/lib/libcrypto/whrlpool/wp_test.c b/src/lib/libcrypto/whrlpool/wp_test.c new file mode 100644 index 0000000000..c68c2c62ca --- /dev/null +++ b/src/lib/libcrypto/whrlpool/wp_test.c | |||
| @@ -0,0 +1,228 @@ | |||
| 1 | /* ==================================================================== | ||
| 2 | * Copyright (c) 2005 The OpenSSL Project. All rights reserved. | ||
| 3 | * ==================================================================== | ||
| 4 | */ | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | |||
| 9 | #include <openssl/whrlpool.h> | ||
| 10 | #include <openssl/crypto.h> | ||
| 11 | |||
| 12 | #if defined(OPENSSL_NO_WHIRLPOOL) | ||
| 13 | int main(int argc, char *argv[]) | ||
| 14 | { | ||
| 15 | printf("No Whirlpool support\n"); | ||
| 16 | return(0); | ||
| 17 | } | ||
| 18 | #else | ||
| 19 | |||
| 20 | /* ISO/IEC 10118-3 test vector set */ | ||
| 21 | unsigned char iso_test_1[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 22 | 0x19,0xFA,0x61,0xD7,0x55,0x22,0xA4,0x66, | ||
| 23 | 0x9B,0x44,0xE3,0x9C,0x1D,0x2E,0x17,0x26, | ||
| 24 | 0xC5,0x30,0x23,0x21,0x30,0xD4,0x07,0xF8, | ||
| 25 | 0x9A,0xFE,0xE0,0x96,0x49,0x97,0xF7,0xA7, | ||
| 26 | 0x3E,0x83,0xBE,0x69,0x8B,0x28,0x8F,0xEB, | ||
| 27 | 0xCF,0x88,0xE3,0xE0,0x3C,0x4F,0x07,0x57, | ||
| 28 | 0xEA,0x89,0x64,0xE5,0x9B,0x63,0xD9,0x37, | ||
| 29 | 0x08,0xB1,0x38,0xCC,0x42,0xA6,0x6E,0xB3 }; | ||
| 30 | |||
| 31 | unsigned char iso_test_2[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 32 | 0x8A,0xCA,0x26,0x02,0x79,0x2A,0xEC,0x6F, | ||
| 33 | 0x11,0xA6,0x72,0x06,0x53,0x1F,0xB7,0xD7, | ||
| 34 | 0xF0,0xDF,0xF5,0x94,0x13,0x14,0x5E,0x69, | ||
| 35 | 0x73,0xC4,0x50,0x01,0xD0,0x08,0x7B,0x42, | ||
| 36 | 0xD1,0x1B,0xC6,0x45,0x41,0x3A,0xEF,0xF6, | ||
| 37 | 0x3A,0x42,0x39,0x1A,0x39,0x14,0x5A,0x59, | ||
| 38 | 0x1A,0x92,0x20,0x0D,0x56,0x01,0x95,0xE5, | ||
| 39 | 0x3B,0x47,0x85,0x84,0xFD,0xAE,0x23,0x1A }; | ||
| 40 | |||
| 41 | unsigned char iso_test_3[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 42 | 0x4E,0x24,0x48,0xA4,0xC6,0xF4,0x86,0xBB, | ||
| 43 | 0x16,0xB6,0x56,0x2C,0x73,0xB4,0x02,0x0B, | ||
| 44 | 0xF3,0x04,0x3E,0x3A,0x73,0x1B,0xCE,0x72, | ||
| 45 | 0x1A,0xE1,0xB3,0x03,0xD9,0x7E,0x6D,0x4C, | ||
| 46 | 0x71,0x81,0xEE,0xBD,0xB6,0xC5,0x7E,0x27, | ||
| 47 | 0x7D,0x0E,0x34,0x95,0x71,0x14,0xCB,0xD6, | ||
| 48 | 0xC7,0x97,0xFC,0x9D,0x95,0xD8,0xB5,0x82, | ||
| 49 | 0xD2,0x25,0x29,0x20,0x76,0xD4,0xEE,0xF5 }; | ||
| 50 | |||
| 51 | unsigned char iso_test_4[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 52 | 0x37,0x8C,0x84,0xA4,0x12,0x6E,0x2D,0xC6, | ||
| 53 | 0xE5,0x6D,0xCC,0x74,0x58,0x37,0x7A,0xAC, | ||
| 54 | 0x83,0x8D,0x00,0x03,0x22,0x30,0xF5,0x3C, | ||
| 55 | 0xE1,0xF5,0x70,0x0C,0x0F,0xFB,0x4D,0x3B, | ||
| 56 | 0x84,0x21,0x55,0x76,0x59,0xEF,0x55,0xC1, | ||
| 57 | 0x06,0xB4,0xB5,0x2A,0xC5,0xA4,0xAA,0xA6, | ||
| 58 | 0x92,0xED,0x92,0x00,0x52,0x83,0x8F,0x33, | ||
| 59 | 0x62,0xE8,0x6D,0xBD,0x37,0xA8,0x90,0x3E }; | ||
| 60 | |||
| 61 | unsigned char iso_test_5[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 62 | 0xF1,0xD7,0x54,0x66,0x26,0x36,0xFF,0xE9, | ||
| 63 | 0x2C,0x82,0xEB,0xB9,0x21,0x2A,0x48,0x4A, | ||
| 64 | 0x8D,0x38,0x63,0x1E,0xAD,0x42,0x38,0xF5, | ||
| 65 | 0x44,0x2E,0xE1,0x3B,0x80,0x54,0xE4,0x1B, | ||
| 66 | 0x08,0xBF,0x2A,0x92,0x51,0xC3,0x0B,0x6A, | ||
| 67 | 0x0B,0x8A,0xAE,0x86,0x17,0x7A,0xB4,0xA6, | ||
| 68 | 0xF6,0x8F,0x67,0x3E,0x72,0x07,0x86,0x5D, | ||
| 69 | 0x5D,0x98,0x19,0xA3,0xDB,0xA4,0xEB,0x3B }; | ||
| 70 | |||
| 71 | unsigned char iso_test_6[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 72 | 0xDC,0x37,0xE0,0x08,0xCF,0x9E,0xE6,0x9B, | ||
| 73 | 0xF1,0x1F,0x00,0xED,0x9A,0xBA,0x26,0x90, | ||
| 74 | 0x1D,0xD7,0xC2,0x8C,0xDE,0xC0,0x66,0xCC, | ||
| 75 | 0x6A,0xF4,0x2E,0x40,0xF8,0x2F,0x3A,0x1E, | ||
| 76 | 0x08,0xEB,0xA2,0x66,0x29,0x12,0x9D,0x8F, | ||
| 77 | 0xB7,0xCB,0x57,0x21,0x1B,0x92,0x81,0xA6, | ||
| 78 | 0x55,0x17,0xCC,0x87,0x9D,0x7B,0x96,0x21, | ||
| 79 | 0x42,0xC6,0x5F,0x5A,0x7A,0xF0,0x14,0x67 }; | ||
| 80 | |||
| 81 | unsigned char iso_test_7[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 82 | 0x46,0x6E,0xF1,0x8B,0xAB,0xB0,0x15,0x4D, | ||
| 83 | 0x25,0xB9,0xD3,0x8A,0x64,0x14,0xF5,0xC0, | ||
| 84 | 0x87,0x84,0x37,0x2B,0xCC,0xB2,0x04,0xD6, | ||
| 85 | 0x54,0x9C,0x4A,0xFA,0xDB,0x60,0x14,0x29, | ||
| 86 | 0x4D,0x5B,0xD8,0xDF,0x2A,0x6C,0x44,0xE5, | ||
| 87 | 0x38,0xCD,0x04,0x7B,0x26,0x81,0xA5,0x1A, | ||
| 88 | 0x2C,0x60,0x48,0x1E,0x88,0xC5,0xA2,0x0B, | ||
| 89 | 0x2C,0x2A,0x80,0xCF,0x3A,0x9A,0x08,0x3B }; | ||
| 90 | |||
| 91 | unsigned char iso_test_8[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 92 | 0x2A,0x98,0x7E,0xA4,0x0F,0x91,0x70,0x61, | ||
| 93 | 0xF5,0xD6,0xF0,0xA0,0xE4,0x64,0x4F,0x48, | ||
| 94 | 0x8A,0x7A,0x5A,0x52,0xDE,0xEE,0x65,0x62, | ||
| 95 | 0x07,0xC5,0x62,0xF9,0x88,0xE9,0x5C,0x69, | ||
| 96 | 0x16,0xBD,0xC8,0x03,0x1B,0xC5,0xBE,0x1B, | ||
| 97 | 0x7B,0x94,0x76,0x39,0xFE,0x05,0x0B,0x56, | ||
| 98 | 0x93,0x9B,0xAA,0xA0,0xAD,0xFF,0x9A,0xE6, | ||
| 99 | 0x74,0x5B,0x7B,0x18,0x1C,0x3B,0xE3,0xFD }; | ||
| 100 | |||
| 101 | unsigned char iso_test_9[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 102 | 0x0C,0x99,0x00,0x5B,0xEB,0x57,0xEF,0xF5, | ||
| 103 | 0x0A,0x7C,0xF0,0x05,0x56,0x0D,0xDF,0x5D, | ||
| 104 | 0x29,0x05,0x7F,0xD8,0x6B,0x20,0xBF,0xD6, | ||
| 105 | 0x2D,0xEC,0xA0,0xF1,0xCC,0xEA,0x4A,0xF5, | ||
| 106 | 0x1F,0xC1,0x54,0x90,0xED,0xDC,0x47,0xAF, | ||
| 107 | 0x32,0xBB,0x2B,0x66,0xC3,0x4F,0xF9,0xAD, | ||
| 108 | 0x8C,0x60,0x08,0xAD,0x67,0x7F,0x77,0x12, | ||
| 109 | 0x69,0x53,0xB2,0x26,0xE4,0xED,0x8B,0x01 }; | ||
| 110 | |||
| 111 | int main (int argc,char *argv[]) | ||
| 112 | { unsigned char md[WHIRLPOOL_DIGEST_LENGTH]; | ||
| 113 | int i; | ||
| 114 | WHIRLPOOL_CTX ctx; | ||
| 115 | |||
| 116 | #ifdef OPENSSL_IA32_SSE2 | ||
| 117 | /* Alternative to this is to call OpenSSL_add_all_algorithms... | ||
| 118 | * The below code is retained exclusively for debugging purposes. */ | ||
| 119 | { char *env; | ||
| 120 | |||
| 121 | if ((env=getenv("OPENSSL_ia32cap"))) | ||
| 122 | OPENSSL_ia32cap = strtoul (env,NULL,0); | ||
| 123 | } | ||
| 124 | #endif | ||
| 125 | |||
| 126 | fprintf(stdout,"Testing Whirlpool "); | ||
| 127 | |||
| 128 | WHIRLPOOL("",0,md); | ||
| 129 | if (memcmp(md,iso_test_1,sizeof(iso_test_1))) | ||
| 130 | { fflush(stdout); | ||
| 131 | fprintf(stderr,"\nTEST 1 of 9 failed.\n"); | ||
| 132 | return 1; | ||
| 133 | } | ||
| 134 | else | ||
| 135 | fprintf(stdout,"."); fflush(stdout); | ||
| 136 | |||
| 137 | WHIRLPOOL("a",1,md); | ||
| 138 | if (memcmp(md,iso_test_2,sizeof(iso_test_2))) | ||
| 139 | { fflush(stdout); | ||
| 140 | fprintf(stderr,"\nTEST 2 of 9 failed.\n"); | ||
| 141 | return 1; | ||
| 142 | } | ||
| 143 | else | ||
| 144 | fprintf(stdout,"."); fflush(stdout); | ||
| 145 | |||
| 146 | WHIRLPOOL("abc",3,md); | ||
| 147 | if (memcmp(md,iso_test_3,sizeof(iso_test_3))) | ||
| 148 | { fflush(stdout); | ||
| 149 | fprintf(stderr,"\nTEST 3 of 9 failed.\n"); | ||
| 150 | return 1; | ||
| 151 | } | ||
| 152 | else | ||
| 153 | fprintf(stdout,"."); fflush(stdout); | ||
| 154 | |||
| 155 | WHIRLPOOL("message digest",14,md); | ||
| 156 | if (memcmp(md,iso_test_4,sizeof(iso_test_4))) | ||
| 157 | { fflush(stdout); | ||
| 158 | fprintf(stderr,"\nTEST 4 of 9 failed.\n"); | ||
| 159 | return 1; | ||
| 160 | } | ||
| 161 | else | ||
| 162 | fprintf(stdout,"."); fflush(stdout); | ||
| 163 | |||
| 164 | WHIRLPOOL("abcdefghijklmnopqrstuvwxyz",26,md); | ||
| 165 | if (memcmp(md,iso_test_5,sizeof(iso_test_5))) | ||
| 166 | { fflush(stdout); | ||
| 167 | fprintf(stderr,"\nTEST 5 of 9 failed.\n"); | ||
| 168 | return 1; | ||
| 169 | } | ||
| 170 | else | ||
| 171 | fprintf(stdout,"."); fflush(stdout); | ||
| 172 | |||
| 173 | WHIRLPOOL( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
| 174 | "abcdefghijklmnopqrstuvwxyz" | ||
| 175 | "0123456789",62,md); | ||
| 176 | if (memcmp(md,iso_test_6,sizeof(iso_test_6))) | ||
| 177 | { fflush(stdout); | ||
| 178 | fprintf(stderr,"\nTEST 6 of 9 failed.\n"); | ||
| 179 | return 1; | ||
| 180 | } | ||
| 181 | else | ||
| 182 | fprintf(stdout,"."); fflush(stdout); | ||
| 183 | |||
| 184 | WHIRLPOOL( "1234567890""1234567890""1234567890""1234567890" | ||
| 185 | "1234567890""1234567890""1234567890""1234567890",80,md); | ||
| 186 | if (memcmp(md,iso_test_7,sizeof(iso_test_7))) | ||
| 187 | { fflush(stdout); | ||
| 188 | fprintf(stderr,"\nTEST 7 of 9 failed.\n"); | ||
| 189 | return 1; | ||
| 190 | } | ||
| 191 | else | ||
| 192 | fprintf(stdout,"."); fflush(stdout); | ||
| 193 | |||
| 194 | WHIRLPOOL("abcdbcdecdefdefgefghfghighijhijk",32,md); | ||
| 195 | if (memcmp(md,iso_test_8,sizeof(iso_test_8))) | ||
| 196 | { fflush(stdout); | ||
| 197 | fprintf(stderr,"\nTEST 8 of 9 failed.\n"); | ||
| 198 | return 1; | ||
| 199 | } | ||
| 200 | else | ||
| 201 | fprintf(stdout,"."); fflush(stdout); | ||
| 202 | |||
| 203 | WHIRLPOOL_Init (&ctx); | ||
| 204 | for (i=0;i<1000000;i+=288) | ||
| 205 | WHIRLPOOL_Update (&ctx, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 206 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 207 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 208 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 209 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 210 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 211 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 212 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 213 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 214 | (1000000-i)<288?1000000-i:288); | ||
| 215 | WHIRLPOOL_Final (md,&ctx); | ||
| 216 | if (memcmp(md,iso_test_9,sizeof(iso_test_9))) | ||
| 217 | { fflush(stdout); | ||
| 218 | fprintf(stderr,"\nTEST 9 of 9 failed.\n"); | ||
| 219 | return 1; | ||
| 220 | } | ||
| 221 | else | ||
| 222 | fprintf(stdout,"."); fflush(stdout); | ||
| 223 | |||
| 224 | fprintf(stdout," passed.\n"); fflush(stdout); | ||
| 225 | |||
| 226 | return 0; | ||
| 227 | } | ||
| 228 | #endif | ||
diff --git a/src/lib/libcrypto/x509v3/v3_addr.c b/src/lib/libcrypto/x509v3/v3_addr.c new file mode 100644 index 0000000000..9087d66e0a --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_addr.c | |||
| @@ -0,0 +1,1287 @@ | |||
| 1 | /* | ||
| 2 | * Contributed to the OpenSSL Project by the American Registry for | ||
| 3 | * Internet Numbers ("ARIN"). | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2006 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | */ | ||
| 57 | |||
| 58 | /* | ||
| 59 | * Implementation of RFC 3779 section 2.2. | ||
| 60 | */ | ||
| 61 | |||
| 62 | #include <stdio.h> | ||
| 63 | #include <stdlib.h> | ||
| 64 | |||
| 65 | #include "cryptlib.h" | ||
| 66 | #include <openssl/conf.h> | ||
| 67 | #include <openssl/asn1.h> | ||
| 68 | #include <openssl/asn1t.h> | ||
| 69 | #include <openssl/buffer.h> | ||
| 70 | #include <openssl/x509v3.h> | ||
| 71 | |||
| 72 | #ifndef OPENSSL_NO_RFC3779 | ||
| 73 | |||
| 74 | /* | ||
| 75 | * OpenSSL ASN.1 template translation of RFC 3779 2.2.3. | ||
| 76 | */ | ||
| 77 | |||
| 78 | ASN1_SEQUENCE(IPAddressRange) = { | ||
| 79 | ASN1_SIMPLE(IPAddressRange, min, ASN1_BIT_STRING), | ||
| 80 | ASN1_SIMPLE(IPAddressRange, max, ASN1_BIT_STRING) | ||
| 81 | } ASN1_SEQUENCE_END(IPAddressRange) | ||
| 82 | |||
| 83 | ASN1_CHOICE(IPAddressOrRange) = { | ||
| 84 | ASN1_SIMPLE(IPAddressOrRange, u.addressPrefix, ASN1_BIT_STRING), | ||
| 85 | ASN1_SIMPLE(IPAddressOrRange, u.addressRange, IPAddressRange) | ||
| 86 | } ASN1_CHOICE_END(IPAddressOrRange) | ||
| 87 | |||
| 88 | ASN1_CHOICE(IPAddressChoice) = { | ||
| 89 | ASN1_SIMPLE(IPAddressChoice, u.inherit, ASN1_NULL), | ||
| 90 | ASN1_SEQUENCE_OF(IPAddressChoice, u.addressesOrRanges, IPAddressOrRange) | ||
| 91 | } ASN1_CHOICE_END(IPAddressChoice) | ||
| 92 | |||
| 93 | ASN1_SEQUENCE(IPAddressFamily) = { | ||
| 94 | ASN1_SIMPLE(IPAddressFamily, addressFamily, ASN1_OCTET_STRING), | ||
| 95 | ASN1_SIMPLE(IPAddressFamily, ipAddressChoice, IPAddressChoice) | ||
| 96 | } ASN1_SEQUENCE_END(IPAddressFamily) | ||
| 97 | |||
| 98 | ASN1_ITEM_TEMPLATE(IPAddrBlocks) = | ||
| 99 | ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, | ||
| 100 | IPAddrBlocks, IPAddressFamily) | ||
| 101 | ASN1_ITEM_TEMPLATE_END(IPAddrBlocks) | ||
| 102 | |||
| 103 | IMPLEMENT_ASN1_FUNCTIONS(IPAddressRange) | ||
| 104 | IMPLEMENT_ASN1_FUNCTIONS(IPAddressOrRange) | ||
| 105 | IMPLEMENT_ASN1_FUNCTIONS(IPAddressChoice) | ||
| 106 | IMPLEMENT_ASN1_FUNCTIONS(IPAddressFamily) | ||
| 107 | |||
| 108 | /* | ||
| 109 | * How much buffer space do we need for a raw address? | ||
| 110 | */ | ||
| 111 | #define ADDR_RAW_BUF_LEN 16 | ||
| 112 | |||
| 113 | /* | ||
| 114 | * What's the address length associated with this AFI? | ||
| 115 | */ | ||
| 116 | static int length_from_afi(const unsigned afi) | ||
| 117 | { | ||
| 118 | switch (afi) { | ||
| 119 | case IANA_AFI_IPV4: | ||
| 120 | return 4; | ||
| 121 | case IANA_AFI_IPV6: | ||
| 122 | return 16; | ||
| 123 | default: | ||
| 124 | return 0; | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | /* | ||
| 129 | * Extract the AFI from an IPAddressFamily. | ||
| 130 | */ | ||
| 131 | unsigned int v3_addr_get_afi(const IPAddressFamily *f) | ||
| 132 | { | ||
| 133 | return ((f != NULL && | ||
| 134 | f->addressFamily != NULL && | ||
| 135 | f->addressFamily->data != NULL) | ||
| 136 | ? ((f->addressFamily->data[0] << 8) | | ||
| 137 | (f->addressFamily->data[1])) | ||
| 138 | : 0); | ||
| 139 | } | ||
| 140 | |||
| 141 | /* | ||
| 142 | * Expand the bitstring form of an address into a raw byte array. | ||
| 143 | * At the moment this is coded for simplicity, not speed. | ||
| 144 | */ | ||
| 145 | static void addr_expand(unsigned char *addr, | ||
| 146 | const ASN1_BIT_STRING *bs, | ||
| 147 | const int length, | ||
| 148 | const unsigned char fill) | ||
| 149 | { | ||
| 150 | OPENSSL_assert(bs->length >= 0 && bs->length <= length); | ||
| 151 | if (bs->length > 0) { | ||
| 152 | memcpy(addr, bs->data, bs->length); | ||
| 153 | if ((bs->flags & 7) != 0) { | ||
| 154 | unsigned char mask = 0xFF >> (8 - (bs->flags & 7)); | ||
| 155 | if (fill == 0) | ||
| 156 | addr[bs->length - 1] &= ~mask; | ||
| 157 | else | ||
| 158 | addr[bs->length - 1] |= mask; | ||
| 159 | } | ||
| 160 | } | ||
| 161 | memset(addr + bs->length, fill, length - bs->length); | ||
| 162 | } | ||
| 163 | |||
| 164 | /* | ||
| 165 | * Extract the prefix length from a bitstring. | ||
| 166 | */ | ||
| 167 | #define addr_prefixlen(bs) ((int) ((bs)->length * 8 - ((bs)->flags & 7))) | ||
| 168 | |||
| 169 | /* | ||
| 170 | * i2r handler for one address bitstring. | ||
| 171 | */ | ||
| 172 | static int i2r_address(BIO *out, | ||
| 173 | const unsigned afi, | ||
| 174 | const unsigned char fill, | ||
| 175 | const ASN1_BIT_STRING *bs) | ||
| 176 | { | ||
| 177 | unsigned char addr[ADDR_RAW_BUF_LEN]; | ||
| 178 | int i, n; | ||
| 179 | |||
| 180 | switch (afi) { | ||
| 181 | case IANA_AFI_IPV4: | ||
| 182 | addr_expand(addr, bs, 4, fill); | ||
| 183 | BIO_printf(out, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]); | ||
| 184 | break; | ||
| 185 | case IANA_AFI_IPV6: | ||
| 186 | addr_expand(addr, bs, 16, fill); | ||
| 187 | for (n = 16; n > 1 && addr[n-1] == 0x00 && addr[n-2] == 0x00; n -= 2) | ||
| 188 | ; | ||
| 189 | for (i = 0; i < n; i += 2) | ||
| 190 | BIO_printf(out, "%x%s", (addr[i] << 8) | addr[i+1], (i < 14 ? ":" : "")); | ||
| 191 | if (i < 16) | ||
| 192 | BIO_puts(out, ":"); | ||
| 193 | if (i == 0) | ||
| 194 | BIO_puts(out, ":"); | ||
| 195 | break; | ||
| 196 | default: | ||
| 197 | for (i = 0; i < bs->length; i++) | ||
| 198 | BIO_printf(out, "%s%02x", (i > 0 ? ":" : ""), bs->data[i]); | ||
| 199 | BIO_printf(out, "[%d]", (int) (bs->flags & 7)); | ||
| 200 | break; | ||
| 201 | } | ||
| 202 | return 1; | ||
| 203 | } | ||
| 204 | |||
| 205 | /* | ||
| 206 | * i2r handler for a sequence of addresses and ranges. | ||
| 207 | */ | ||
| 208 | static int i2r_IPAddressOrRanges(BIO *out, | ||
| 209 | const int indent, | ||
| 210 | const IPAddressOrRanges *aors, | ||
| 211 | const unsigned afi) | ||
| 212 | { | ||
| 213 | int i; | ||
| 214 | for (i = 0; i < sk_IPAddressOrRange_num(aors); i++) { | ||
| 215 | const IPAddressOrRange *aor = sk_IPAddressOrRange_value(aors, i); | ||
| 216 | BIO_printf(out, "%*s", indent, ""); | ||
| 217 | switch (aor->type) { | ||
| 218 | case IPAddressOrRange_addressPrefix: | ||
| 219 | if (!i2r_address(out, afi, 0x00, aor->u.addressPrefix)) | ||
| 220 | return 0; | ||
| 221 | BIO_printf(out, "/%d\n", addr_prefixlen(aor->u.addressPrefix)); | ||
| 222 | continue; | ||
| 223 | case IPAddressOrRange_addressRange: | ||
| 224 | if (!i2r_address(out, afi, 0x00, aor->u.addressRange->min)) | ||
| 225 | return 0; | ||
| 226 | BIO_puts(out, "-"); | ||
| 227 | if (!i2r_address(out, afi, 0xFF, aor->u.addressRange->max)) | ||
| 228 | return 0; | ||
| 229 | BIO_puts(out, "\n"); | ||
| 230 | continue; | ||
| 231 | } | ||
| 232 | } | ||
| 233 | return 1; | ||
| 234 | } | ||
| 235 | |||
| 236 | /* | ||
| 237 | * i2r handler for an IPAddrBlocks extension. | ||
| 238 | */ | ||
| 239 | static int i2r_IPAddrBlocks(const X509V3_EXT_METHOD *method, | ||
| 240 | void *ext, | ||
| 241 | BIO *out, | ||
| 242 | int indent) | ||
| 243 | { | ||
| 244 | const IPAddrBlocks *addr = ext; | ||
| 245 | int i; | ||
| 246 | for (i = 0; i < sk_IPAddressFamily_num(addr); i++) { | ||
| 247 | IPAddressFamily *f = sk_IPAddressFamily_value(addr, i); | ||
| 248 | const unsigned int afi = v3_addr_get_afi(f); | ||
| 249 | switch (afi) { | ||
| 250 | case IANA_AFI_IPV4: | ||
| 251 | BIO_printf(out, "%*sIPv4", indent, ""); | ||
| 252 | break; | ||
| 253 | case IANA_AFI_IPV6: | ||
| 254 | BIO_printf(out, "%*sIPv6", indent, ""); | ||
| 255 | break; | ||
| 256 | default: | ||
| 257 | BIO_printf(out, "%*sUnknown AFI %u", indent, "", afi); | ||
| 258 | break; | ||
| 259 | } | ||
| 260 | if (f->addressFamily->length > 2) { | ||
| 261 | switch (f->addressFamily->data[2]) { | ||
| 262 | case 1: | ||
| 263 | BIO_puts(out, " (Unicast)"); | ||
| 264 | break; | ||
| 265 | case 2: | ||
| 266 | BIO_puts(out, " (Multicast)"); | ||
| 267 | break; | ||
| 268 | case 3: | ||
| 269 | BIO_puts(out, " (Unicast/Multicast)"); | ||
| 270 | break; | ||
| 271 | case 4: | ||
| 272 | BIO_puts(out, " (MPLS)"); | ||
| 273 | break; | ||
| 274 | case 64: | ||
| 275 | BIO_puts(out, " (Tunnel)"); | ||
| 276 | break; | ||
| 277 | case 65: | ||
| 278 | BIO_puts(out, " (VPLS)"); | ||
| 279 | break; | ||
| 280 | case 66: | ||
| 281 | BIO_puts(out, " (BGP MDT)"); | ||
| 282 | break; | ||
| 283 | case 128: | ||
| 284 | BIO_puts(out, " (MPLS-labeled VPN)"); | ||
| 285 | break; | ||
| 286 | default: | ||
| 287 | BIO_printf(out, " (Unknown SAFI %u)", | ||
| 288 | (unsigned) f->addressFamily->data[2]); | ||
| 289 | break; | ||
| 290 | } | ||
| 291 | } | ||
| 292 | switch (f->ipAddressChoice->type) { | ||
| 293 | case IPAddressChoice_inherit: | ||
| 294 | BIO_puts(out, ": inherit\n"); | ||
| 295 | break; | ||
| 296 | case IPAddressChoice_addressesOrRanges: | ||
| 297 | BIO_puts(out, ":\n"); | ||
| 298 | if (!i2r_IPAddressOrRanges(out, | ||
| 299 | indent + 2, | ||
| 300 | f->ipAddressChoice->u.addressesOrRanges, | ||
| 301 | afi)) | ||
| 302 | return 0; | ||
| 303 | break; | ||
| 304 | } | ||
| 305 | } | ||
| 306 | return 1; | ||
| 307 | } | ||
| 308 | |||
| 309 | /* | ||
| 310 | * Sort comparison function for a sequence of IPAddressOrRange | ||
| 311 | * elements. | ||
| 312 | */ | ||
| 313 | static int IPAddressOrRange_cmp(const IPAddressOrRange *a, | ||
| 314 | const IPAddressOrRange *b, | ||
| 315 | const int length) | ||
| 316 | { | ||
| 317 | unsigned char addr_a[ADDR_RAW_BUF_LEN], addr_b[ADDR_RAW_BUF_LEN]; | ||
| 318 | int prefixlen_a = 0, prefixlen_b = 0; | ||
| 319 | int r; | ||
| 320 | |||
| 321 | switch (a->type) { | ||
| 322 | case IPAddressOrRange_addressPrefix: | ||
| 323 | addr_expand(addr_a, a->u.addressPrefix, length, 0x00); | ||
| 324 | prefixlen_a = addr_prefixlen(a->u.addressPrefix); | ||
| 325 | break; | ||
| 326 | case IPAddressOrRange_addressRange: | ||
| 327 | addr_expand(addr_a, a->u.addressRange->min, length, 0x00); | ||
| 328 | prefixlen_a = length * 8; | ||
| 329 | break; | ||
| 330 | } | ||
| 331 | |||
| 332 | switch (b->type) { | ||
| 333 | case IPAddressOrRange_addressPrefix: | ||
| 334 | addr_expand(addr_b, b->u.addressPrefix, length, 0x00); | ||
| 335 | prefixlen_b = addr_prefixlen(b->u.addressPrefix); | ||
| 336 | break; | ||
| 337 | case IPAddressOrRange_addressRange: | ||
| 338 | addr_expand(addr_b, b->u.addressRange->min, length, 0x00); | ||
| 339 | prefixlen_b = length * 8; | ||
| 340 | break; | ||
| 341 | } | ||
| 342 | |||
| 343 | if ((r = memcmp(addr_a, addr_b, length)) != 0) | ||
| 344 | return r; | ||
| 345 | else | ||
| 346 | return prefixlen_a - prefixlen_b; | ||
| 347 | } | ||
| 348 | |||
| 349 | /* | ||
| 350 | * IPv4-specific closure over IPAddressOrRange_cmp, since sk_sort() | ||
| 351 | * comparision routines are only allowed two arguments. | ||
| 352 | */ | ||
| 353 | static int v4IPAddressOrRange_cmp(const IPAddressOrRange * const *a, | ||
| 354 | const IPAddressOrRange * const *b) | ||
| 355 | { | ||
| 356 | return IPAddressOrRange_cmp(*a, *b, 4); | ||
| 357 | } | ||
| 358 | |||
| 359 | /* | ||
| 360 | * IPv6-specific closure over IPAddressOrRange_cmp, since sk_sort() | ||
| 361 | * comparision routines are only allowed two arguments. | ||
| 362 | */ | ||
| 363 | static int v6IPAddressOrRange_cmp(const IPAddressOrRange * const *a, | ||
| 364 | const IPAddressOrRange * const *b) | ||
| 365 | { | ||
| 366 | return IPAddressOrRange_cmp(*a, *b, 16); | ||
| 367 | } | ||
| 368 | |||
| 369 | /* | ||
| 370 | * Calculate whether a range collapses to a prefix. | ||
| 371 | * See last paragraph of RFC 3779 2.2.3.7. | ||
| 372 | */ | ||
| 373 | static int range_should_be_prefix(const unsigned char *min, | ||
| 374 | const unsigned char *max, | ||
| 375 | const int length) | ||
| 376 | { | ||
| 377 | unsigned char mask; | ||
| 378 | int i, j; | ||
| 379 | |||
| 380 | for (i = 0; i < length && min[i] == max[i]; i++) | ||
| 381 | ; | ||
| 382 | for (j = length - 1; j >= 0 && min[j] == 0x00 && max[j] == 0xFF; j--) | ||
| 383 | ; | ||
| 384 | if (i < j) | ||
| 385 | return -1; | ||
| 386 | if (i > j) | ||
| 387 | return i * 8; | ||
| 388 | mask = min[i] ^ max[i]; | ||
| 389 | switch (mask) { | ||
| 390 | case 0x01: j = 7; break; | ||
| 391 | case 0x03: j = 6; break; | ||
| 392 | case 0x07: j = 5; break; | ||
| 393 | case 0x0F: j = 4; break; | ||
| 394 | case 0x1F: j = 3; break; | ||
| 395 | case 0x3F: j = 2; break; | ||
| 396 | case 0x7F: j = 1; break; | ||
| 397 | default: return -1; | ||
| 398 | } | ||
| 399 | if ((min[i] & mask) != 0 || (max[i] & mask) != mask) | ||
| 400 | return -1; | ||
| 401 | else | ||
| 402 | return i * 8 + j; | ||
| 403 | } | ||
| 404 | |||
| 405 | /* | ||
| 406 | * Construct a prefix. | ||
| 407 | */ | ||
| 408 | static int make_addressPrefix(IPAddressOrRange **result, | ||
| 409 | unsigned char *addr, | ||
| 410 | const int prefixlen) | ||
| 411 | { | ||
| 412 | int bytelen = (prefixlen + 7) / 8, bitlen = prefixlen % 8; | ||
| 413 | IPAddressOrRange *aor = IPAddressOrRange_new(); | ||
| 414 | |||
| 415 | if (aor == NULL) | ||
| 416 | return 0; | ||
| 417 | aor->type = IPAddressOrRange_addressPrefix; | ||
| 418 | if (aor->u.addressPrefix == NULL && | ||
| 419 | (aor->u.addressPrefix = ASN1_BIT_STRING_new()) == NULL) | ||
| 420 | goto err; | ||
| 421 | if (!ASN1_BIT_STRING_set(aor->u.addressPrefix, addr, bytelen)) | ||
| 422 | goto err; | ||
| 423 | aor->u.addressPrefix->flags &= ~7; | ||
| 424 | aor->u.addressPrefix->flags |= ASN1_STRING_FLAG_BITS_LEFT; | ||
| 425 | if (bitlen > 0) { | ||
| 426 | aor->u.addressPrefix->data[bytelen - 1] &= ~(0xFF >> bitlen); | ||
| 427 | aor->u.addressPrefix->flags |= 8 - bitlen; | ||
| 428 | } | ||
| 429 | |||
| 430 | *result = aor; | ||
| 431 | return 1; | ||
| 432 | |||
| 433 | err: | ||
| 434 | IPAddressOrRange_free(aor); | ||
| 435 | return 0; | ||
| 436 | } | ||
| 437 | |||
| 438 | /* | ||
| 439 | * Construct a range. If it can be expressed as a prefix, | ||
| 440 | * return a prefix instead. Doing this here simplifies | ||
| 441 | * the rest of the code considerably. | ||
| 442 | */ | ||
| 443 | static int make_addressRange(IPAddressOrRange **result, | ||
| 444 | unsigned char *min, | ||
| 445 | unsigned char *max, | ||
| 446 | const int length) | ||
| 447 | { | ||
| 448 | IPAddressOrRange *aor; | ||
| 449 | int i, prefixlen; | ||
| 450 | |||
| 451 | if ((prefixlen = range_should_be_prefix(min, max, length)) >= 0) | ||
| 452 | return make_addressPrefix(result, min, prefixlen); | ||
| 453 | |||
| 454 | if ((aor = IPAddressOrRange_new()) == NULL) | ||
| 455 | return 0; | ||
| 456 | aor->type = IPAddressOrRange_addressRange; | ||
| 457 | OPENSSL_assert(aor->u.addressRange == NULL); | ||
| 458 | if ((aor->u.addressRange = IPAddressRange_new()) == NULL) | ||
| 459 | goto err; | ||
| 460 | if (aor->u.addressRange->min == NULL && | ||
| 461 | (aor->u.addressRange->min = ASN1_BIT_STRING_new()) == NULL) | ||
| 462 | goto err; | ||
| 463 | if (aor->u.addressRange->max == NULL && | ||
| 464 | (aor->u.addressRange->max = ASN1_BIT_STRING_new()) == NULL) | ||
| 465 | goto err; | ||
| 466 | |||
| 467 | for (i = length; i > 0 && min[i - 1] == 0x00; --i) | ||
| 468 | ; | ||
| 469 | if (!ASN1_BIT_STRING_set(aor->u.addressRange->min, min, i)) | ||
| 470 | goto err; | ||
| 471 | aor->u.addressRange->min->flags &= ~7; | ||
| 472 | aor->u.addressRange->min->flags |= ASN1_STRING_FLAG_BITS_LEFT; | ||
| 473 | if (i > 0) { | ||
| 474 | unsigned char b = min[i - 1]; | ||
| 475 | int j = 1; | ||
| 476 | while ((b & (0xFFU >> j)) != 0) | ||
| 477 | ++j; | ||
| 478 | aor->u.addressRange->min->flags |= 8 - j; | ||
| 479 | } | ||
| 480 | |||
| 481 | for (i = length; i > 0 && max[i - 1] == 0xFF; --i) | ||
| 482 | ; | ||
| 483 | if (!ASN1_BIT_STRING_set(aor->u.addressRange->max, max, i)) | ||
| 484 | goto err; | ||
| 485 | aor->u.addressRange->max->flags &= ~7; | ||
| 486 | aor->u.addressRange->max->flags |= ASN1_STRING_FLAG_BITS_LEFT; | ||
| 487 | if (i > 0) { | ||
| 488 | unsigned char b = max[i - 1]; | ||
| 489 | int j = 1; | ||
| 490 | while ((b & (0xFFU >> j)) != (0xFFU >> j)) | ||
| 491 | ++j; | ||
| 492 | aor->u.addressRange->max->flags |= 8 - j; | ||
| 493 | } | ||
| 494 | |||
| 495 | *result = aor; | ||
| 496 | return 1; | ||
| 497 | |||
| 498 | err: | ||
| 499 | IPAddressOrRange_free(aor); | ||
| 500 | return 0; | ||
| 501 | } | ||
| 502 | |||
| 503 | /* | ||
| 504 | * Construct a new address family or find an existing one. | ||
| 505 | */ | ||
| 506 | static IPAddressFamily *make_IPAddressFamily(IPAddrBlocks *addr, | ||
| 507 | const unsigned afi, | ||
| 508 | const unsigned *safi) | ||
| 509 | { | ||
| 510 | IPAddressFamily *f; | ||
| 511 | unsigned char key[3]; | ||
| 512 | unsigned keylen; | ||
| 513 | int i; | ||
| 514 | |||
| 515 | key[0] = (afi >> 8) & 0xFF; | ||
| 516 | key[1] = afi & 0xFF; | ||
| 517 | if (safi != NULL) { | ||
| 518 | key[2] = *safi & 0xFF; | ||
| 519 | keylen = 3; | ||
| 520 | } else { | ||
| 521 | keylen = 2; | ||
| 522 | } | ||
| 523 | |||
| 524 | for (i = 0; i < sk_IPAddressFamily_num(addr); i++) { | ||
| 525 | f = sk_IPAddressFamily_value(addr, i); | ||
| 526 | OPENSSL_assert(f->addressFamily->data != NULL); | ||
| 527 | if (f->addressFamily->length == keylen && | ||
| 528 | !memcmp(f->addressFamily->data, key, keylen)) | ||
| 529 | return f; | ||
| 530 | } | ||
| 531 | |||
| 532 | if ((f = IPAddressFamily_new()) == NULL) | ||
| 533 | goto err; | ||
| 534 | if (f->ipAddressChoice == NULL && | ||
| 535 | (f->ipAddressChoice = IPAddressChoice_new()) == NULL) | ||
| 536 | goto err; | ||
| 537 | if (f->addressFamily == NULL && | ||
| 538 | (f->addressFamily = ASN1_OCTET_STRING_new()) == NULL) | ||
| 539 | goto err; | ||
| 540 | if (!ASN1_OCTET_STRING_set(f->addressFamily, key, keylen)) | ||
| 541 | goto err; | ||
| 542 | if (!sk_IPAddressFamily_push(addr, f)) | ||
| 543 | goto err; | ||
| 544 | |||
| 545 | return f; | ||
| 546 | |||
| 547 | err: | ||
| 548 | IPAddressFamily_free(f); | ||
| 549 | return NULL; | ||
| 550 | } | ||
| 551 | |||
| 552 | /* | ||
| 553 | * Add an inheritance element. | ||
| 554 | */ | ||
| 555 | int v3_addr_add_inherit(IPAddrBlocks *addr, | ||
| 556 | const unsigned afi, | ||
| 557 | const unsigned *safi) | ||
| 558 | { | ||
| 559 | IPAddressFamily *f = make_IPAddressFamily(addr, afi, safi); | ||
| 560 | if (f == NULL || | ||
| 561 | f->ipAddressChoice == NULL || | ||
| 562 | (f->ipAddressChoice->type == IPAddressChoice_addressesOrRanges && | ||
| 563 | f->ipAddressChoice->u.addressesOrRanges != NULL)) | ||
| 564 | return 0; | ||
| 565 | if (f->ipAddressChoice->type == IPAddressChoice_inherit && | ||
| 566 | f->ipAddressChoice->u.inherit != NULL) | ||
| 567 | return 1; | ||
| 568 | if (f->ipAddressChoice->u.inherit == NULL && | ||
| 569 | (f->ipAddressChoice->u.inherit = ASN1_NULL_new()) == NULL) | ||
| 570 | return 0; | ||
| 571 | f->ipAddressChoice->type = IPAddressChoice_inherit; | ||
| 572 | return 1; | ||
| 573 | } | ||
| 574 | |||
| 575 | /* | ||
| 576 | * Construct an IPAddressOrRange sequence, or return an existing one. | ||
| 577 | */ | ||
| 578 | static IPAddressOrRanges *make_prefix_or_range(IPAddrBlocks *addr, | ||
| 579 | const unsigned afi, | ||
| 580 | const unsigned *safi) | ||
| 581 | { | ||
| 582 | IPAddressFamily *f = make_IPAddressFamily(addr, afi, safi); | ||
| 583 | IPAddressOrRanges *aors = NULL; | ||
| 584 | |||
| 585 | if (f == NULL || | ||
| 586 | f->ipAddressChoice == NULL || | ||
| 587 | (f->ipAddressChoice->type == IPAddressChoice_inherit && | ||
| 588 | f->ipAddressChoice->u.inherit != NULL)) | ||
| 589 | return NULL; | ||
| 590 | if (f->ipAddressChoice->type == IPAddressChoice_addressesOrRanges) | ||
| 591 | aors = f->ipAddressChoice->u.addressesOrRanges; | ||
| 592 | if (aors != NULL) | ||
| 593 | return aors; | ||
| 594 | if ((aors = sk_IPAddressOrRange_new_null()) == NULL) | ||
| 595 | return NULL; | ||
| 596 | switch (afi) { | ||
| 597 | case IANA_AFI_IPV4: | ||
| 598 | sk_IPAddressOrRange_set_cmp_func(aors, v4IPAddressOrRange_cmp); | ||
| 599 | break; | ||
| 600 | case IANA_AFI_IPV6: | ||
| 601 | sk_IPAddressOrRange_set_cmp_func(aors, v6IPAddressOrRange_cmp); | ||
| 602 | break; | ||
| 603 | } | ||
| 604 | f->ipAddressChoice->type = IPAddressChoice_addressesOrRanges; | ||
| 605 | f->ipAddressChoice->u.addressesOrRanges = aors; | ||
| 606 | return aors; | ||
| 607 | } | ||
| 608 | |||
| 609 | /* | ||
| 610 | * Add a prefix. | ||
| 611 | */ | ||
| 612 | int v3_addr_add_prefix(IPAddrBlocks *addr, | ||
| 613 | const unsigned afi, | ||
| 614 | const unsigned *safi, | ||
| 615 | unsigned char *a, | ||
| 616 | const int prefixlen) | ||
| 617 | { | ||
| 618 | IPAddressOrRanges *aors = make_prefix_or_range(addr, afi, safi); | ||
| 619 | IPAddressOrRange *aor; | ||
| 620 | if (aors == NULL || !make_addressPrefix(&aor, a, prefixlen)) | ||
| 621 | return 0; | ||
| 622 | if (sk_IPAddressOrRange_push(aors, aor)) | ||
| 623 | return 1; | ||
| 624 | IPAddressOrRange_free(aor); | ||
| 625 | return 0; | ||
| 626 | } | ||
| 627 | |||
| 628 | /* | ||
| 629 | * Add a range. | ||
| 630 | */ | ||
| 631 | int v3_addr_add_range(IPAddrBlocks *addr, | ||
| 632 | const unsigned afi, | ||
| 633 | const unsigned *safi, | ||
| 634 | unsigned char *min, | ||
| 635 | unsigned char *max) | ||
| 636 | { | ||
| 637 | IPAddressOrRanges *aors = make_prefix_or_range(addr, afi, safi); | ||
| 638 | IPAddressOrRange *aor; | ||
| 639 | int length = length_from_afi(afi); | ||
| 640 | if (aors == NULL) | ||
| 641 | return 0; | ||
| 642 | if (!make_addressRange(&aor, min, max, length)) | ||
| 643 | return 0; | ||
| 644 | if (sk_IPAddressOrRange_push(aors, aor)) | ||
| 645 | return 1; | ||
| 646 | IPAddressOrRange_free(aor); | ||
| 647 | return 0; | ||
| 648 | } | ||
| 649 | |||
| 650 | /* | ||
| 651 | * Extract min and max values from an IPAddressOrRange. | ||
| 652 | */ | ||
| 653 | static void extract_min_max(IPAddressOrRange *aor, | ||
| 654 | unsigned char *min, | ||
| 655 | unsigned char *max, | ||
| 656 | int length) | ||
| 657 | { | ||
| 658 | OPENSSL_assert(aor != NULL && min != NULL && max != NULL); | ||
| 659 | switch (aor->type) { | ||
| 660 | case IPAddressOrRange_addressPrefix: | ||
| 661 | addr_expand(min, aor->u.addressPrefix, length, 0x00); | ||
| 662 | addr_expand(max, aor->u.addressPrefix, length, 0xFF); | ||
| 663 | return; | ||
| 664 | case IPAddressOrRange_addressRange: | ||
| 665 | addr_expand(min, aor->u.addressRange->min, length, 0x00); | ||
| 666 | addr_expand(max, aor->u.addressRange->max, length, 0xFF); | ||
| 667 | return; | ||
| 668 | } | ||
| 669 | } | ||
| 670 | |||
| 671 | /* | ||
| 672 | * Public wrapper for extract_min_max(). | ||
| 673 | */ | ||
| 674 | int v3_addr_get_range(IPAddressOrRange *aor, | ||
| 675 | const unsigned afi, | ||
| 676 | unsigned char *min, | ||
| 677 | unsigned char *max, | ||
| 678 | const int length) | ||
| 679 | { | ||
| 680 | int afi_length = length_from_afi(afi); | ||
| 681 | if (aor == NULL || min == NULL || max == NULL || | ||
| 682 | afi_length == 0 || length < afi_length || | ||
| 683 | (aor->type != IPAddressOrRange_addressPrefix && | ||
| 684 | aor->type != IPAddressOrRange_addressRange)) | ||
| 685 | return 0; | ||
| 686 | extract_min_max(aor, min, max, afi_length); | ||
| 687 | return afi_length; | ||
| 688 | } | ||
| 689 | |||
| 690 | /* | ||
| 691 | * Sort comparision function for a sequence of IPAddressFamily. | ||
| 692 | * | ||
| 693 | * The last paragraph of RFC 3779 2.2.3.3 is slightly ambiguous about | ||
| 694 | * the ordering: I can read it as meaning that IPv6 without a SAFI | ||
| 695 | * comes before IPv4 with a SAFI, which seems pretty weird. The | ||
| 696 | * examples in appendix B suggest that the author intended the | ||
| 697 | * null-SAFI rule to apply only within a single AFI, which is what I | ||
| 698 | * would have expected and is what the following code implements. | ||
| 699 | */ | ||
| 700 | static int IPAddressFamily_cmp(const IPAddressFamily * const *a_, | ||
| 701 | const IPAddressFamily * const *b_) | ||
| 702 | { | ||
| 703 | const ASN1_OCTET_STRING *a = (*a_)->addressFamily; | ||
| 704 | const ASN1_OCTET_STRING *b = (*b_)->addressFamily; | ||
| 705 | int len = ((a->length <= b->length) ? a->length : b->length); | ||
| 706 | int cmp = memcmp(a->data, b->data, len); | ||
| 707 | return cmp ? cmp : a->length - b->length; | ||
| 708 | } | ||
| 709 | |||
| 710 | /* | ||
| 711 | * Check whether an IPAddrBLocks is in canonical form. | ||
| 712 | */ | ||
| 713 | int v3_addr_is_canonical(IPAddrBlocks *addr) | ||
| 714 | { | ||
| 715 | unsigned char a_min[ADDR_RAW_BUF_LEN], a_max[ADDR_RAW_BUF_LEN]; | ||
| 716 | unsigned char b_min[ADDR_RAW_BUF_LEN], b_max[ADDR_RAW_BUF_LEN]; | ||
| 717 | IPAddressOrRanges *aors; | ||
| 718 | int i, j, k; | ||
| 719 | |||
| 720 | /* | ||
| 721 | * Empty extension is cannonical. | ||
| 722 | */ | ||
| 723 | if (addr == NULL) | ||
| 724 | return 1; | ||
| 725 | |||
| 726 | /* | ||
| 727 | * Check whether the top-level list is in order. | ||
| 728 | */ | ||
| 729 | for (i = 0; i < sk_IPAddressFamily_num(addr) - 1; i++) { | ||
| 730 | const IPAddressFamily *a = sk_IPAddressFamily_value(addr, i); | ||
| 731 | const IPAddressFamily *b = sk_IPAddressFamily_value(addr, i + 1); | ||
| 732 | if (IPAddressFamily_cmp(&a, &b) >= 0) | ||
| 733 | return 0; | ||
| 734 | } | ||
| 735 | |||
| 736 | /* | ||
| 737 | * Top level's ok, now check each address family. | ||
| 738 | */ | ||
| 739 | for (i = 0; i < sk_IPAddressFamily_num(addr); i++) { | ||
| 740 | IPAddressFamily *f = sk_IPAddressFamily_value(addr, i); | ||
| 741 | int length = length_from_afi(v3_addr_get_afi(f)); | ||
| 742 | |||
| 743 | /* | ||
| 744 | * Inheritance is canonical. Anything other than inheritance or | ||
| 745 | * a SEQUENCE OF IPAddressOrRange is an ASN.1 error or something. | ||
| 746 | */ | ||
| 747 | if (f == NULL || f->ipAddressChoice == NULL) | ||
| 748 | return 0; | ||
| 749 | switch (f->ipAddressChoice->type) { | ||
| 750 | case IPAddressChoice_inherit: | ||
| 751 | continue; | ||
| 752 | case IPAddressChoice_addressesOrRanges: | ||
| 753 | break; | ||
| 754 | default: | ||
| 755 | return 0; | ||
| 756 | } | ||
| 757 | |||
| 758 | /* | ||
| 759 | * It's an IPAddressOrRanges sequence, check it. | ||
| 760 | */ | ||
| 761 | aors = f->ipAddressChoice->u.addressesOrRanges; | ||
| 762 | if (sk_IPAddressOrRange_num(aors) == 0) | ||
| 763 | return 0; | ||
| 764 | for (j = 0; j < sk_IPAddressOrRange_num(aors) - 1; j++) { | ||
| 765 | IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, j); | ||
| 766 | IPAddressOrRange *b = sk_IPAddressOrRange_value(aors, j + 1); | ||
| 767 | |||
| 768 | extract_min_max(a, a_min, a_max, length); | ||
| 769 | extract_min_max(b, b_min, b_max, length); | ||
| 770 | |||
| 771 | /* | ||
| 772 | * Punt misordered list, overlapping start, or inverted range. | ||
| 773 | */ | ||
| 774 | if (memcmp(a_min, b_min, length) >= 0 || | ||
| 775 | memcmp(a_min, a_max, length) > 0 || | ||
| 776 | memcmp(b_min, b_max, length) > 0) | ||
| 777 | return 0; | ||
| 778 | |||
| 779 | /* | ||
| 780 | * Punt if adjacent or overlapping. Check for adjacency by | ||
| 781 | * subtracting one from b_min first. | ||
| 782 | */ | ||
| 783 | for (k = length - 1; k >= 0 && b_min[k]-- == 0x00; k--) | ||
| 784 | ; | ||
| 785 | if (memcmp(a_max, b_min, length) >= 0) | ||
| 786 | return 0; | ||
| 787 | |||
| 788 | /* | ||
| 789 | * Check for range that should be expressed as a prefix. | ||
| 790 | */ | ||
| 791 | if (a->type == IPAddressOrRange_addressRange && | ||
| 792 | range_should_be_prefix(a_min, a_max, length) >= 0) | ||
| 793 | return 0; | ||
| 794 | } | ||
| 795 | |||
| 796 | /* | ||
| 797 | * Check final range to see if it should be a prefix. | ||
| 798 | */ | ||
| 799 | j = sk_IPAddressOrRange_num(aors) - 1; | ||
| 800 | { | ||
| 801 | IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, j); | ||
| 802 | if (a->type == IPAddressOrRange_addressRange) { | ||
| 803 | extract_min_max(a, a_min, a_max, length); | ||
| 804 | if (range_should_be_prefix(a_min, a_max, length) >= 0) | ||
| 805 | return 0; | ||
| 806 | } | ||
| 807 | } | ||
| 808 | } | ||
| 809 | |||
| 810 | /* | ||
| 811 | * If we made it through all that, we're happy. | ||
| 812 | */ | ||
| 813 | return 1; | ||
| 814 | } | ||
| 815 | |||
| 816 | /* | ||
| 817 | * Whack an IPAddressOrRanges into canonical form. | ||
| 818 | */ | ||
| 819 | static int IPAddressOrRanges_canonize(IPAddressOrRanges *aors, | ||
| 820 | const unsigned afi) | ||
| 821 | { | ||
| 822 | int i, j, length = length_from_afi(afi); | ||
| 823 | |||
| 824 | /* | ||
| 825 | * Sort the IPAddressOrRanges sequence. | ||
| 826 | */ | ||
| 827 | sk_IPAddressOrRange_sort(aors); | ||
| 828 | |||
| 829 | /* | ||
| 830 | * Clean up representation issues, punt on duplicates or overlaps. | ||
| 831 | */ | ||
| 832 | for (i = 0; i < sk_IPAddressOrRange_num(aors) - 1; i++) { | ||
| 833 | IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, i); | ||
| 834 | IPAddressOrRange *b = sk_IPAddressOrRange_value(aors, i + 1); | ||
| 835 | unsigned char a_min[ADDR_RAW_BUF_LEN], a_max[ADDR_RAW_BUF_LEN]; | ||
| 836 | unsigned char b_min[ADDR_RAW_BUF_LEN], b_max[ADDR_RAW_BUF_LEN]; | ||
| 837 | |||
| 838 | extract_min_max(a, a_min, a_max, length); | ||
| 839 | extract_min_max(b, b_min, b_max, length); | ||
| 840 | |||
| 841 | /* | ||
| 842 | * Punt overlaps. | ||
| 843 | */ | ||
| 844 | if (memcmp(a_max, b_min, length) >= 0) | ||
| 845 | return 0; | ||
| 846 | |||
| 847 | /* | ||
| 848 | * Merge if a and b are adjacent. We check for | ||
| 849 | * adjacency by subtracting one from b_min first. | ||
| 850 | */ | ||
| 851 | for (j = length - 1; j >= 0 && b_min[j]-- == 0x00; j--) | ||
| 852 | ; | ||
| 853 | if (memcmp(a_max, b_min, length) == 0) { | ||
| 854 | IPAddressOrRange *merged; | ||
| 855 | if (!make_addressRange(&merged, a_min, b_max, length)) | ||
| 856 | return 0; | ||
| 857 | sk_IPAddressOrRange_set(aors, i, merged); | ||
| 858 | sk_IPAddressOrRange_delete(aors, i + 1); | ||
| 859 | IPAddressOrRange_free(a); | ||
| 860 | IPAddressOrRange_free(b); | ||
| 861 | --i; | ||
| 862 | continue; | ||
| 863 | } | ||
| 864 | } | ||
| 865 | |||
| 866 | return 1; | ||
| 867 | } | ||
| 868 | |||
| 869 | /* | ||
| 870 | * Whack an IPAddrBlocks extension into canonical form. | ||
| 871 | */ | ||
| 872 | int v3_addr_canonize(IPAddrBlocks *addr) | ||
| 873 | { | ||
| 874 | int i; | ||
| 875 | for (i = 0; i < sk_IPAddressFamily_num(addr); i++) { | ||
| 876 | IPAddressFamily *f = sk_IPAddressFamily_value(addr, i); | ||
| 877 | if (f->ipAddressChoice->type == IPAddressChoice_addressesOrRanges && | ||
| 878 | !IPAddressOrRanges_canonize(f->ipAddressChoice->u.addressesOrRanges, | ||
| 879 | v3_addr_get_afi(f))) | ||
| 880 | return 0; | ||
| 881 | } | ||
| 882 | sk_IPAddressFamily_set_cmp_func(addr, IPAddressFamily_cmp); | ||
| 883 | sk_IPAddressFamily_sort(addr); | ||
| 884 | OPENSSL_assert(v3_addr_is_canonical(addr)); | ||
| 885 | return 1; | ||
| 886 | } | ||
| 887 | |||
| 888 | /* | ||
| 889 | * v2i handler for the IPAddrBlocks extension. | ||
| 890 | */ | ||
| 891 | static void *v2i_IPAddrBlocks(const struct v3_ext_method *method, | ||
| 892 | struct v3_ext_ctx *ctx, | ||
| 893 | STACK_OF(CONF_VALUE) *values) | ||
| 894 | { | ||
| 895 | static const char v4addr_chars[] = "0123456789."; | ||
| 896 | static const char v6addr_chars[] = "0123456789.:abcdefABCDEF"; | ||
| 897 | IPAddrBlocks *addr = NULL; | ||
| 898 | char *s = NULL, *t; | ||
| 899 | int i; | ||
| 900 | |||
| 901 | if ((addr = sk_IPAddressFamily_new(IPAddressFamily_cmp)) == NULL) { | ||
| 902 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE); | ||
| 903 | return NULL; | ||
| 904 | } | ||
| 905 | |||
| 906 | for (i = 0; i < sk_CONF_VALUE_num(values); i++) { | ||
| 907 | CONF_VALUE *val = sk_CONF_VALUE_value(values, i); | ||
| 908 | unsigned char min[ADDR_RAW_BUF_LEN], max[ADDR_RAW_BUF_LEN]; | ||
| 909 | unsigned afi, *safi = NULL, safi_; | ||
| 910 | const char *addr_chars; | ||
| 911 | int prefixlen, i1, i2, delim, length; | ||
| 912 | |||
| 913 | if ( !name_cmp(val->name, "IPv4")) { | ||
| 914 | afi = IANA_AFI_IPV4; | ||
| 915 | } else if (!name_cmp(val->name, "IPv6")) { | ||
| 916 | afi = IANA_AFI_IPV6; | ||
| 917 | } else if (!name_cmp(val->name, "IPv4-SAFI")) { | ||
| 918 | afi = IANA_AFI_IPV4; | ||
| 919 | safi = &safi_; | ||
| 920 | } else if (!name_cmp(val->name, "IPv6-SAFI")) { | ||
| 921 | afi = IANA_AFI_IPV6; | ||
| 922 | safi = &safi_; | ||
| 923 | } else { | ||
| 924 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_NAME_ERROR); | ||
| 925 | X509V3_conf_err(val); | ||
| 926 | goto err; | ||
| 927 | } | ||
| 928 | |||
| 929 | switch (afi) { | ||
| 930 | case IANA_AFI_IPV4: | ||
| 931 | addr_chars = v4addr_chars; | ||
| 932 | break; | ||
| 933 | case IANA_AFI_IPV6: | ||
| 934 | addr_chars = v6addr_chars; | ||
| 935 | break; | ||
| 936 | } | ||
| 937 | |||
| 938 | length = length_from_afi(afi); | ||
| 939 | |||
| 940 | /* | ||
| 941 | * Handle SAFI, if any, and BUF_strdup() so we can null-terminate | ||
| 942 | * the other input values. | ||
| 943 | */ | ||
| 944 | if (safi != NULL) { | ||
| 945 | *safi = strtoul(val->value, &t, 0); | ||
| 946 | t += strspn(t, " \t"); | ||
| 947 | if (*safi > 0xFF || *t++ != ':') { | ||
| 948 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_SAFI); | ||
| 949 | X509V3_conf_err(val); | ||
| 950 | goto err; | ||
| 951 | } | ||
| 952 | t += strspn(t, " \t"); | ||
| 953 | s = BUF_strdup(t); | ||
| 954 | } else { | ||
| 955 | s = BUF_strdup(val->value); | ||
| 956 | } | ||
| 957 | if (s == NULL) { | ||
| 958 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE); | ||
| 959 | goto err; | ||
| 960 | } | ||
| 961 | |||
| 962 | /* | ||
| 963 | * Check for inheritance. Not worth additional complexity to | ||
| 964 | * optimize this (seldom-used) case. | ||
| 965 | */ | ||
| 966 | if (!strcmp(s, "inherit")) { | ||
| 967 | if (!v3_addr_add_inherit(addr, afi, safi)) { | ||
| 968 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_INHERITANCE); | ||
| 969 | X509V3_conf_err(val); | ||
| 970 | goto err; | ||
| 971 | } | ||
| 972 | OPENSSL_free(s); | ||
| 973 | s = NULL; | ||
| 974 | continue; | ||
| 975 | } | ||
| 976 | |||
| 977 | i1 = strspn(s, addr_chars); | ||
| 978 | i2 = i1 + strspn(s + i1, " \t"); | ||
| 979 | delim = s[i2++]; | ||
| 980 | s[i1] = '\0'; | ||
| 981 | |||
| 982 | if (a2i_ipadd(min, s) != length) { | ||
| 983 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_IPADDRESS); | ||
| 984 | X509V3_conf_err(val); | ||
| 985 | goto err; | ||
| 986 | } | ||
| 987 | |||
| 988 | switch (delim) { | ||
| 989 | case '/': | ||
| 990 | prefixlen = (int) strtoul(s + i2, &t, 10); | ||
| 991 | if (t == s + i2 || *t != '\0') { | ||
| 992 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_VALUE_ERROR); | ||
| 993 | X509V3_conf_err(val); | ||
| 994 | goto err; | ||
| 995 | } | ||
| 996 | if (!v3_addr_add_prefix(addr, afi, safi, min, prefixlen)) { | ||
| 997 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE); | ||
| 998 | goto err; | ||
| 999 | } | ||
| 1000 | break; | ||
| 1001 | case '-': | ||
| 1002 | i1 = i2 + strspn(s + i2, " \t"); | ||
| 1003 | i2 = i1 + strspn(s + i1, addr_chars); | ||
| 1004 | if (i1 == i2 || s[i2] != '\0') { | ||
| 1005 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_VALUE_ERROR); | ||
| 1006 | X509V3_conf_err(val); | ||
| 1007 | goto err; | ||
| 1008 | } | ||
| 1009 | if (a2i_ipadd(max, s + i1) != length) { | ||
| 1010 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_IPADDRESS); | ||
| 1011 | X509V3_conf_err(val); | ||
| 1012 | goto err; | ||
| 1013 | } | ||
| 1014 | if (!v3_addr_add_range(addr, afi, safi, min, max)) { | ||
| 1015 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE); | ||
| 1016 | goto err; | ||
| 1017 | } | ||
| 1018 | break; | ||
| 1019 | case '\0': | ||
| 1020 | if (!v3_addr_add_prefix(addr, afi, safi, min, length * 8)) { | ||
| 1021 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE); | ||
| 1022 | goto err; | ||
| 1023 | } | ||
| 1024 | break; | ||
| 1025 | default: | ||
| 1026 | X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_VALUE_ERROR); | ||
| 1027 | X509V3_conf_err(val); | ||
| 1028 | goto err; | ||
| 1029 | } | ||
| 1030 | |||
| 1031 | OPENSSL_free(s); | ||
| 1032 | s = NULL; | ||
| 1033 | } | ||
| 1034 | |||
| 1035 | /* | ||
| 1036 | * Canonize the result, then we're done. | ||
| 1037 | */ | ||
| 1038 | if (!v3_addr_canonize(addr)) | ||
| 1039 | goto err; | ||
| 1040 | return addr; | ||
| 1041 | |||
| 1042 | err: | ||
| 1043 | OPENSSL_free(s); | ||
| 1044 | sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free); | ||
| 1045 | return NULL; | ||
| 1046 | } | ||
| 1047 | |||
| 1048 | /* | ||
| 1049 | * OpenSSL dispatch | ||
| 1050 | */ | ||
| 1051 | const X509V3_EXT_METHOD v3_addr = { | ||
| 1052 | NID_sbgp_ipAddrBlock, /* nid */ | ||
| 1053 | 0, /* flags */ | ||
| 1054 | ASN1_ITEM_ref(IPAddrBlocks), /* template */ | ||
| 1055 | 0, 0, 0, 0, /* old functions, ignored */ | ||
| 1056 | 0, /* i2s */ | ||
| 1057 | 0, /* s2i */ | ||
| 1058 | 0, /* i2v */ | ||
| 1059 | v2i_IPAddrBlocks, /* v2i */ | ||
| 1060 | i2r_IPAddrBlocks, /* i2r */ | ||
| 1061 | 0, /* r2i */ | ||
| 1062 | NULL /* extension-specific data */ | ||
| 1063 | }; | ||
| 1064 | |||
| 1065 | /* | ||
| 1066 | * Figure out whether extension sues inheritance. | ||
| 1067 | */ | ||
| 1068 | int v3_addr_inherits(IPAddrBlocks *addr) | ||
| 1069 | { | ||
| 1070 | int i; | ||
| 1071 | if (addr == NULL) | ||
| 1072 | return 0; | ||
| 1073 | for (i = 0; i < sk_IPAddressFamily_num(addr); i++) { | ||
| 1074 | IPAddressFamily *f = sk_IPAddressFamily_value(addr, i); | ||
| 1075 | if (f->ipAddressChoice->type == IPAddressChoice_inherit) | ||
| 1076 | return 1; | ||
| 1077 | } | ||
| 1078 | return 0; | ||
| 1079 | } | ||
| 1080 | |||
| 1081 | /* | ||
| 1082 | * Figure out whether parent contains child. | ||
| 1083 | */ | ||
| 1084 | static int addr_contains(IPAddressOrRanges *parent, | ||
| 1085 | IPAddressOrRanges *child, | ||
| 1086 | int length) | ||
| 1087 | { | ||
| 1088 | unsigned char p_min[ADDR_RAW_BUF_LEN], p_max[ADDR_RAW_BUF_LEN]; | ||
| 1089 | unsigned char c_min[ADDR_RAW_BUF_LEN], c_max[ADDR_RAW_BUF_LEN]; | ||
| 1090 | int p, c; | ||
| 1091 | |||
| 1092 | if (child == NULL || parent == child) | ||
| 1093 | return 1; | ||
| 1094 | if (parent == NULL) | ||
| 1095 | return 0; | ||
| 1096 | |||
| 1097 | p = 0; | ||
| 1098 | for (c = 0; c < sk_IPAddressOrRange_num(child); c++) { | ||
| 1099 | extract_min_max(sk_IPAddressOrRange_value(child, c), | ||
| 1100 | c_min, c_max, length); | ||
| 1101 | for (;; p++) { | ||
| 1102 | if (p >= sk_IPAddressOrRange_num(parent)) | ||
| 1103 | return 0; | ||
| 1104 | extract_min_max(sk_IPAddressOrRange_value(parent, p), | ||
| 1105 | p_min, p_max, length); | ||
| 1106 | if (memcmp(p_max, c_max, length) < 0) | ||
| 1107 | continue; | ||
| 1108 | if (memcmp(p_min, c_min, length) > 0) | ||
| 1109 | return 0; | ||
| 1110 | break; | ||
| 1111 | } | ||
| 1112 | } | ||
| 1113 | |||
| 1114 | return 1; | ||
| 1115 | } | ||
| 1116 | |||
| 1117 | /* | ||
| 1118 | * Test whether a is a subset of b. | ||
| 1119 | */ | ||
| 1120 | int v3_addr_subset(IPAddrBlocks *a, IPAddrBlocks *b) | ||
| 1121 | { | ||
| 1122 | int i; | ||
| 1123 | if (a == NULL || a == b) | ||
| 1124 | return 1; | ||
| 1125 | if (b == NULL || v3_addr_inherits(a) || v3_addr_inherits(b)) | ||
| 1126 | return 0; | ||
| 1127 | sk_IPAddressFamily_set_cmp_func(b, IPAddressFamily_cmp); | ||
| 1128 | for (i = 0; i < sk_IPAddressFamily_num(a); i++) { | ||
| 1129 | IPAddressFamily *fa = sk_IPAddressFamily_value(a, i); | ||
| 1130 | int j = sk_IPAddressFamily_find(b, fa); | ||
| 1131 | IPAddressFamily *fb; | ||
| 1132 | fb = sk_IPAddressFamily_value(b, j); | ||
| 1133 | if (fb == NULL) | ||
| 1134 | return 0; | ||
| 1135 | if (!addr_contains(fb->ipAddressChoice->u.addressesOrRanges, | ||
| 1136 | fa->ipAddressChoice->u.addressesOrRanges, | ||
| 1137 | length_from_afi(v3_addr_get_afi(fb)))) | ||
| 1138 | return 0; | ||
| 1139 | } | ||
| 1140 | return 1; | ||
| 1141 | } | ||
| 1142 | |||
| 1143 | /* | ||
| 1144 | * Validation error handling via callback. | ||
| 1145 | */ | ||
| 1146 | #define validation_err(_err_) \ | ||
| 1147 | do { \ | ||
| 1148 | if (ctx != NULL) { \ | ||
| 1149 | ctx->error = _err_; \ | ||
| 1150 | ctx->error_depth = i; \ | ||
| 1151 | ctx->current_cert = x; \ | ||
| 1152 | ret = ctx->verify_cb(0, ctx); \ | ||
| 1153 | } else { \ | ||
| 1154 | ret = 0; \ | ||
| 1155 | } \ | ||
| 1156 | if (!ret) \ | ||
| 1157 | goto done; \ | ||
| 1158 | } while (0) | ||
| 1159 | |||
| 1160 | /* | ||
| 1161 | * Core code for RFC 3779 2.3 path validation. | ||
| 1162 | */ | ||
| 1163 | static int v3_addr_validate_path_internal(X509_STORE_CTX *ctx, | ||
| 1164 | STACK_OF(X509) *chain, | ||
| 1165 | IPAddrBlocks *ext) | ||
| 1166 | { | ||
| 1167 | IPAddrBlocks *child = NULL; | ||
| 1168 | int i, j, ret = 1; | ||
| 1169 | X509 *x; | ||
| 1170 | |||
| 1171 | OPENSSL_assert(chain != NULL && sk_X509_num(chain) > 0); | ||
| 1172 | OPENSSL_assert(ctx != NULL || ext != NULL); | ||
| 1173 | OPENSSL_assert(ctx == NULL || ctx->verify_cb != NULL); | ||
| 1174 | |||
| 1175 | /* | ||
| 1176 | * Figure out where to start. If we don't have an extension to | ||
| 1177 | * check, we're done. Otherwise, check canonical form and | ||
| 1178 | * set up for walking up the chain. | ||
| 1179 | */ | ||
| 1180 | if (ext != NULL) { | ||
| 1181 | i = -1; | ||
| 1182 | x = NULL; | ||
| 1183 | } else { | ||
| 1184 | i = 0; | ||
| 1185 | x = sk_X509_value(chain, i); | ||
| 1186 | OPENSSL_assert(x != NULL); | ||
| 1187 | if ((ext = x->rfc3779_addr) == NULL) | ||
| 1188 | goto done; | ||
| 1189 | } | ||
| 1190 | if (!v3_addr_is_canonical(ext)) | ||
| 1191 | validation_err(X509_V_ERR_INVALID_EXTENSION); | ||
| 1192 | sk_IPAddressFamily_set_cmp_func(ext, IPAddressFamily_cmp); | ||
| 1193 | if ((child = sk_IPAddressFamily_dup(ext)) == NULL) { | ||
| 1194 | X509V3err(X509V3_F_V3_ADDR_VALIDATE_PATH_INTERNAL, ERR_R_MALLOC_FAILURE); | ||
| 1195 | ret = 0; | ||
| 1196 | goto done; | ||
| 1197 | } | ||
| 1198 | |||
| 1199 | /* | ||
| 1200 | * Now walk up the chain. No cert may list resources that its | ||
| 1201 | * parent doesn't list. | ||
| 1202 | */ | ||
| 1203 | for (i++; i < sk_X509_num(chain); i++) { | ||
| 1204 | x = sk_X509_value(chain, i); | ||
| 1205 | OPENSSL_assert(x != NULL); | ||
| 1206 | if (!v3_addr_is_canonical(x->rfc3779_addr)) | ||
| 1207 | validation_err(X509_V_ERR_INVALID_EXTENSION); | ||
| 1208 | if (x->rfc3779_addr == NULL) { | ||
| 1209 | for (j = 0; j < sk_IPAddressFamily_num(child); j++) { | ||
| 1210 | IPAddressFamily *fc = sk_IPAddressFamily_value(child, j); | ||
| 1211 | if (fc->ipAddressChoice->type != IPAddressChoice_inherit) { | ||
| 1212 | validation_err(X509_V_ERR_UNNESTED_RESOURCE); | ||
| 1213 | break; | ||
| 1214 | } | ||
| 1215 | } | ||
| 1216 | continue; | ||
| 1217 | } | ||
| 1218 | sk_IPAddressFamily_set_cmp_func(x->rfc3779_addr, IPAddressFamily_cmp); | ||
| 1219 | for (j = 0; j < sk_IPAddressFamily_num(child); j++) { | ||
| 1220 | IPAddressFamily *fc = sk_IPAddressFamily_value(child, j); | ||
| 1221 | int k = sk_IPAddressFamily_find(x->rfc3779_addr, fc); | ||
| 1222 | IPAddressFamily *fp = sk_IPAddressFamily_value(x->rfc3779_addr, k); | ||
| 1223 | if (fp == NULL) { | ||
| 1224 | if (fc->ipAddressChoice->type == IPAddressChoice_addressesOrRanges) { | ||
| 1225 | validation_err(X509_V_ERR_UNNESTED_RESOURCE); | ||
| 1226 | break; | ||
| 1227 | } | ||
| 1228 | continue; | ||
| 1229 | } | ||
| 1230 | if (fp->ipAddressChoice->type == IPAddressChoice_addressesOrRanges) { | ||
| 1231 | if (fc->ipAddressChoice->type == IPAddressChoice_inherit || | ||
| 1232 | addr_contains(fp->ipAddressChoice->u.addressesOrRanges, | ||
| 1233 | fc->ipAddressChoice->u.addressesOrRanges, | ||
| 1234 | length_from_afi(v3_addr_get_afi(fc)))) | ||
| 1235 | sk_IPAddressFamily_set(child, j, fp); | ||
| 1236 | else | ||
| 1237 | validation_err(X509_V_ERR_UNNESTED_RESOURCE); | ||
| 1238 | } | ||
| 1239 | } | ||
| 1240 | } | ||
| 1241 | |||
| 1242 | /* | ||
| 1243 | * Trust anchor can't inherit. | ||
| 1244 | */ | ||
| 1245 | OPENSSL_assert(x != NULL); | ||
| 1246 | if (x->rfc3779_addr != NULL) { | ||
| 1247 | for (j = 0; j < sk_IPAddressFamily_num(x->rfc3779_addr); j++) { | ||
| 1248 | IPAddressFamily *fp = sk_IPAddressFamily_value(x->rfc3779_addr, j); | ||
| 1249 | if (fp->ipAddressChoice->type == IPAddressChoice_inherit && | ||
| 1250 | sk_IPAddressFamily_find(child, fp) >= 0) | ||
| 1251 | validation_err(X509_V_ERR_UNNESTED_RESOURCE); | ||
| 1252 | } | ||
| 1253 | } | ||
| 1254 | |||
| 1255 | done: | ||
| 1256 | sk_IPAddressFamily_free(child); | ||
| 1257 | return ret; | ||
| 1258 | } | ||
| 1259 | |||
| 1260 | #undef validation_err | ||
| 1261 | |||
| 1262 | /* | ||
| 1263 | * RFC 3779 2.3 path validation -- called from X509_verify_cert(). | ||
| 1264 | */ | ||
| 1265 | int v3_addr_validate_path(X509_STORE_CTX *ctx) | ||
| 1266 | { | ||
| 1267 | return v3_addr_validate_path_internal(ctx, ctx->chain, NULL); | ||
| 1268 | } | ||
| 1269 | |||
| 1270 | /* | ||
| 1271 | * RFC 3779 2.3 path validation of an extension. | ||
| 1272 | * Test whether chain covers extension. | ||
| 1273 | */ | ||
| 1274 | int v3_addr_validate_resource_set(STACK_OF(X509) *chain, | ||
| 1275 | IPAddrBlocks *ext, | ||
| 1276 | int allow_inheritance) | ||
| 1277 | { | ||
| 1278 | if (ext == NULL) | ||
| 1279 | return 1; | ||
| 1280 | if (chain == NULL || sk_X509_num(chain) == 0) | ||
| 1281 | return 0; | ||
| 1282 | if (!allow_inheritance && v3_addr_inherits(ext)) | ||
| 1283 | return 0; | ||
| 1284 | return v3_addr_validate_path_internal(NULL, chain, ext); | ||
| 1285 | } | ||
| 1286 | |||
| 1287 | #endif /* OPENSSL_NO_RFC3779 */ | ||
diff --git a/src/lib/libcrypto/x509v3/v3_asid.c b/src/lib/libcrypto/x509v3/v3_asid.c new file mode 100644 index 0000000000..56702f86b9 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_asid.c | |||
| @@ -0,0 +1,844 @@ | |||
| 1 | /* | ||
| 2 | * Contributed to the OpenSSL Project by the American Registry for | ||
| 3 | * Internet Numbers ("ARIN"). | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2006 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | */ | ||
| 57 | |||
| 58 | /* | ||
| 59 | * Implementation of RFC 3779 section 3.2. | ||
| 60 | */ | ||
| 61 | |||
| 62 | #include <stdio.h> | ||
| 63 | #include <string.h> | ||
| 64 | #include <assert.h> | ||
| 65 | #include "cryptlib.h" | ||
| 66 | #include <openssl/conf.h> | ||
| 67 | #include <openssl/asn1.h> | ||
| 68 | #include <openssl/asn1t.h> | ||
| 69 | #include <openssl/x509v3.h> | ||
| 70 | #include <openssl/x509.h> | ||
| 71 | #include <openssl/bn.h> | ||
| 72 | |||
| 73 | #ifndef OPENSSL_NO_RFC3779 | ||
| 74 | |||
| 75 | /* | ||
| 76 | * OpenSSL ASN.1 template translation of RFC 3779 3.2.3. | ||
| 77 | */ | ||
| 78 | |||
| 79 | ASN1_SEQUENCE(ASRange) = { | ||
| 80 | ASN1_SIMPLE(ASRange, min, ASN1_INTEGER), | ||
| 81 | ASN1_SIMPLE(ASRange, max, ASN1_INTEGER) | ||
| 82 | } ASN1_SEQUENCE_END(ASRange) | ||
| 83 | |||
| 84 | ASN1_CHOICE(ASIdOrRange) = { | ||
| 85 | ASN1_SIMPLE(ASIdOrRange, u.id, ASN1_INTEGER), | ||
| 86 | ASN1_SIMPLE(ASIdOrRange, u.range, ASRange) | ||
| 87 | } ASN1_CHOICE_END(ASIdOrRange) | ||
| 88 | |||
| 89 | ASN1_CHOICE(ASIdentifierChoice) = { | ||
| 90 | ASN1_SIMPLE(ASIdentifierChoice, u.inherit, ASN1_NULL), | ||
| 91 | ASN1_SEQUENCE_OF(ASIdentifierChoice, u.asIdsOrRanges, ASIdOrRange) | ||
| 92 | } ASN1_CHOICE_END(ASIdentifierChoice) | ||
| 93 | |||
| 94 | ASN1_SEQUENCE(ASIdentifiers) = { | ||
| 95 | ASN1_EXP_OPT(ASIdentifiers, asnum, ASIdentifierChoice, 0), | ||
| 96 | ASN1_EXP_OPT(ASIdentifiers, rdi, ASIdentifierChoice, 1) | ||
| 97 | } ASN1_SEQUENCE_END(ASIdentifiers) | ||
| 98 | |||
| 99 | IMPLEMENT_ASN1_FUNCTIONS(ASRange) | ||
| 100 | IMPLEMENT_ASN1_FUNCTIONS(ASIdOrRange) | ||
| 101 | IMPLEMENT_ASN1_FUNCTIONS(ASIdentifierChoice) | ||
| 102 | IMPLEMENT_ASN1_FUNCTIONS(ASIdentifiers) | ||
| 103 | |||
| 104 | /* | ||
| 105 | * i2r method for an ASIdentifierChoice. | ||
| 106 | */ | ||
| 107 | static int i2r_ASIdentifierChoice(BIO *out, | ||
| 108 | ASIdentifierChoice *choice, | ||
| 109 | int indent, | ||
| 110 | const char *msg) | ||
| 111 | { | ||
| 112 | int i; | ||
| 113 | char *s; | ||
| 114 | if (choice == NULL) | ||
| 115 | return 1; | ||
| 116 | BIO_printf(out, "%*s%s:\n", indent, "", msg); | ||
| 117 | switch (choice->type) { | ||
| 118 | case ASIdentifierChoice_inherit: | ||
| 119 | BIO_printf(out, "%*sinherit\n", indent + 2, ""); | ||
| 120 | break; | ||
| 121 | case ASIdentifierChoice_asIdsOrRanges: | ||
| 122 | for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges); i++) { | ||
| 123 | ASIdOrRange *aor = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i); | ||
| 124 | switch (aor->type) { | ||
| 125 | case ASIdOrRange_id: | ||
| 126 | if ((s = i2s_ASN1_INTEGER(NULL, aor->u.id)) == NULL) | ||
| 127 | return 0; | ||
| 128 | BIO_printf(out, "%*s%s\n", indent + 2, "", s); | ||
| 129 | OPENSSL_free(s); | ||
| 130 | break; | ||
| 131 | case ASIdOrRange_range: | ||
| 132 | if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->min)) == NULL) | ||
| 133 | return 0; | ||
| 134 | BIO_printf(out, "%*s%s-", indent + 2, "", s); | ||
| 135 | OPENSSL_free(s); | ||
| 136 | if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->max)) == NULL) | ||
| 137 | return 0; | ||
| 138 | BIO_printf(out, "%s\n", s); | ||
| 139 | OPENSSL_free(s); | ||
| 140 | break; | ||
| 141 | default: | ||
| 142 | return 0; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | break; | ||
| 146 | default: | ||
| 147 | return 0; | ||
| 148 | } | ||
| 149 | return 1; | ||
| 150 | } | ||
| 151 | |||
| 152 | /* | ||
| 153 | * i2r method for an ASIdentifier extension. | ||
| 154 | */ | ||
| 155 | static int i2r_ASIdentifiers(const X509V3_EXT_METHOD *method, | ||
| 156 | void *ext, | ||
| 157 | BIO *out, | ||
| 158 | int indent) | ||
| 159 | { | ||
| 160 | ASIdentifiers *asid = ext; | ||
| 161 | return (i2r_ASIdentifierChoice(out, asid->asnum, indent, | ||
| 162 | "Autonomous System Numbers") && | ||
| 163 | i2r_ASIdentifierChoice(out, asid->rdi, indent, | ||
| 164 | "Routing Domain Identifiers")); | ||
| 165 | } | ||
| 166 | |||
| 167 | /* | ||
| 168 | * Sort comparision function for a sequence of ASIdOrRange elements. | ||
| 169 | */ | ||
| 170 | static int ASIdOrRange_cmp(const ASIdOrRange * const *a_, | ||
| 171 | const ASIdOrRange * const *b_) | ||
| 172 | { | ||
| 173 | const ASIdOrRange *a = *a_, *b = *b_; | ||
| 174 | |||
| 175 | assert((a->type == ASIdOrRange_id && a->u.id != NULL) || | ||
| 176 | (a->type == ASIdOrRange_range && a->u.range != NULL && | ||
| 177 | a->u.range->min != NULL && a->u.range->max != NULL)); | ||
| 178 | |||
| 179 | assert((b->type == ASIdOrRange_id && b->u.id != NULL) || | ||
| 180 | (b->type == ASIdOrRange_range && b->u.range != NULL && | ||
| 181 | b->u.range->min != NULL && b->u.range->max != NULL)); | ||
| 182 | |||
| 183 | if (a->type == ASIdOrRange_id && b->type == ASIdOrRange_id) | ||
| 184 | return ASN1_INTEGER_cmp(a->u.id, b->u.id); | ||
| 185 | |||
| 186 | if (a->type == ASIdOrRange_range && b->type == ASIdOrRange_range) { | ||
| 187 | int r = ASN1_INTEGER_cmp(a->u.range->min, b->u.range->min); | ||
| 188 | return r != 0 ? r : ASN1_INTEGER_cmp(a->u.range->max, b->u.range->max); | ||
| 189 | } | ||
| 190 | |||
| 191 | if (a->type == ASIdOrRange_id) | ||
| 192 | return ASN1_INTEGER_cmp(a->u.id, b->u.range->min); | ||
| 193 | else | ||
| 194 | return ASN1_INTEGER_cmp(a->u.range->min, b->u.id); | ||
| 195 | } | ||
| 196 | |||
| 197 | /* | ||
| 198 | * Add an inherit element. | ||
| 199 | */ | ||
| 200 | int v3_asid_add_inherit(ASIdentifiers *asid, int which) | ||
| 201 | { | ||
| 202 | ASIdentifierChoice **choice; | ||
| 203 | if (asid == NULL) | ||
| 204 | return 0; | ||
| 205 | switch (which) { | ||
| 206 | case V3_ASID_ASNUM: | ||
| 207 | choice = &asid->asnum; | ||
| 208 | break; | ||
| 209 | case V3_ASID_RDI: | ||
| 210 | choice = &asid->rdi; | ||
| 211 | break; | ||
| 212 | default: | ||
| 213 | return 0; | ||
| 214 | } | ||
| 215 | if (*choice == NULL) { | ||
| 216 | if ((*choice = ASIdentifierChoice_new()) == NULL) | ||
| 217 | return 0; | ||
| 218 | assert((*choice)->u.inherit == NULL); | ||
| 219 | if (((*choice)->u.inherit = ASN1_NULL_new()) == NULL) | ||
| 220 | return 0; | ||
| 221 | (*choice)->type = ASIdentifierChoice_inherit; | ||
| 222 | } | ||
| 223 | return (*choice)->type == ASIdentifierChoice_inherit; | ||
| 224 | } | ||
| 225 | |||
| 226 | /* | ||
| 227 | * Add an ID or range to an ASIdentifierChoice. | ||
| 228 | */ | ||
| 229 | int v3_asid_add_id_or_range(ASIdentifiers *asid, | ||
| 230 | int which, | ||
| 231 | ASN1_INTEGER *min, | ||
| 232 | ASN1_INTEGER *max) | ||
| 233 | { | ||
| 234 | ASIdentifierChoice **choice; | ||
| 235 | ASIdOrRange *aor; | ||
| 236 | if (asid == NULL) | ||
| 237 | return 0; | ||
| 238 | switch (which) { | ||
| 239 | case V3_ASID_ASNUM: | ||
| 240 | choice = &asid->asnum; | ||
| 241 | break; | ||
| 242 | case V3_ASID_RDI: | ||
| 243 | choice = &asid->rdi; | ||
| 244 | break; | ||
| 245 | default: | ||
| 246 | return 0; | ||
| 247 | } | ||
| 248 | if (*choice != NULL && (*choice)->type == ASIdentifierChoice_inherit) | ||
| 249 | return 0; | ||
| 250 | if (*choice == NULL) { | ||
| 251 | if ((*choice = ASIdentifierChoice_new()) == NULL) | ||
| 252 | return 0; | ||
| 253 | assert((*choice)->u.asIdsOrRanges == NULL); | ||
| 254 | (*choice)->u.asIdsOrRanges = sk_ASIdOrRange_new(ASIdOrRange_cmp); | ||
| 255 | if ((*choice)->u.asIdsOrRanges == NULL) | ||
| 256 | return 0; | ||
| 257 | (*choice)->type = ASIdentifierChoice_asIdsOrRanges; | ||
| 258 | } | ||
| 259 | if ((aor = ASIdOrRange_new()) == NULL) | ||
| 260 | return 0; | ||
| 261 | if (max == NULL) { | ||
| 262 | aor->type = ASIdOrRange_id; | ||
| 263 | aor->u.id = min; | ||
| 264 | } else { | ||
| 265 | aor->type = ASIdOrRange_range; | ||
| 266 | if ((aor->u.range = ASRange_new()) == NULL) | ||
| 267 | goto err; | ||
| 268 | ASN1_INTEGER_free(aor->u.range->min); | ||
| 269 | aor->u.range->min = min; | ||
| 270 | ASN1_INTEGER_free(aor->u.range->max); | ||
| 271 | aor->u.range->max = max; | ||
| 272 | } | ||
| 273 | if (!(sk_ASIdOrRange_push((*choice)->u.asIdsOrRanges, aor))) | ||
| 274 | goto err; | ||
| 275 | return 1; | ||
| 276 | |||
| 277 | err: | ||
| 278 | ASIdOrRange_free(aor); | ||
| 279 | return 0; | ||
| 280 | } | ||
| 281 | |||
| 282 | /* | ||
| 283 | * Extract min and max values from an ASIdOrRange. | ||
| 284 | */ | ||
| 285 | static void extract_min_max(ASIdOrRange *aor, | ||
| 286 | ASN1_INTEGER **min, | ||
| 287 | ASN1_INTEGER **max) | ||
| 288 | { | ||
| 289 | assert(aor != NULL && min != NULL && max != NULL); | ||
| 290 | switch (aor->type) { | ||
| 291 | case ASIdOrRange_id: | ||
| 292 | *min = aor->u.id; | ||
| 293 | *max = aor->u.id; | ||
| 294 | return; | ||
| 295 | case ASIdOrRange_range: | ||
| 296 | *min = aor->u.range->min; | ||
| 297 | *max = aor->u.range->max; | ||
| 298 | return; | ||
| 299 | } | ||
| 300 | } | ||
| 301 | |||
| 302 | /* | ||
| 303 | * Check whether an ASIdentifierChoice is in canonical form. | ||
| 304 | */ | ||
| 305 | static int ASIdentifierChoice_is_canonical(ASIdentifierChoice *choice) | ||
| 306 | { | ||
| 307 | ASN1_INTEGER *a_max_plus_one = NULL; | ||
| 308 | BIGNUM *bn = NULL; | ||
| 309 | int i, ret = 0; | ||
| 310 | |||
| 311 | /* | ||
| 312 | * Empty element or inheritance is canonical. | ||
| 313 | */ | ||
| 314 | if (choice == NULL || choice->type == ASIdentifierChoice_inherit) | ||
| 315 | return 1; | ||
| 316 | |||
| 317 | /* | ||
| 318 | * If not a list, or if empty list, it's broken. | ||
| 319 | */ | ||
| 320 | if (choice->type != ASIdentifierChoice_asIdsOrRanges || | ||
| 321 | sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0) | ||
| 322 | return 0; | ||
| 323 | |||
| 324 | /* | ||
| 325 | * It's a list, check it. | ||
| 326 | */ | ||
| 327 | for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) { | ||
| 328 | ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i); | ||
| 329 | ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1); | ||
| 330 | ASN1_INTEGER *a_min, *a_max, *b_min, *b_max; | ||
| 331 | |||
| 332 | extract_min_max(a, &a_min, &a_max); | ||
| 333 | extract_min_max(b, &b_min, &b_max); | ||
| 334 | |||
| 335 | /* | ||
| 336 | * Punt misordered list, overlapping start, or inverted range. | ||
| 337 | */ | ||
| 338 | if (ASN1_INTEGER_cmp(a_min, b_min) >= 0 || | ||
| 339 | ASN1_INTEGER_cmp(a_min, a_max) > 0 || | ||
| 340 | ASN1_INTEGER_cmp(b_min, b_max) > 0) | ||
| 341 | goto done; | ||
| 342 | |||
| 343 | /* | ||
| 344 | * Calculate a_max + 1 to check for adjacency. | ||
| 345 | */ | ||
| 346 | if ((bn == NULL && (bn = BN_new()) == NULL) || | ||
| 347 | ASN1_INTEGER_to_BN(a_max, bn) == NULL || | ||
| 348 | !BN_add_word(bn, 1) || | ||
| 349 | (a_max_plus_one = BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) { | ||
| 350 | X509V3err(X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL, | ||
| 351 | ERR_R_MALLOC_FAILURE); | ||
| 352 | goto done; | ||
| 353 | } | ||
| 354 | |||
| 355 | /* | ||
| 356 | * Punt if adjacent or overlapping. | ||
| 357 | */ | ||
| 358 | if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) >= 0) | ||
| 359 | goto done; | ||
| 360 | } | ||
| 361 | |||
| 362 | ret = 1; | ||
| 363 | |||
| 364 | done: | ||
| 365 | ASN1_INTEGER_free(a_max_plus_one); | ||
| 366 | BN_free(bn); | ||
| 367 | return ret; | ||
| 368 | } | ||
| 369 | |||
| 370 | /* | ||
| 371 | * Check whether an ASIdentifier extension is in canonical form. | ||
| 372 | */ | ||
| 373 | int v3_asid_is_canonical(ASIdentifiers *asid) | ||
| 374 | { | ||
| 375 | return (asid == NULL || | ||
| 376 | (ASIdentifierChoice_is_canonical(asid->asnum) || | ||
| 377 | ASIdentifierChoice_is_canonical(asid->rdi))); | ||
| 378 | } | ||
| 379 | |||
| 380 | /* | ||
| 381 | * Whack an ASIdentifierChoice into canonical form. | ||
| 382 | */ | ||
| 383 | static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice) | ||
| 384 | { | ||
| 385 | ASN1_INTEGER *a_max_plus_one = NULL; | ||
| 386 | BIGNUM *bn = NULL; | ||
| 387 | int i, ret = 0; | ||
| 388 | |||
| 389 | /* | ||
| 390 | * Nothing to do for empty element or inheritance. | ||
| 391 | */ | ||
| 392 | if (choice == NULL || choice->type == ASIdentifierChoice_inherit) | ||
| 393 | return 1; | ||
| 394 | |||
| 395 | /* | ||
| 396 | * We have a list. Sort it. | ||
| 397 | */ | ||
| 398 | assert(choice->type == ASIdentifierChoice_asIdsOrRanges); | ||
| 399 | sk_ASIdOrRange_sort(choice->u.asIdsOrRanges); | ||
| 400 | |||
| 401 | /* | ||
| 402 | * Now check for errors and suboptimal encoding, rejecting the | ||
| 403 | * former and fixing the latter. | ||
| 404 | */ | ||
| 405 | for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) { | ||
| 406 | ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i); | ||
| 407 | ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1); | ||
| 408 | ASN1_INTEGER *a_min, *a_max, *b_min, *b_max; | ||
| 409 | |||
| 410 | extract_min_max(a, &a_min, &a_max); | ||
| 411 | extract_min_max(b, &b_min, &b_max); | ||
| 412 | |||
| 413 | /* | ||
| 414 | * Make sure we're properly sorted (paranoia). | ||
| 415 | */ | ||
| 416 | assert(ASN1_INTEGER_cmp(a_min, b_min) <= 0); | ||
| 417 | |||
| 418 | /* | ||
| 419 | * Check for overlaps. | ||
| 420 | */ | ||
| 421 | if (ASN1_INTEGER_cmp(a_max, b_min) >= 0) { | ||
| 422 | X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE, | ||
| 423 | X509V3_R_EXTENSION_VALUE_ERROR); | ||
| 424 | goto done; | ||
| 425 | } | ||
| 426 | |||
| 427 | /* | ||
| 428 | * Calculate a_max + 1 to check for adjacency. | ||
| 429 | */ | ||
| 430 | if ((bn == NULL && (bn = BN_new()) == NULL) || | ||
| 431 | ASN1_INTEGER_to_BN(a_max, bn) == NULL || | ||
| 432 | !BN_add_word(bn, 1) || | ||
| 433 | (a_max_plus_one = BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) { | ||
| 434 | X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE, ERR_R_MALLOC_FAILURE); | ||
| 435 | goto done; | ||
| 436 | } | ||
| 437 | |||
| 438 | /* | ||
| 439 | * If a and b are adjacent, merge them. | ||
| 440 | */ | ||
| 441 | if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) == 0) { | ||
| 442 | ASRange *r; | ||
| 443 | switch (a->type) { | ||
| 444 | case ASIdOrRange_id: | ||
| 445 | if ((r = OPENSSL_malloc(sizeof(ASRange))) == NULL) { | ||
| 446 | X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE, | ||
| 447 | ERR_R_MALLOC_FAILURE); | ||
| 448 | goto done; | ||
| 449 | } | ||
| 450 | r->min = a_min; | ||
| 451 | r->max = b_max; | ||
| 452 | a->type = ASIdOrRange_range; | ||
| 453 | a->u.range = r; | ||
| 454 | break; | ||
| 455 | case ASIdOrRange_range: | ||
| 456 | ASN1_INTEGER_free(a->u.range->max); | ||
| 457 | a->u.range->max = b_max; | ||
| 458 | break; | ||
| 459 | } | ||
| 460 | switch (b->type) { | ||
| 461 | case ASIdOrRange_id: | ||
| 462 | b->u.id = NULL; | ||
| 463 | break; | ||
| 464 | case ASIdOrRange_range: | ||
| 465 | b->u.range->max = NULL; | ||
| 466 | break; | ||
| 467 | } | ||
| 468 | ASIdOrRange_free(b); | ||
| 469 | sk_ASIdOrRange_delete(choice->u.asIdsOrRanges, i + 1); | ||
| 470 | i--; | ||
| 471 | continue; | ||
| 472 | } | ||
| 473 | } | ||
| 474 | |||
| 475 | assert(ASIdentifierChoice_is_canonical(choice)); /* Paranoia */ | ||
| 476 | |||
| 477 | ret = 1; | ||
| 478 | |||
| 479 | done: | ||
| 480 | ASN1_INTEGER_free(a_max_plus_one); | ||
| 481 | BN_free(bn); | ||
| 482 | return ret; | ||
| 483 | } | ||
| 484 | |||
| 485 | /* | ||
| 486 | * Whack an ASIdentifier extension into canonical form. | ||
| 487 | */ | ||
| 488 | int v3_asid_canonize(ASIdentifiers *asid) | ||
| 489 | { | ||
| 490 | return (asid == NULL || | ||
| 491 | (ASIdentifierChoice_canonize(asid->asnum) && | ||
| 492 | ASIdentifierChoice_canonize(asid->rdi))); | ||
| 493 | } | ||
| 494 | |||
| 495 | /* | ||
| 496 | * v2i method for an ASIdentifier extension. | ||
| 497 | */ | ||
| 498 | static void *v2i_ASIdentifiers(const struct v3_ext_method *method, | ||
| 499 | struct v3_ext_ctx *ctx, | ||
| 500 | STACK_OF(CONF_VALUE) *values) | ||
| 501 | { | ||
| 502 | ASIdentifiers *asid = NULL; | ||
| 503 | int i; | ||
| 504 | |||
| 505 | if ((asid = ASIdentifiers_new()) == NULL) { | ||
| 506 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE); | ||
| 507 | return NULL; | ||
| 508 | } | ||
| 509 | |||
| 510 | for (i = 0; i < sk_CONF_VALUE_num(values); i++) { | ||
| 511 | CONF_VALUE *val = sk_CONF_VALUE_value(values, i); | ||
| 512 | ASN1_INTEGER *min = NULL, *max = NULL; | ||
| 513 | int i1, i2, i3, is_range, which; | ||
| 514 | |||
| 515 | /* | ||
| 516 | * Figure out whether this is an AS or an RDI. | ||
| 517 | */ | ||
| 518 | if ( !name_cmp(val->name, "AS")) { | ||
| 519 | which = V3_ASID_ASNUM; | ||
| 520 | } else if (!name_cmp(val->name, "RDI")) { | ||
| 521 | which = V3_ASID_RDI; | ||
| 522 | } else { | ||
| 523 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, X509V3_R_EXTENSION_NAME_ERROR); | ||
| 524 | X509V3_conf_err(val); | ||
| 525 | goto err; | ||
| 526 | } | ||
| 527 | |||
| 528 | /* | ||
| 529 | * Handle inheritance. | ||
| 530 | */ | ||
| 531 | if (!strcmp(val->value, "inherit")) { | ||
| 532 | if (v3_asid_add_inherit(asid, which)) | ||
| 533 | continue; | ||
| 534 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, X509V3_R_INVALID_INHERITANCE); | ||
| 535 | X509V3_conf_err(val); | ||
| 536 | goto err; | ||
| 537 | } | ||
| 538 | |||
| 539 | /* | ||
| 540 | * Number, range, or mistake, pick it apart and figure out which. | ||
| 541 | */ | ||
| 542 | i1 = strspn(val->value, "0123456789"); | ||
| 543 | if (val->value[i1] == '\0') { | ||
| 544 | is_range = 0; | ||
| 545 | } else { | ||
| 546 | is_range = 1; | ||
| 547 | i2 = i1 + strspn(val->value + i1, " \t"); | ||
| 548 | if (val->value[i2] != '-') { | ||
| 549 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, X509V3_R_INVALID_ASNUMBER); | ||
| 550 | X509V3_conf_err(val); | ||
| 551 | goto err; | ||
| 552 | } | ||
| 553 | i2++; | ||
| 554 | i2 = i2 + strspn(val->value + i2, " \t"); | ||
| 555 | i3 = i2 + strspn(val->value + i2, "0123456789"); | ||
| 556 | if (val->value[i3] != '\0') { | ||
| 557 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, X509V3_R_INVALID_ASRANGE); | ||
| 558 | X509V3_conf_err(val); | ||
| 559 | goto err; | ||
| 560 | } | ||
| 561 | } | ||
| 562 | |||
| 563 | /* | ||
| 564 | * Syntax is ok, read and add it. | ||
| 565 | */ | ||
| 566 | if (!is_range) { | ||
| 567 | if (!X509V3_get_value_int(val, &min)) { | ||
| 568 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE); | ||
| 569 | goto err; | ||
| 570 | } | ||
| 571 | } else { | ||
| 572 | char *s = BUF_strdup(val->value); | ||
| 573 | if (s == NULL) { | ||
| 574 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE); | ||
| 575 | goto err; | ||
| 576 | } | ||
| 577 | s[i1] = '\0'; | ||
| 578 | min = s2i_ASN1_INTEGER(NULL, s); | ||
| 579 | max = s2i_ASN1_INTEGER(NULL, s + i2); | ||
| 580 | OPENSSL_free(s); | ||
| 581 | if (min == NULL || max == NULL) { | ||
| 582 | ASN1_INTEGER_free(min); | ||
| 583 | ASN1_INTEGER_free(max); | ||
| 584 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE); | ||
| 585 | goto err; | ||
| 586 | } | ||
| 587 | } | ||
| 588 | if (!v3_asid_add_id_or_range(asid, which, min, max)) { | ||
| 589 | ASN1_INTEGER_free(min); | ||
| 590 | ASN1_INTEGER_free(max); | ||
| 591 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE); | ||
| 592 | goto err; | ||
| 593 | } | ||
| 594 | } | ||
| 595 | |||
| 596 | /* | ||
| 597 | * Canonize the result, then we're done. | ||
| 598 | */ | ||
| 599 | if (!v3_asid_canonize(asid)) | ||
| 600 | goto err; | ||
| 601 | return asid; | ||
| 602 | |||
| 603 | err: | ||
| 604 | ASIdentifiers_free(asid); | ||
| 605 | return NULL; | ||
| 606 | } | ||
| 607 | |||
| 608 | /* | ||
| 609 | * OpenSSL dispatch. | ||
| 610 | */ | ||
| 611 | const X509V3_EXT_METHOD v3_asid = { | ||
| 612 | NID_sbgp_autonomousSysNum, /* nid */ | ||
| 613 | 0, /* flags */ | ||
| 614 | ASN1_ITEM_ref(ASIdentifiers), /* template */ | ||
| 615 | 0, 0, 0, 0, /* old functions, ignored */ | ||
| 616 | 0, /* i2s */ | ||
| 617 | 0, /* s2i */ | ||
| 618 | 0, /* i2v */ | ||
| 619 | v2i_ASIdentifiers, /* v2i */ | ||
| 620 | i2r_ASIdentifiers, /* i2r */ | ||
| 621 | 0, /* r2i */ | ||
| 622 | NULL /* extension-specific data */ | ||
| 623 | }; | ||
| 624 | |||
| 625 | /* | ||
| 626 | * Figure out whether extension uses inheritance. | ||
| 627 | */ | ||
| 628 | int v3_asid_inherits(ASIdentifiers *asid) | ||
| 629 | { | ||
| 630 | return (asid != NULL && | ||
| 631 | ((asid->asnum != NULL && | ||
| 632 | asid->asnum->type == ASIdentifierChoice_inherit) || | ||
| 633 | (asid->rdi != NULL && | ||
| 634 | asid->rdi->type == ASIdentifierChoice_inherit))); | ||
| 635 | } | ||
| 636 | |||
| 637 | /* | ||
| 638 | * Figure out whether parent contains child. | ||
| 639 | */ | ||
| 640 | static int asid_contains(ASIdOrRanges *parent, ASIdOrRanges *child) | ||
| 641 | { | ||
| 642 | ASN1_INTEGER *p_min, *p_max, *c_min, *c_max; | ||
| 643 | int p, c; | ||
| 644 | |||
| 645 | if (child == NULL || parent == child) | ||
| 646 | return 1; | ||
| 647 | if (parent == NULL) | ||
| 648 | return 0; | ||
| 649 | |||
| 650 | p = 0; | ||
| 651 | for (c = 0; c < sk_ASIdOrRange_num(child); c++) { | ||
| 652 | extract_min_max(sk_ASIdOrRange_value(child, c), &c_min, &c_max); | ||
| 653 | for (;; p++) { | ||
| 654 | if (p >= sk_ASIdOrRange_num(parent)) | ||
| 655 | return 0; | ||
| 656 | extract_min_max(sk_ASIdOrRange_value(parent, p), &p_min, &p_max); | ||
| 657 | if (ASN1_INTEGER_cmp(p_max, c_max) < 0) | ||
| 658 | continue; | ||
| 659 | if (ASN1_INTEGER_cmp(p_min, c_min) > 0) | ||
| 660 | return 0; | ||
| 661 | break; | ||
| 662 | } | ||
| 663 | } | ||
| 664 | |||
| 665 | return 1; | ||
| 666 | } | ||
| 667 | |||
| 668 | /* | ||
| 669 | * Test whether a is a subet of b. | ||
| 670 | */ | ||
| 671 | int v3_asid_subset(ASIdentifiers *a, ASIdentifiers *b) | ||
| 672 | { | ||
| 673 | return (a == NULL || | ||
| 674 | a == b || | ||
| 675 | (b != NULL && | ||
| 676 | !v3_asid_inherits(a) && | ||
| 677 | !v3_asid_inherits(b) && | ||
| 678 | asid_contains(b->asnum->u.asIdsOrRanges, | ||
| 679 | a->asnum->u.asIdsOrRanges) && | ||
| 680 | asid_contains(b->rdi->u.asIdsOrRanges, | ||
| 681 | a->rdi->u.asIdsOrRanges))); | ||
| 682 | } | ||
| 683 | |||
| 684 | /* | ||
| 685 | * Validation error handling via callback. | ||
| 686 | */ | ||
| 687 | #define validation_err(_err_) \ | ||
| 688 | do { \ | ||
| 689 | if (ctx != NULL) { \ | ||
| 690 | ctx->error = _err_; \ | ||
| 691 | ctx->error_depth = i; \ | ||
| 692 | ctx->current_cert = x; \ | ||
| 693 | ret = ctx->verify_cb(0, ctx); \ | ||
| 694 | } else { \ | ||
| 695 | ret = 0; \ | ||
| 696 | } \ | ||
| 697 | if (!ret) \ | ||
| 698 | goto done; \ | ||
| 699 | } while (0) | ||
| 700 | |||
| 701 | /* | ||
| 702 | * Core code for RFC 3779 3.3 path validation. | ||
| 703 | */ | ||
| 704 | static int v3_asid_validate_path_internal(X509_STORE_CTX *ctx, | ||
| 705 | STACK_OF(X509) *chain, | ||
| 706 | ASIdentifiers *ext) | ||
| 707 | { | ||
| 708 | ASIdOrRanges *child_as = NULL, *child_rdi = NULL; | ||
| 709 | int i, ret = 1, inherit_as = 0, inherit_rdi = 0; | ||
| 710 | X509 *x; | ||
| 711 | |||
| 712 | assert(chain != NULL && sk_X509_num(chain) > 0); | ||
| 713 | assert(ctx != NULL || ext != NULL); | ||
| 714 | assert(ctx == NULL || ctx->verify_cb != NULL); | ||
| 715 | |||
| 716 | /* | ||
| 717 | * Figure out where to start. If we don't have an extension to | ||
| 718 | * check, we're done. Otherwise, check canonical form and | ||
| 719 | * set up for walking up the chain. | ||
| 720 | */ | ||
| 721 | if (ext != NULL) { | ||
| 722 | i = -1; | ||
| 723 | x = NULL; | ||
| 724 | } else { | ||
| 725 | i = 0; | ||
| 726 | x = sk_X509_value(chain, i); | ||
| 727 | assert(x != NULL); | ||
| 728 | if ((ext = x->rfc3779_asid) == NULL) | ||
| 729 | goto done; | ||
| 730 | } | ||
| 731 | if (!v3_asid_is_canonical(ext)) | ||
| 732 | validation_err(X509_V_ERR_INVALID_EXTENSION); | ||
| 733 | if (ext->asnum != NULL) { | ||
| 734 | switch (ext->asnum->type) { | ||
| 735 | case ASIdentifierChoice_inherit: | ||
| 736 | inherit_as = 1; | ||
| 737 | break; | ||
| 738 | case ASIdentifierChoice_asIdsOrRanges: | ||
| 739 | child_as = ext->asnum->u.asIdsOrRanges; | ||
| 740 | break; | ||
| 741 | } | ||
| 742 | } | ||
| 743 | if (ext->rdi != NULL) { | ||
| 744 | switch (ext->rdi->type) { | ||
| 745 | case ASIdentifierChoice_inherit: | ||
| 746 | inherit_rdi = 1; | ||
| 747 | break; | ||
| 748 | case ASIdentifierChoice_asIdsOrRanges: | ||
| 749 | child_rdi = ext->rdi->u.asIdsOrRanges; | ||
| 750 | break; | ||
| 751 | } | ||
| 752 | } | ||
| 753 | |||
| 754 | /* | ||
| 755 | * Now walk up the chain. Extensions must be in canonical form, no | ||
| 756 | * cert may list resources that its parent doesn't list. | ||
| 757 | */ | ||
| 758 | for (i++; i < sk_X509_num(chain); i++) { | ||
| 759 | x = sk_X509_value(chain, i); | ||
| 760 | assert(x != NULL); | ||
| 761 | if (x->rfc3779_asid == NULL) { | ||
| 762 | if (child_as != NULL || child_rdi != NULL) | ||
| 763 | validation_err(X509_V_ERR_UNNESTED_RESOURCE); | ||
| 764 | continue; | ||
| 765 | } | ||
| 766 | if (!v3_asid_is_canonical(x->rfc3779_asid)) | ||
| 767 | validation_err(X509_V_ERR_INVALID_EXTENSION); | ||
| 768 | if (x->rfc3779_asid->asnum == NULL && child_as != NULL) { | ||
| 769 | validation_err(X509_V_ERR_UNNESTED_RESOURCE); | ||
| 770 | child_as = NULL; | ||
| 771 | inherit_as = 0; | ||
| 772 | } | ||
| 773 | if (x->rfc3779_asid->asnum != NULL && | ||
| 774 | x->rfc3779_asid->asnum->type == ASIdentifierChoice_asIdsOrRanges) { | ||
| 775 | if (inherit_as || | ||
| 776 | asid_contains(x->rfc3779_asid->asnum->u.asIdsOrRanges, child_as)) { | ||
| 777 | child_as = x->rfc3779_asid->asnum->u.asIdsOrRanges; | ||
| 778 | inherit_as = 0; | ||
| 779 | } else { | ||
| 780 | validation_err(X509_V_ERR_UNNESTED_RESOURCE); | ||
| 781 | } | ||
| 782 | } | ||
| 783 | if (x->rfc3779_asid->rdi == NULL && child_rdi != NULL) { | ||
| 784 | validation_err(X509_V_ERR_UNNESTED_RESOURCE); | ||
| 785 | child_rdi = NULL; | ||
| 786 | inherit_rdi = 0; | ||
| 787 | } | ||
| 788 | if (x->rfc3779_asid->rdi != NULL && | ||
| 789 | x->rfc3779_asid->rdi->type == ASIdentifierChoice_asIdsOrRanges) { | ||
| 790 | if (inherit_rdi || | ||
| 791 | asid_contains(x->rfc3779_asid->rdi->u.asIdsOrRanges, child_rdi)) { | ||
| 792 | child_rdi = x->rfc3779_asid->rdi->u.asIdsOrRanges; | ||
| 793 | inherit_rdi = 0; | ||
| 794 | } else { | ||
| 795 | validation_err(X509_V_ERR_UNNESTED_RESOURCE); | ||
| 796 | } | ||
| 797 | } | ||
| 798 | } | ||
| 799 | |||
| 800 | /* | ||
| 801 | * Trust anchor can't inherit. | ||
| 802 | */ | ||
| 803 | assert(x != NULL); | ||
| 804 | if (x->rfc3779_asid != NULL) { | ||
| 805 | if (x->rfc3779_asid->asnum != NULL && | ||
| 806 | x->rfc3779_asid->asnum->type == ASIdentifierChoice_inherit) | ||
| 807 | validation_err(X509_V_ERR_UNNESTED_RESOURCE); | ||
| 808 | if (x->rfc3779_asid->rdi != NULL && | ||
| 809 | x->rfc3779_asid->rdi->type == ASIdentifierChoice_inherit) | ||
| 810 | validation_err(X509_V_ERR_UNNESTED_RESOURCE); | ||
| 811 | } | ||
| 812 | |||
| 813 | done: | ||
| 814 | return ret; | ||
| 815 | } | ||
| 816 | |||
| 817 | #undef validation_err | ||
| 818 | |||
| 819 | /* | ||
| 820 | * RFC 3779 3.3 path validation -- called from X509_verify_cert(). | ||
| 821 | */ | ||
| 822 | int v3_asid_validate_path(X509_STORE_CTX *ctx) | ||
| 823 | { | ||
| 824 | return v3_asid_validate_path_internal(ctx, ctx->chain, NULL); | ||
| 825 | } | ||
| 826 | |||
| 827 | /* | ||
| 828 | * RFC 3779 3.3 path validation of an extension. | ||
| 829 | * Test whether chain covers extension. | ||
| 830 | */ | ||
| 831 | int v3_asid_validate_resource_set(STACK_OF(X509) *chain, | ||
| 832 | ASIdentifiers *ext, | ||
| 833 | int allow_inheritance) | ||
| 834 | { | ||
| 835 | if (ext == NULL) | ||
| 836 | return 1; | ||
| 837 | if (chain == NULL || sk_X509_num(chain) == 0) | ||
| 838 | return 0; | ||
| 839 | if (!allow_inheritance && v3_asid_inherits(ext)) | ||
| 840 | return 0; | ||
| 841 | return v3_asid_validate_path_internal(NULL, chain, ext); | ||
| 842 | } | ||
| 843 | |||
| 844 | #endif /* OPENSSL_NO_RFC3779 */ | ||
diff --git a/src/lib/libcrypto/rc4/rc4_fblk.c b/src/lib/libssl/src/crypto/asn1/x_nx509.c index 1b2a42979b..fbd9a22db3 100644 --- a/src/lib/libcrypto/rc4/rc4_fblk.c +++ b/src/lib/libssl/src/crypto/asn1/x_nx509.c | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | /* crypto/rc4/rc4_fblk.c */ | 1 | /* x_nx509.c */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project. | 3 | * project 2005. |
| 4 | */ | 4 | */ |
| 5 | /* ==================================================================== | 5 | /* ==================================================================== |
| 6 | * Copyright (c) 2008 The OpenSSL Project. All rights reserved. | 6 | * Copyright (c) 2005 The OpenSSL Project. All rights reserved. |
| 7 | * | 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions |
| @@ -49,27 +49,24 @@ | |||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 51 | * ==================================================================== | 51 | * ==================================================================== |
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 52 | */ | 57 | */ |
| 53 | 58 | ||
| 59 | #include <stddef.h> | ||
| 60 | #include <openssl/x509.h> | ||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/asn1t.h> | ||
| 54 | 63 | ||
| 55 | #include <openssl/rc4.h> | 64 | /* Old netscape certificate wrapper format */ |
| 56 | #include "rc4_locl.h" | ||
| 57 | #include <openssl/opensslv.h> | ||
| 58 | #include <openssl/crypto.h> | ||
| 59 | #ifdef OPENSSL_FIPS | ||
| 60 | #include <openssl/fips.h> | ||
| 61 | #endif | ||
| 62 | 65 | ||
| 63 | /* FIPS mode blocking for RC4 has to be done separately since RC4_set_key | 66 | ASN1_SEQUENCE(NETSCAPE_X509) = { |
| 64 | * may be implemented in an assembly language file. | 67 | ASN1_SIMPLE(NETSCAPE_X509, header, ASN1_OCTET_STRING), |
| 65 | */ | 68 | ASN1_OPT(NETSCAPE_X509, cert, X509) |
| 69 | } ASN1_SEQUENCE_END(NETSCAPE_X509) | ||
| 66 | 70 | ||
| 67 | #ifdef OPENSSL_FIPS | 71 | IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_X509) |
| 68 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) | ||
| 69 | { | ||
| 70 | if (FIPS_mode()) | ||
| 71 | FIPS_BAD_ABORT(RC4) | ||
| 72 | private_RC4_set_key(key, len, data); | ||
| 73 | } | ||
| 74 | #endif | ||
| 75 | 72 | ||
diff --git a/src/lib/libcrypto/engine/hw_sureware_err.h b/src/lib/libssl/src/crypto/ecdh/ecdh.h index bc52af5e05..b4b58ee65b 100644 --- a/src/lib/libcrypto/engine/hw_sureware_err.h +++ b/src/lib/libssl/src/crypto/ecdh/ecdh.h | |||
| @@ -1,5 +1,20 @@ | |||
| 1 | /* crypto/ecdh/ecdh.h */ | ||
| 1 | /* ==================================================================== | 2 | /* ==================================================================== |
| 2 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
| 4 | * | ||
| 5 | * The Elliptic Curve Public-Key Crypto Library (ECC Code) included | ||
| 6 | * herein is developed by SUN MICROSYSTEMS, INC., and is contributed | ||
| 7 | * to the OpenSSL project. | ||
| 8 | * | ||
| 9 | * The ECC Code is licensed pursuant to the OpenSSL open source | ||
| 10 | * license provided below. | ||
| 11 | * | ||
| 12 | * The ECDH software is originally written by Douglas Stebila of | ||
| 13 | * Sun Microsystems Laboratories. | ||
| 14 | * | ||
| 15 | */ | ||
| 16 | /* ==================================================================== | ||
| 17 | * Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved. | ||
| 3 | * | 18 | * |
| 4 | * Redistribution and use in source and binary forms, with or without | 19 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions | 20 | * modification, are permitted provided that the following conditions |
| @@ -16,12 +31,12 @@ | |||
| 16 | * 3. All advertising materials mentioning features or use of this | 31 | * 3. All advertising materials mentioning features or use of this |
| 17 | * software must display the following acknowledgment: | 32 | * software must display the following acknowledgment: |
| 18 | * "This product includes software developed by the OpenSSL Project | 33 | * "This product includes software developed by the OpenSSL Project |
| 19 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | 34 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" |
| 20 | * | 35 | * |
| 21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | 36 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
| 22 | * endorse or promote products derived from this software without | 37 | * endorse or promote products derived from this software without |
| 23 | * prior written permission. For written permission, please contact | 38 | * prior written permission. For written permission, please contact |
| 24 | * openssl-core@openssl.org. | 39 | * licensing@OpenSSL.org. |
| 25 | * | 40 | * |
| 26 | * 5. Products derived from this software may not be called "OpenSSL" | 41 | * 5. Products derived from this software may not be called "OpenSSL" |
| 27 | * nor may "OpenSSL" appear in their names without prior written | 42 | * nor may "OpenSSL" appear in their names without prior written |
| @@ -30,7 +45,7 @@ | |||
| 30 | * 6. Redistributions of any form whatsoever must retain the following | 45 | * 6. Redistributions of any form whatsoever must retain the following |
| 31 | * acknowledgment: | 46 | * acknowledgment: |
| 32 | * "This product includes software developed by the OpenSSL Project | 47 | * "This product includes software developed by the OpenSSL Project |
| 33 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | 48 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" |
| 34 | * | 49 | * |
| 35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | 50 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
| 36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 51 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| @@ -51,42 +66,56 @@ | |||
| 51 | * Hudson (tjh@cryptsoft.com). | 66 | * Hudson (tjh@cryptsoft.com). |
| 52 | * | 67 | * |
| 53 | */ | 68 | */ |
| 69 | #ifndef HEADER_ECDH_H | ||
| 70 | #define HEADER_ECDH_H | ||
| 71 | |||
| 72 | #include <openssl/opensslconf.h> | ||
| 73 | |||
| 74 | #ifdef OPENSSL_NO_ECDH | ||
| 75 | #error ECDH is disabled. | ||
| 76 | #endif | ||
| 77 | |||
| 78 | #include <openssl/ec.h> | ||
| 79 | #include <openssl/ossl_typ.h> | ||
| 80 | #ifndef OPENSSL_NO_DEPRECATED | ||
| 81 | #include <openssl/bn.h> | ||
| 82 | #endif | ||
| 83 | |||
| 84 | #ifdef __cplusplus | ||
| 85 | extern "C" { | ||
| 86 | #endif | ||
| 87 | |||
| 88 | const ECDH_METHOD *ECDH_OpenSSL(void); | ||
| 89 | |||
| 90 | void ECDH_set_default_method(const ECDH_METHOD *); | ||
| 91 | const ECDH_METHOD *ECDH_get_default_method(void); | ||
| 92 | int ECDH_set_method(EC_KEY *, const ECDH_METHOD *); | ||
| 93 | |||
| 94 | int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, | ||
| 95 | void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)); | ||
| 96 | |||
| 97 | int ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new | ||
| 98 | *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
| 99 | int ECDH_set_ex_data(EC_KEY *d, int idx, void *arg); | ||
| 100 | void *ECDH_get_ex_data(EC_KEY *d, int idx); | ||
| 54 | 101 | ||
| 55 | #ifndef HEADER_SUREWARE_ERR_H | ||
| 56 | #define HEADER_SUREWARE_ERR_H | ||
| 57 | 102 | ||
| 58 | /* BEGIN ERROR CODES */ | 103 | /* BEGIN ERROR CODES */ |
| 59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 104 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
| 60 | * made after this point may be overwritten when the script is next run. | 105 | * made after this point may be overwritten when the script is next run. |
| 61 | */ | 106 | */ |
| 62 | static void ERR_load_SUREWARE_strings(void); | 107 | void ERR_load_ECDH_strings(void); |
| 63 | static void ERR_unload_SUREWARE_strings(void); | ||
| 64 | static void ERR_SUREWARE_error(int function, int reason, char *file, int line); | ||
| 65 | #define SUREWAREerr(f,r) ERR_SUREWARE_error((f),(r),__FILE__,__LINE__) | ||
| 66 | 108 | ||
| 67 | /* Error codes for the SUREWARE functions. */ | 109 | /* Error codes for the ECDH functions. */ |
| 68 | 110 | ||
| 69 | /* Function codes. */ | 111 | /* Function codes. */ |
| 70 | #define SUREWARE_F_SUREWAREHK_CTRL 100 | 112 | #define ECDH_F_ECDH_COMPUTE_KEY 100 |
| 71 | #define SUREWARE_F_SUREWAREHK_DSA_DO_SIGN 101 | 113 | #define ECDH_F_ECDH_DATA_NEW_METHOD 101 |
| 72 | #define SUREWARE_F_SUREWAREHK_EX_FREE 102 | ||
| 73 | #define SUREWARE_F_SUREWAREHK_FINISH 103 | ||
| 74 | #define SUREWARE_F_SUREWAREHK_INIT 104 | ||
| 75 | #define SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY 105 | ||
| 76 | #define SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY 106 | ||
| 77 | #define SUREWARE_F_SUREWAREHK_MOD_EXP 107 | ||
| 78 | #define SUREWARE_F_SUREWAREHK_RAND_BYTES 108 | ||
| 79 | #define SUREWARE_F_SUREWAREHK_RAND_SEED 109 | ||
| 80 | #define SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC 110 | ||
| 81 | #define SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC 111 | ||
| 82 | 114 | ||
| 83 | /* Reason codes. */ | 115 | /* Reason codes. */ |
| 84 | #define SUREWARE_R_BIO_WAS_FREED 100 | 116 | #define ECDH_R_KDF_FAILED 102 |
| 85 | #define SUREWARE_R_MISSING_KEY_COMPONENTS 105 | 117 | #define ECDH_R_NO_PRIVATE_VALUE 100 |
| 86 | #define SUREWARE_R_REQUEST_FAILED 101 | 118 | #define ECDH_R_POINT_ARITHMETIC_FAILURE 101 |
| 87 | #define SUREWARE_R_REQUEST_FALLBACK 102 | ||
| 88 | #define SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL 103 | ||
| 89 | #define SUREWARE_R_UNIT_FAILURE 104 | ||
| 90 | 119 | ||
| 91 | #ifdef __cplusplus | 120 | #ifdef __cplusplus |
| 92 | } | 121 | } |
diff --git a/src/lib/libcrypto/evp/dig_eng.c b/src/lib/libssl/src/crypto/evp/m_ecdsa.c index 64cdf9366c..8d87a49ebe 100644 --- a/src/lib/libcrypto/evp/dig_eng.c +++ b/src/lib/libssl/src/crypto/evp/m_ecdsa.c | |||
| @@ -1,4 +1,57 @@ | |||
| 1 | /* crypto/evp/digest.c */ | 1 | /* crypto/evp/m_ecdsa.c */ |
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 55 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 56 | * All rights reserved. |
| 4 | * | 57 | * |
| @@ -55,126 +108,41 @@ | |||
| 55 | * copied and put under another distribution licence | 108 | * copied and put under another distribution licence |
| 56 | * [including the GNU Public Licence.] | 109 | * [including the GNU Public Licence.] |
| 57 | */ | 110 | */ |
| 58 | /* ==================================================================== | ||
| 59 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
| 60 | * | ||
| 61 | * Redistribution and use in source and binary forms, with or without | ||
| 62 | * modification, are permitted provided that the following conditions | ||
| 63 | * are met: | ||
| 64 | * | ||
| 65 | * 1. Redistributions of source code must retain the above copyright | ||
| 66 | * notice, this list of conditions and the following disclaimer. | ||
| 67 | * | ||
| 68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 69 | * notice, this list of conditions and the following disclaimer in | ||
| 70 | * the documentation and/or other materials provided with the | ||
| 71 | * distribution. | ||
| 72 | * | ||
| 73 | * 3. All advertising materials mentioning features or use of this | ||
| 74 | * software must display the following acknowledgment: | ||
| 75 | * "This product includes software developed by the OpenSSL Project | ||
| 76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 77 | * | ||
| 78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 79 | * endorse or promote products derived from this software without | ||
| 80 | * prior written permission. For written permission, please contact | ||
| 81 | * openssl-core@openssl.org. | ||
| 82 | * | ||
| 83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 84 | * nor may "OpenSSL" appear in their names without prior written | ||
| 85 | * permission of the OpenSSL Project. | ||
| 86 | * | ||
| 87 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 88 | * acknowledgment: | ||
| 89 | * "This product includes software developed by the OpenSSL Project | ||
| 90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 91 | * | ||
| 92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 104 | * ==================================================================== | ||
| 105 | * | ||
| 106 | * This product includes cryptographic software written by Eric Young | ||
| 107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 108 | * Hudson (tjh@cryptsoft.com). | ||
| 109 | * | ||
| 110 | */ | ||
| 111 | 111 | ||
| 112 | #include <stdio.h> | 112 | #include <stdio.h> |
| 113 | #include "cryptlib.h" | 113 | #include "cryptlib.h" |
| 114 | #include <openssl/objects.h> | ||
| 115 | #include <openssl/evp.h> | 114 | #include <openssl/evp.h> |
| 116 | #ifndef OPENSSL_NO_ENGINE | 115 | #include <openssl/objects.h> |
| 117 | #include <openssl/engine.h> | 116 | #include <openssl/x509.h> |
| 118 | #endif | ||
| 119 | #include "evp_locl.h" | ||
| 120 | 117 | ||
| 121 | #ifndef OPENSSL_NO_ENGINE | 118 | #ifndef OPENSSL_NO_SHA |
| 119 | static int init(EVP_MD_CTX *ctx) | ||
| 120 | { return SHA1_Init(ctx->md_data); } | ||
| 122 | 121 | ||
| 123 | #ifdef OPENSSL_FIPS | 122 | static int update(EVP_MD_CTX *ctx,const void *data,size_t count) |
| 123 | { return SHA1_Update(ctx->md_data,data,count); } | ||
| 124 | 124 | ||
| 125 | static int do_evp_md_engine_full(EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl) | 125 | static int final(EVP_MD_CTX *ctx,unsigned char *md) |
| 126 | { return SHA1_Final(md,ctx->md_data); } | ||
| 127 | |||
| 128 | static const EVP_MD ecdsa_md= | ||
| 126 | { | 129 | { |
| 127 | if (*ptype) | 130 | NID_ecdsa_with_SHA1, |
| 128 | { | 131 | NID_ecdsa_with_SHA1, |
| 129 | /* Ensure an ENGINE left lying around from last time is cleared | 132 | SHA_DIGEST_LENGTH, |
| 130 | * (the previous check attempted to avoid this if the same | 133 | EVP_MD_FLAG_PKEY_DIGEST, |
| 131 | * ENGINE and EVP_MD could be used). */ | 134 | init, |
| 132 | if(ctx->engine) | 135 | update, |
| 133 | ENGINE_finish(ctx->engine); | 136 | final, |
| 134 | if(impl) | 137 | NULL, |
| 135 | { | 138 | NULL, |
| 136 | if (!ENGINE_init(impl)) | 139 | EVP_PKEY_ECDSA_method, |
| 137 | { | 140 | SHA_CBLOCK, |
| 138 | EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_INITIALIZATION_ERROR); | 141 | sizeof(EVP_MD *)+sizeof(SHA_CTX), |
| 139 | return 0; | 142 | }; |
| 140 | } | ||
| 141 | } | ||
| 142 | else | ||
| 143 | /* Ask if an ENGINE is reserved for this job */ | ||
| 144 | impl = ENGINE_get_digest_engine((*ptype)->type); | ||
| 145 | if(impl) | ||
| 146 | { | ||
| 147 | /* There's an ENGINE for this job ... (apparently) */ | ||
| 148 | const EVP_MD *d = ENGINE_get_digest(impl, (*ptype)->type); | ||
| 149 | if(!d) | ||
| 150 | { | ||
| 151 | /* Same comment from evp_enc.c */ | ||
| 152 | EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_INITIALIZATION_ERROR); | ||
| 153 | return 0; | ||
| 154 | } | ||
| 155 | /* We'll use the ENGINE's private digest definition */ | ||
| 156 | *ptype = d; | ||
| 157 | /* Store the ENGINE functional reference so we know | ||
| 158 | * 'type' came from an ENGINE and we need to release | ||
| 159 | * it when done. */ | ||
| 160 | ctx->engine = impl; | ||
| 161 | } | ||
| 162 | else | ||
| 163 | ctx->engine = NULL; | ||
| 164 | } | ||
| 165 | else | ||
| 166 | if(!ctx->digest) | ||
| 167 | { | ||
| 168 | EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_NO_DIGEST_SET); | ||
| 169 | return 0; | ||
| 170 | } | ||
| 171 | return 1; | ||
| 172 | } | ||
| 173 | 143 | ||
| 174 | void int_EVP_MD_init_engine_callbacks(void) | 144 | const EVP_MD *EVP_ecdsa(void) |
| 175 | { | 145 | { |
| 176 | int_EVP_MD_set_engine_callbacks( | 146 | return(&ecdsa_md); |
| 177 | ENGINE_init, ENGINE_finish, do_evp_md_engine_full); | ||
| 178 | } | 147 | } |
| 179 | #endif | 148 | #endif |
| 180 | #endif | ||
diff --git a/src/lib/libcrypto/ec/ec2_smpt.c b/src/lib/libssl/src/crypto/rsa/rsa_depr.c index 59d52bf663..a859ded987 100644 --- a/src/lib/libcrypto/ec/ec2_smpt.c +++ b/src/lib/libssl/src/crypto/rsa/rsa_depr.c | |||
| @@ -1,7 +1,4 @@ | |||
| 1 | /* crypto/ec/ec2_smpt.c */ | 1 | /* crypto/rsa/rsa_depr.c */ |
| 2 | /* This code was originally written by Douglas Stebila | ||
| 3 | * <dstebila@student.math.uwaterloo.ca> for the OpenSSL project. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | 2 | /* ==================================================================== |
| 6 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. |
| 7 | * | 4 | * |
| @@ -56,19 +53,49 @@ | |||
| 56 | * | 53 | * |
| 57 | */ | 54 | */ |
| 58 | 55 | ||
| 56 | /* NB: This file contains deprecated functions (compatibility wrappers to the | ||
| 57 | * "new" versions). */ | ||
| 59 | 58 | ||
| 60 | /* Calaculates and sets the affine coordinates of an EC_POINT from the given | 59 | #include <stdio.h> |
| 61 | * compressed coordinates. Uses algorithm 2.3.4 of SEC 1. | 60 | #include <time.h> |
| 62 | * Note that the simple implementation only uses affine coordinates. | 61 | #include "cryptlib.h" |
| 63 | * | 62 | #include <openssl/bn.h> |
| 64 | * This algorithm is patented by Certicom Corp. under US Patent 6,141,420 | 63 | #include <openssl/rsa.h> |
| 65 | * (for licensing information, contact licensing@certicom.com). | 64 | |
| 66 | * This function is disabled by default and can be enabled by defining the | 65 | #ifdef OPENSSL_NO_DEPRECATED |
| 67 | * preprocessor macro OPENSSL_EC_BIN_PT_COMP at Configure-time. | 66 | |
| 68 | */ | 67 | static void *dummy=&dummy; |
| 69 | int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point, | 68 | |
| 70 | const BIGNUM *x_, int y_bit, BN_CTX *ctx) | 69 | #else |
| 70 | |||
| 71 | RSA *RSA_generate_key(int bits, unsigned long e_value, | ||
| 72 | void (*callback)(int,int,void *), void *cb_arg) | ||
| 71 | { | 73 | { |
| 72 | ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_DISABLED); | 74 | BN_GENCB cb; |
| 75 | int i; | ||
| 76 | RSA *rsa = RSA_new(); | ||
| 77 | BIGNUM *e = BN_new(); | ||
| 78 | |||
| 79 | if(!rsa || !e) goto err; | ||
| 80 | |||
| 81 | /* The problem is when building with 8, 16, or 32 BN_ULONG, | ||
| 82 | * unsigned long can be larger */ | ||
| 83 | for (i=0; i<(int)sizeof(unsigned long)*8; i++) | ||
| 84 | { | ||
| 85 | if (e_value & (1UL<<i)) | ||
| 86 | if (BN_set_bit(e,i) == 0) | ||
| 87 | goto err; | ||
| 88 | } | ||
| 89 | |||
| 90 | BN_GENCB_set_old(&cb, callback, cb_arg); | ||
| 91 | |||
| 92 | if(RSA_generate_key_ex(rsa, bits, e, &cb)) { | ||
| 93 | BN_free(e); | ||
| 94 | return rsa; | ||
| 95 | } | ||
| 96 | err: | ||
| 97 | if(e) BN_free(e); | ||
| 98 | if(rsa) RSA_free(rsa); | ||
| 73 | return 0; | 99 | return 0; |
| 74 | } | 100 | } |
| 101 | #endif | ||
diff --git a/src/lib/libcrypto/engine/hw_4758_cca_err.c b/src/lib/libssl/src/engines/e_4758cca_err.c index 7ea5c63707..6ecdc6e627 100644 --- a/src/lib/libcrypto/engine/hw_4758_cca_err.c +++ b/src/lib/libssl/src/engines/e_4758cca_err.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* hw_4758_cca_err.c */ | 1 | /* e_4758cca_err.c */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| @@ -60,34 +60,38 @@ | |||
| 60 | 60 | ||
| 61 | #include <stdio.h> | 61 | #include <stdio.h> |
| 62 | #include <openssl/err.h> | 62 | #include <openssl/err.h> |
| 63 | #include "hw_4758_cca_err.h" | 63 | #include "e_4758cca_err.h" |
| 64 | 64 | ||
| 65 | /* BEGIN ERROR CODES */ | 65 | /* BEGIN ERROR CODES */ |
| 66 | #ifndef OPENSSL_NO_ERR | 66 | #ifndef OPENSSL_NO_ERR |
| 67 | |||
| 68 | #define ERR_FUNC(func) ERR_PACK(0,func,0) | ||
| 69 | #define ERR_REASON(reason) ERR_PACK(0,0,reason) | ||
| 70 | |||
| 67 | static ERR_STRING_DATA CCA4758_str_functs[]= | 71 | static ERR_STRING_DATA CCA4758_str_functs[]= |
| 68 | { | 72 | { |
| 69 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_CTRL,0), "IBM_4758_CCA_CTRL"}, | 73 | {ERR_FUNC(CCA4758_F_CCA_RSA_SIGN), "CCA_RSA_SIGN"}, |
| 70 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_FINISH,0), "IBM_4758_CCA_FINISH"}, | 74 | {ERR_FUNC(CCA4758_F_CCA_RSA_VERIFY), "CCA_RSA_VERIFY"}, |
| 71 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_INIT,0), "IBM_4758_CCA_INIT"}, | 75 | {ERR_FUNC(CCA4758_F_IBM_4758_CCA_CTRL), "IBM_4758_CCA_CTRL"}, |
| 72 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,0), "IBM_4758_CCA_LOAD_PRIVKEY"}, | 76 | {ERR_FUNC(CCA4758_F_IBM_4758_CCA_FINISH), "IBM_4758_CCA_FINISH"}, |
| 73 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,0), "IBM_4758_CCA_LOAD_PUBKEY"}, | 77 | {ERR_FUNC(CCA4758_F_IBM_4758_CCA_INIT), "IBM_4758_CCA_INIT"}, |
| 74 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_SIGN,0), "IBM_4758_CCA_SIGN"}, | 78 | {ERR_FUNC(CCA4758_F_IBM_4758_LOAD_PRIVKEY), "IBM_4758_LOAD_PRIVKEY"}, |
| 75 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_VERIFY,0), "IBM_4758_CCA_VERIFY"}, | 79 | {ERR_FUNC(CCA4758_F_IBM_4758_LOAD_PUBKEY), "IBM_4758_LOAD_PUBKEY"}, |
| 76 | {0,NULL} | 80 | {0,NULL} |
| 77 | }; | 81 | }; |
| 78 | 82 | ||
| 79 | static ERR_STRING_DATA CCA4758_str_reasons[]= | 83 | static ERR_STRING_DATA CCA4758_str_reasons[]= |
| 80 | { | 84 | { |
| 81 | {CCA4758_R_ALREADY_LOADED ,"already loaded"}, | 85 | {ERR_REASON(CCA4758_R_ALREADY_LOADED) ,"already loaded"}, |
| 82 | {CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD ,"asn1 oid unknown for md"}, | 86 | {ERR_REASON(CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD),"asn1 oid unknown for md"}, |
| 83 | {CCA4758_R_COMMAND_NOT_IMPLEMENTED ,"command not implemented"}, | 87 | {ERR_REASON(CCA4758_R_COMMAND_NOT_IMPLEMENTED),"command not implemented"}, |
| 84 | {CCA4758_R_DSO_FAILURE ,"dso failure"}, | 88 | {ERR_REASON(CCA4758_R_DSO_FAILURE) ,"dso failure"}, |
| 85 | {CCA4758_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"}, | 89 | {ERR_REASON(CCA4758_R_FAILED_LOADING_PRIVATE_KEY),"failed loading private key"}, |
| 86 | {CCA4758_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"}, | 90 | {ERR_REASON(CCA4758_R_FAILED_LOADING_PUBLIC_KEY),"failed loading public key"}, |
| 87 | {CCA4758_R_NOT_LOADED ,"not loaded"}, | 91 | {ERR_REASON(CCA4758_R_NOT_LOADED) ,"not loaded"}, |
| 88 | {CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"}, | 92 | {ERR_REASON(CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL),"size too large or too small"}, |
| 89 | {CCA4758_R_UNIT_FAILURE ,"unit failure"}, | 93 | {ERR_REASON(CCA4758_R_UNIT_FAILURE) ,"unit failure"}, |
| 90 | {CCA4758_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"}, | 94 | {ERR_REASON(CCA4758_R_UNKNOWN_ALGORITHM_TYPE),"unknown algorithm type"}, |
| 91 | {0,NULL} | 95 | {0,NULL} |
| 92 | }; | 96 | }; |
| 93 | 97 | ||
diff --git a/src/lib/libcrypto/engine/hw_4758_cca_err.h b/src/lib/libssl/src/engines/e_4758cca_err.h index 2fc563ab11..26087edbfa 100644 --- a/src/lib/libcrypto/engine/hw_4758_cca_err.h +++ b/src/lib/libssl/src/engines/e_4758cca_err.h | |||
| @@ -55,6 +55,10 @@ | |||
| 55 | #ifndef HEADER_CCA4758_ERR_H | 55 | #ifndef HEADER_CCA4758_ERR_H |
| 56 | #define HEADER_CCA4758_ERR_H | 56 | #define HEADER_CCA4758_ERR_H |
| 57 | 57 | ||
| 58 | #ifdef __cplusplus | ||
| 59 | extern "C" { | ||
| 60 | #endif | ||
| 61 | |||
| 58 | /* BEGIN ERROR CODES */ | 62 | /* BEGIN ERROR CODES */ |
| 59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 63 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
| 60 | * made after this point may be overwritten when the script is next run. | 64 | * made after this point may be overwritten when the script is next run. |
| @@ -67,13 +71,13 @@ static void ERR_CCA4758_error(int function, int reason, char *file, int line); | |||
| 67 | /* Error codes for the CCA4758 functions. */ | 71 | /* Error codes for the CCA4758 functions. */ |
| 68 | 72 | ||
| 69 | /* Function codes. */ | 73 | /* Function codes. */ |
| 74 | #define CCA4758_F_CCA_RSA_SIGN 105 | ||
| 75 | #define CCA4758_F_CCA_RSA_VERIFY 106 | ||
| 70 | #define CCA4758_F_IBM_4758_CCA_CTRL 100 | 76 | #define CCA4758_F_IBM_4758_CCA_CTRL 100 |
| 71 | #define CCA4758_F_IBM_4758_CCA_FINISH 101 | 77 | #define CCA4758_F_IBM_4758_CCA_FINISH 101 |
| 72 | #define CCA4758_F_IBM_4758_CCA_INIT 102 | 78 | #define CCA4758_F_IBM_4758_CCA_INIT 102 |
| 73 | #define CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY 103 | 79 | #define CCA4758_F_IBM_4758_LOAD_PRIVKEY 103 |
| 74 | #define CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY 104 | 80 | #define CCA4758_F_IBM_4758_LOAD_PUBKEY 104 |
| 75 | #define CCA4758_F_IBM_4758_CCA_SIGN 105 | ||
| 76 | #define CCA4758_F_IBM_4758_CCA_VERIFY 106 | ||
| 77 | 81 | ||
| 78 | /* Reason codes. */ | 82 | /* Reason codes. */ |
| 79 | #define CCA4758_R_ALREADY_LOADED 100 | 83 | #define CCA4758_R_ALREADY_LOADED 100 |
diff --git a/src/lib/libcrypto/engine/hw_aep_err.h b/src/lib/libssl/src/engines/e_aep_err.h index 8fe4cf921f..35b2e74260 100644 --- a/src/lib/libcrypto/engine/hw_aep_err.h +++ b/src/lib/libssl/src/engines/e_aep_err.h | |||
| @@ -55,6 +55,10 @@ | |||
| 55 | #ifndef HEADER_AEPHK_ERR_H | 55 | #ifndef HEADER_AEPHK_ERR_H |
| 56 | #define HEADER_AEPHK_ERR_H | 56 | #define HEADER_AEPHK_ERR_H |
| 57 | 57 | ||
| 58 | #ifdef __cplusplus | ||
| 59 | extern "C" { | ||
| 60 | #endif | ||
| 61 | |||
| 58 | /* BEGIN ERROR CODES */ | 62 | /* BEGIN ERROR CODES */ |
| 59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 63 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
| 60 | * made after this point may be overwritten when the script is next run. | 64 | * made after this point may be overwritten when the script is next run. |
diff --git a/src/lib/libcrypto/engine/hw_atalla.c b/src/lib/libssl/src/engines/e_atalla.c index 2b8342bbdd..fabaa86a52 100644 --- a/src/lib/libcrypto/engine/hw_atalla.c +++ b/src/lib/libssl/src/engines/e_atalla.c | |||
| @@ -57,10 +57,21 @@ | |||
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include <string.h> | ||
| 60 | #include <openssl/crypto.h> | 61 | #include <openssl/crypto.h> |
| 61 | #include "cryptlib.h" | 62 | #include <openssl/buffer.h> |
| 62 | #include <openssl/dso.h> | 63 | #include <openssl/dso.h> |
| 63 | #include <openssl/engine.h> | 64 | #include <openssl/engine.h> |
| 65 | #ifndef OPENSSL_NO_RSA | ||
| 66 | #include <openssl/rsa.h> | ||
| 67 | #endif | ||
| 68 | #ifndef OPENSSL_NO_DSA | ||
| 69 | #include <openssl/dsa.h> | ||
| 70 | #endif | ||
| 71 | #ifndef OPENSSL_NO_DH | ||
| 72 | #include <openssl/dh.h> | ||
| 73 | #endif | ||
| 74 | #include <openssl/bn.h> | ||
| 64 | 75 | ||
| 65 | #ifndef OPENSSL_NO_HW | 76 | #ifndef OPENSSL_NO_HW |
| 66 | #ifndef OPENSSL_NO_HW_ATALLA | 77 | #ifndef OPENSSL_NO_HW_ATALLA |
| @@ -72,12 +83,12 @@ | |||
| 72 | #endif | 83 | #endif |
| 73 | 84 | ||
| 74 | #define ATALLA_LIB_NAME "atalla engine" | 85 | #define ATALLA_LIB_NAME "atalla engine" |
| 75 | #include "hw_atalla_err.c" | 86 | #include "e_atalla_err.c" |
| 76 | 87 | ||
| 77 | static int atalla_destroy(ENGINE *e); | 88 | static int atalla_destroy(ENGINE *e); |
| 78 | static int atalla_init(ENGINE *e); | 89 | static int atalla_init(ENGINE *e); |
| 79 | static int atalla_finish(ENGINE *e); | 90 | static int atalla_finish(ENGINE *e); |
| 80 | static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | 91 | static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)); |
| 81 | 92 | ||
| 82 | /* BIGNUM stuff */ | 93 | /* BIGNUM stuff */ |
| 83 | static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 94 | static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| @@ -85,11 +96,11 @@ static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | |||
| 85 | 96 | ||
| 86 | #ifndef OPENSSL_NO_RSA | 97 | #ifndef OPENSSL_NO_RSA |
| 87 | /* RSA stuff */ | 98 | /* RSA stuff */ |
| 88 | static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa); | 99 | static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx); |
| 89 | #endif | ||
| 90 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | 100 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ |
| 91 | static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 101 | static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| 92 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | 102 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); |
| 103 | #endif | ||
| 93 | 104 | ||
| 94 | #ifndef OPENSSL_NO_DSA | 105 | #ifndef OPENSSL_NO_DSA |
| 95 | /* DSA stuff */ | 106 | /* DSA stuff */ |
| @@ -135,6 +146,7 @@ static RSA_METHOD atalla_rsa = | |||
| 135 | 0, | 146 | 0, |
| 136 | NULL, | 147 | NULL, |
| 137 | NULL, | 148 | NULL, |
| 149 | NULL, | ||
| 138 | NULL | 150 | NULL |
| 139 | }; | 151 | }; |
| 140 | #endif | 152 | #endif |
| @@ -152,7 +164,9 @@ static DSA_METHOD atalla_dsa = | |||
| 152 | NULL, /* init */ | 164 | NULL, /* init */ |
| 153 | NULL, /* finish */ | 165 | NULL, /* finish */ |
| 154 | 0, /* flags */ | 166 | 0, /* flags */ |
| 155 | NULL /* app_data */ | 167 | NULL, /* app_data */ |
| 168 | NULL, /* dsa_paramgen */ | ||
| 169 | NULL /* dsa_keygen */ | ||
| 156 | }; | 170 | }; |
| 157 | #endif | 171 | #endif |
| 158 | 172 | ||
| @@ -167,6 +181,7 @@ static DH_METHOD atalla_dh = | |||
| 167 | NULL, | 181 | NULL, |
| 168 | NULL, | 182 | NULL, |
| 169 | 0, | 183 | 0, |
| 184 | NULL, | ||
| 170 | NULL | 185 | NULL |
| 171 | }; | 186 | }; |
| 172 | #endif | 187 | #endif |
| @@ -242,7 +257,7 @@ static int bind_helper(ENGINE *e) | |||
| 242 | return 1; | 257 | return 1; |
| 243 | } | 258 | } |
| 244 | 259 | ||
| 245 | #ifndef ENGINE_DYNAMIC_SUPPORT | 260 | #ifdef OPENSSL_NO_DYNAMIC_ENGINE |
| 246 | static ENGINE *engine_atalla(void) | 261 | static ENGINE *engine_atalla(void) |
| 247 | { | 262 | { |
| 248 | ENGINE *ret = ENGINE_new(); | 263 | ENGINE *ret = ENGINE_new(); |
| @@ -402,7 +417,7 @@ static int atalla_finish(ENGINE *e) | |||
| 402 | return 1; | 417 | return 1; |
| 403 | } | 418 | } |
| 404 | 419 | ||
| 405 | static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | 420 | static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) |
| 406 | { | 421 | { |
| 407 | int initialised = ((atalla_dso == NULL) ? 0 : 1); | 422 | int initialised = ((atalla_dso == NULL) ? 0 : 1); |
| 408 | switch(cmd) | 423 | switch(cmd) |
| @@ -498,9 +513,8 @@ err: | |||
| 498 | } | 513 | } |
| 499 | 514 | ||
| 500 | #ifndef OPENSSL_NO_RSA | 515 | #ifndef OPENSSL_NO_RSA |
| 501 | static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | 516 | static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) |
| 502 | { | 517 | { |
| 503 | BN_CTX *ctx = NULL; | ||
| 504 | int to_return = 0; | 518 | int to_return = 0; |
| 505 | 519 | ||
| 506 | if(!atalla_dso) | 520 | if(!atalla_dso) |
| @@ -508,8 +522,6 @@ static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | |||
| 508 | ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_NOT_LOADED); | 522 | ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_NOT_LOADED); |
| 509 | goto err; | 523 | goto err; |
| 510 | } | 524 | } |
| 511 | if((ctx = BN_CTX_new()) == NULL) | ||
| 512 | goto err; | ||
| 513 | if(!rsa->d || !rsa->n) | 525 | if(!rsa->d || !rsa->n) |
| 514 | { | 526 | { |
| 515 | ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_MISSING_KEY_COMPONENTS); | 527 | ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_MISSING_KEY_COMPONENTS); |
| @@ -517,8 +529,6 @@ static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | |||
| 517 | } | 529 | } |
| 518 | to_return = atalla_mod_exp(r0, I, rsa->d, rsa->n, ctx); | 530 | to_return = atalla_mod_exp(r0, I, rsa->d, rsa->n, ctx); |
| 519 | err: | 531 | err: |
| 520 | if(ctx) | ||
| 521 | BN_CTX_free(ctx); | ||
| 522 | return to_return; | 532 | return to_return; |
| 523 | } | 533 | } |
| 524 | #endif | 534 | #endif |
| @@ -559,12 +569,14 @@ static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | |||
| 559 | } | 569 | } |
| 560 | #endif | 570 | #endif |
| 561 | 571 | ||
| 572 | #ifndef OPENSSL_NO_RSA | ||
| 562 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | 573 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ |
| 563 | static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 574 | static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| 564 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | 575 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) |
| 565 | { | 576 | { |
| 566 | return atalla_mod_exp(r, a, p, m, ctx); | 577 | return atalla_mod_exp(r, a, p, m, ctx); |
| 567 | } | 578 | } |
| 579 | #endif | ||
| 568 | 580 | ||
| 569 | #ifndef OPENSSL_NO_DH | 581 | #ifndef OPENSSL_NO_DH |
| 570 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | 582 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ |
| @@ -578,7 +590,7 @@ static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r, | |||
| 578 | 590 | ||
| 579 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | 591 | /* This stuff is needed if this ENGINE is being compiled into a self-contained |
| 580 | * shared-library. */ | 592 | * shared-library. */ |
| 581 | #ifdef ENGINE_DYNAMIC_SUPPORT | 593 | #ifndef OPENSSL_NO_DYNAMIC_ENGINE |
| 582 | static int bind_fn(ENGINE *e, const char *id) | 594 | static int bind_fn(ENGINE *e, const char *id) |
| 583 | { | 595 | { |
| 584 | if(id && (strcmp(id, engine_atalla_id) != 0)) | 596 | if(id && (strcmp(id, engine_atalla_id) != 0)) |
| @@ -589,7 +601,7 @@ static int bind_fn(ENGINE *e, const char *id) | |||
| 589 | } | 601 | } |
| 590 | IMPLEMENT_DYNAMIC_CHECK_FN() | 602 | IMPLEMENT_DYNAMIC_CHECK_FN() |
| 591 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | 603 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) |
| 592 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | 604 | #endif /* OPENSSL_NO_DYNAMIC_ENGINE */ |
| 593 | 605 | ||
| 594 | #endif /* !OPENSSL_NO_HW_ATALLA */ | 606 | #endif /* !OPENSSL_NO_HW_ATALLA */ |
| 595 | #endif /* !OPENSSL_NO_HW */ | 607 | #endif /* !OPENSSL_NO_HW */ |
diff --git a/src/lib/libcrypto/engine/hw_atalla_err.h b/src/lib/libssl/src/engines/e_atalla_err.h index cdac052d8c..36e09bf42f 100644 --- a/src/lib/libcrypto/engine/hw_atalla_err.h +++ b/src/lib/libssl/src/engines/e_atalla_err.h | |||
| @@ -55,6 +55,10 @@ | |||
| 55 | #ifndef HEADER_ATALLA_ERR_H | 55 | #ifndef HEADER_ATALLA_ERR_H |
| 56 | #define HEADER_ATALLA_ERR_H | 56 | #define HEADER_ATALLA_ERR_H |
| 57 | 57 | ||
| 58 | #ifdef __cplusplus | ||
| 59 | extern "C" { | ||
| 60 | #endif | ||
| 61 | |||
| 58 | /* BEGIN ERROR CODES */ | 62 | /* BEGIN ERROR CODES */ |
| 59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 63 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
| 60 | * made after this point may be overwritten when the script is next run. | 64 | * made after this point may be overwritten when the script is next run. |
diff --git a/src/lib/libcrypto/engine/hw_ncipher_err.c b/src/lib/libssl/src/engines/e_chil_err.c index 5bc94581b7..c5983b2fd5 100644 --- a/src/lib/libcrypto/engine/hw_ncipher_err.c +++ b/src/lib/libssl/src/engines/e_chil_err.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* hw_ncipher_err.c */ | 1 | /* e_chil_err.c */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| @@ -60,42 +60,45 @@ | |||
| 60 | 60 | ||
| 61 | #include <stdio.h> | 61 | #include <stdio.h> |
| 62 | #include <openssl/err.h> | 62 | #include <openssl/err.h> |
| 63 | #include "hw_ncipher_err.h" | 63 | #include "e_chil_err.h" |
| 64 | 64 | ||
| 65 | /* BEGIN ERROR CODES */ | 65 | /* BEGIN ERROR CODES */ |
| 66 | #ifndef OPENSSL_NO_ERR | 66 | #ifndef OPENSSL_NO_ERR |
| 67 | |||
| 68 | #define ERR_FUNC(func) ERR_PACK(0,func,0) | ||
| 69 | #define ERR_REASON(reason) ERR_PACK(0,0,reason) | ||
| 70 | |||
| 67 | static ERR_STRING_DATA HWCRHK_str_functs[]= | 71 | static ERR_STRING_DATA HWCRHK_str_functs[]= |
| 68 | { | 72 | { |
| 69 | {ERR_PACK(0,HWCRHK_F_HWCRHK_CTRL,0), "HWCRHK_CTRL"}, | 73 | {ERR_FUNC(HWCRHK_F_HWCRHK_CTRL), "HWCRHK_CTRL"}, |
| 70 | {ERR_PACK(0,HWCRHK_F_HWCRHK_FINISH,0), "HWCRHK_FINISH"}, | 74 | {ERR_FUNC(HWCRHK_F_HWCRHK_FINISH), "HWCRHK_FINISH"}, |
| 71 | {ERR_PACK(0,HWCRHK_F_HWCRHK_GET_PASS,0), "HWCRHK_GET_PASS"}, | 75 | {ERR_FUNC(HWCRHK_F_HWCRHK_GET_PASS), "HWCRHK_GET_PASS"}, |
| 72 | {ERR_PACK(0,HWCRHK_F_HWCRHK_INIT,0), "HWCRHK_INIT"}, | 76 | {ERR_FUNC(HWCRHK_F_HWCRHK_INIT), "HWCRHK_INIT"}, |
| 73 | {ERR_PACK(0,HWCRHK_F_HWCRHK_INSERT_CARD,0), "HWCRHK_INSERT_CARD"}, | 77 | {ERR_FUNC(HWCRHK_F_HWCRHK_INSERT_CARD), "HWCRHK_INSERT_CARD"}, |
| 74 | {ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PRIVKEY,0), "HWCRHK_LOAD_PRIVKEY"}, | 78 | {ERR_FUNC(HWCRHK_F_HWCRHK_LOAD_PRIVKEY), "HWCRHK_LOAD_PRIVKEY"}, |
| 75 | {ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PUBKEY,0), "HWCRHK_LOAD_PUBKEY"}, | 79 | {ERR_FUNC(HWCRHK_F_HWCRHK_LOAD_PUBKEY), "HWCRHK_LOAD_PUBKEY"}, |
| 76 | {ERR_PACK(0,HWCRHK_F_HWCRHK_MOD_EXP,0), "HWCRHK_MOD_EXP"}, | 80 | {ERR_FUNC(HWCRHK_F_HWCRHK_MOD_EXP), "HWCRHK_MOD_EXP"}, |
| 77 | {ERR_PACK(0,HWCRHK_F_HWCRHK_RAND_BYTES,0), "HWCRHK_RAND_BYTES"}, | 81 | {ERR_FUNC(HWCRHK_F_HWCRHK_RAND_BYTES), "HWCRHK_RAND_BYTES"}, |
| 78 | {ERR_PACK(0,HWCRHK_F_HWCRHK_RSA_MOD_EXP,0), "HWCRHK_RSA_MOD_EXP"}, | 82 | {ERR_FUNC(HWCRHK_F_HWCRHK_RSA_MOD_EXP), "HWCRHK_RSA_MOD_EXP"}, |
| 79 | {0,NULL} | 83 | {0,NULL} |
| 80 | }; | 84 | }; |
| 81 | 85 | ||
| 82 | static ERR_STRING_DATA HWCRHK_str_reasons[]= | 86 | static ERR_STRING_DATA HWCRHK_str_reasons[]= |
| 83 | { | 87 | { |
| 84 | {HWCRHK_R_ALREADY_LOADED ,"already loaded"}, | 88 | {ERR_REASON(HWCRHK_R_ALREADY_LOADED) ,"already loaded"}, |
| 85 | {HWCRHK_R_BIO_WAS_FREED ,"bio was freed"}, | 89 | {ERR_REASON(HWCRHK_R_BIO_WAS_FREED) ,"bio was freed"}, |
| 86 | {HWCRHK_R_CHIL_ERROR ,"chil error"}, | 90 | {ERR_REASON(HWCRHK_R_CHIL_ERROR) ,"chil error"}, |
| 87 | {HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | 91 | {ERR_REASON(HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED),"ctrl command not implemented"}, |
| 88 | {HWCRHK_R_DSO_FAILURE ,"dso failure"}, | 92 | {ERR_REASON(HWCRHK_R_DSO_FAILURE) ,"dso failure"}, |
| 89 | {HWCRHK_R_DYNAMIC_LOCKING_MISSING ,"dynamic locking missing"}, | 93 | {ERR_REASON(HWCRHK_R_MISSING_KEY_COMPONENTS),"missing key components"}, |
| 90 | {HWCRHK_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | 94 | {ERR_REASON(HWCRHK_R_NOT_INITIALISED) ,"not initialised"}, |
| 91 | {HWCRHK_R_NOT_INITIALISED ,"not initialised"}, | 95 | {ERR_REASON(HWCRHK_R_NOT_LOADED) ,"not loaded"}, |
| 92 | {HWCRHK_R_NOT_LOADED ,"not loaded"}, | 96 | {ERR_REASON(HWCRHK_R_NO_CALLBACK) ,"no callback"}, |
| 93 | {HWCRHK_R_NO_CALLBACK ,"no callback"}, | 97 | {ERR_REASON(HWCRHK_R_NO_KEY) ,"no key"}, |
| 94 | {HWCRHK_R_NO_KEY ,"no key"}, | 98 | {ERR_REASON(HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED),"private key algorithms disabled"}, |
| 95 | {HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED,"private key algorithms disabled"}, | 99 | {ERR_REASON(HWCRHK_R_REQUEST_FAILED) ,"request failed"}, |
| 96 | {HWCRHK_R_REQUEST_FAILED ,"request failed"}, | 100 | {ERR_REASON(HWCRHK_R_REQUEST_FALLBACK) ,"request fallback"}, |
| 97 | {HWCRHK_R_REQUEST_FALLBACK ,"request fallback"}, | 101 | {ERR_REASON(HWCRHK_R_UNIT_FAILURE) ,"unit failure"}, |
| 98 | {HWCRHK_R_UNIT_FAILURE ,"unit failure"}, | ||
| 99 | {0,NULL} | 102 | {0,NULL} |
| 100 | }; | 103 | }; |
| 101 | 104 | ||
diff --git a/src/lib/libcrypto/engine/hw_cswift.c b/src/lib/libssl/src/engines/e_cswift.c index 1411fd8333..bc65179846 100644 --- a/src/lib/libcrypto/engine/hw_cswift.c +++ b/src/lib/libssl/src/engines/e_cswift.c | |||
| @@ -57,10 +57,22 @@ | |||
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include <string.h> | ||
| 60 | #include <openssl/crypto.h> | 61 | #include <openssl/crypto.h> |
| 61 | #include "cryptlib.h" | 62 | #include <openssl/buffer.h> |
| 62 | #include <openssl/dso.h> | 63 | #include <openssl/dso.h> |
| 63 | #include <openssl/engine.h> | 64 | #include <openssl/engine.h> |
| 65 | #ifndef OPENSSL_NO_RSA | ||
| 66 | #include <openssl/rsa.h> | ||
| 67 | #endif | ||
| 68 | #ifndef OPENSSL_NO_DSA | ||
| 69 | #include <openssl/dsa.h> | ||
| 70 | #endif | ||
| 71 | #ifndef OPENSSL_NO_DH | ||
| 72 | #include <openssl/dh.h> | ||
| 73 | #endif | ||
| 74 | #include <openssl/rand.h> | ||
| 75 | #include <openssl/bn.h> | ||
| 64 | 76 | ||
| 65 | #ifndef OPENSSL_NO_HW | 77 | #ifndef OPENSSL_NO_HW |
| 66 | #ifndef OPENSSL_NO_HW_CSWIFT | 78 | #ifndef OPENSSL_NO_HW_CSWIFT |
| @@ -84,28 +96,34 @@ | |||
| 84 | #endif | 96 | #endif |
| 85 | 97 | ||
| 86 | #define CSWIFT_LIB_NAME "cswift engine" | 98 | #define CSWIFT_LIB_NAME "cswift engine" |
| 87 | #include "hw_cswift_err.c" | 99 | #include "e_cswift_err.c" |
| 100 | |||
| 101 | #define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1) | ||
| 88 | 102 | ||
| 89 | static int cswift_destroy(ENGINE *e); | 103 | static int cswift_destroy(ENGINE *e); |
| 90 | static int cswift_init(ENGINE *e); | 104 | static int cswift_init(ENGINE *e); |
| 91 | static int cswift_finish(ENGINE *e); | 105 | static int cswift_finish(ENGINE *e); |
| 92 | static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | 106 | static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)); |
| 107 | #ifndef OPENSSL_NO_RSA | ||
| 93 | static int cswift_bn_32copy(SW_LARGENUMBER * out, const BIGNUM * in); | 108 | static int cswift_bn_32copy(SW_LARGENUMBER * out, const BIGNUM * in); |
| 109 | #endif | ||
| 94 | 110 | ||
| 95 | /* BIGNUM stuff */ | 111 | /* BIGNUM stuff */ |
| 96 | static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 112 | static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| 97 | const BIGNUM *m, BN_CTX *ctx); | 113 | const BIGNUM *m, BN_CTX *ctx); |
| 114 | #ifndef OPENSSL_NO_RSA | ||
| 98 | static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 115 | static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| 99 | const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1, | 116 | const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1, |
| 100 | const BIGNUM *iqmp, BN_CTX *ctx); | 117 | const BIGNUM *iqmp, BN_CTX *ctx); |
| 118 | #endif | ||
| 101 | 119 | ||
| 102 | #ifndef OPENSSL_NO_RSA | 120 | #ifndef OPENSSL_NO_RSA |
| 103 | /* RSA stuff */ | 121 | /* RSA stuff */ |
| 104 | static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa); | 122 | static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx); |
| 105 | #endif | ||
| 106 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | 123 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ |
| 107 | static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 124 | static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| 108 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | 125 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); |
| 126 | #endif | ||
| 109 | 127 | ||
| 110 | #ifndef OPENSSL_NO_DSA | 128 | #ifndef OPENSSL_NO_DSA |
| 111 | /* DSA stuff */ | 129 | /* DSA stuff */ |
| @@ -152,6 +170,7 @@ static RSA_METHOD cswift_rsa = | |||
| 152 | 0, | 170 | 0, |
| 153 | NULL, | 171 | NULL, |
| 154 | NULL, | 172 | NULL, |
| 173 | NULL, | ||
| 155 | NULL | 174 | NULL |
| 156 | }; | 175 | }; |
| 157 | #endif | 176 | #endif |
| @@ -169,7 +188,9 @@ static DSA_METHOD cswift_dsa = | |||
| 169 | NULL, /* init */ | 188 | NULL, /* init */ |
| 170 | NULL, /* finish */ | 189 | NULL, /* finish */ |
| 171 | 0, /* flags */ | 190 | 0, /* flags */ |
| 172 | NULL /* app_data */ | 191 | NULL, /* app_data */ |
| 192 | NULL, /* dsa_paramgen */ | ||
| 193 | NULL /* dsa_keygen */ | ||
| 173 | }; | 194 | }; |
| 174 | #endif | 195 | #endif |
| 175 | 196 | ||
| @@ -184,6 +205,7 @@ static DH_METHOD cswift_dh = | |||
| 184 | NULL, | 205 | NULL, |
| 185 | NULL, | 206 | NULL, |
| 186 | 0, | 207 | 0, |
| 208 | NULL, | ||
| 187 | NULL | 209 | NULL |
| 188 | }; | 210 | }; |
| 189 | #endif | 211 | #endif |
| @@ -260,7 +282,7 @@ static int bind_helper(ENGINE *e) | |||
| 260 | return 1; | 282 | return 1; |
| 261 | } | 283 | } |
| 262 | 284 | ||
| 263 | #ifndef ENGINE_DYNAMIC_SUPPORT | 285 | #ifdef OPENSSL_NO_DYNAMIC_ENGINE |
| 264 | static ENGINE *engine_cswift(void) | 286 | static ENGINE *engine_cswift(void) |
| 265 | { | 287 | { |
| 266 | ENGINE *ret = ENGINE_new(); | 288 | ENGINE *ret = ENGINE_new(); |
| @@ -436,7 +458,7 @@ static int cswift_finish(ENGINE *e) | |||
| 436 | return 1; | 458 | return 1; |
| 437 | } | 459 | } |
| 438 | 460 | ||
| 439 | static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | 461 | static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) |
| 440 | { | 462 | { |
| 441 | int initialised = ((cswift_dso == NULL) ? 0 : 1); | 463 | int initialised = ((cswift_dso == NULL) ? 0 : 1); |
| 442 | switch(cmd) | 464 | switch(cmd) |
| @@ -558,6 +580,7 @@ err: | |||
| 558 | } | 580 | } |
| 559 | 581 | ||
| 560 | 582 | ||
| 583 | #ifndef OPENSSL_NO_RSA | ||
| 561 | int cswift_bn_32copy(SW_LARGENUMBER * out, const BIGNUM * in) | 584 | int cswift_bn_32copy(SW_LARGENUMBER * out, const BIGNUM * in) |
| 562 | { | 585 | { |
| 563 | int mod; | 586 | int mod; |
| @@ -579,7 +602,9 @@ int cswift_bn_32copy(SW_LARGENUMBER * out, const BIGNUM * in) | |||
| 579 | 602 | ||
| 580 | return 1; | 603 | return 1; |
| 581 | } | 604 | } |
| 605 | #endif | ||
| 582 | 606 | ||
| 607 | #ifndef OPENSSL_NO_RSA | ||
| 583 | /* Un petit mod_exp chinois */ | 608 | /* Un petit mod_exp chinois */ |
| 584 | static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 609 | static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| 585 | const BIGNUM *q, const BIGNUM *dmp1, | 610 | const BIGNUM *q, const BIGNUM *dmp1, |
| @@ -711,14 +736,20 @@ err: | |||
| 711 | release_context(hac); | 736 | release_context(hac); |
| 712 | return to_return; | 737 | return to_return; |
| 713 | } | 738 | } |
| 739 | #endif | ||
| 714 | 740 | ||
| 715 | #ifndef OPENSSL_NO_RSA | 741 | #ifndef OPENSSL_NO_RSA |
| 716 | static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | 742 | static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) |
| 717 | { | 743 | { |
| 718 | BN_CTX *ctx; | ||
| 719 | int to_return = 0; | 744 | int to_return = 0; |
| 720 | const RSA_METHOD * def_rsa_method; | 745 | const RSA_METHOD * def_rsa_method; |
| 721 | 746 | ||
| 747 | if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) | ||
| 748 | { | ||
| 749 | CSWIFTerr(CSWIFT_F_CSWIFT_RSA_MOD_EXP,CSWIFT_R_MISSING_KEY_COMPONENTS); | ||
| 750 | goto err; | ||
| 751 | } | ||
| 752 | |||
| 722 | /* Try the limits of RSA (2048 bits) */ | 753 | /* Try the limits of RSA (2048 bits) */ |
| 723 | if(BN_num_bytes(rsa->p) > 128 || | 754 | if(BN_num_bytes(rsa->p) > 128 || |
| 724 | BN_num_bytes(rsa->q) > 128 || | 755 | BN_num_bytes(rsa->q) > 128 || |
| @@ -736,24 +767,14 @@ static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | |||
| 736 | #endif | 767 | #endif |
| 737 | #endif | 768 | #endif |
| 738 | if(def_rsa_method) | 769 | if(def_rsa_method) |
| 739 | return def_rsa_method->rsa_mod_exp(r0, I, rsa); | 770 | return def_rsa_method->rsa_mod_exp(r0, I, rsa, ctx); |
| 740 | } | 771 | } |
| 741 | 772 | ||
| 742 | if((ctx = BN_CTX_new()) == NULL) | ||
| 743 | goto err; | ||
| 744 | if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) | ||
| 745 | { | ||
| 746 | CSWIFTerr(CSWIFT_F_CSWIFT_RSA_MOD_EXP,CSWIFT_R_MISSING_KEY_COMPONENTS); | ||
| 747 | goto err; | ||
| 748 | } | ||
| 749 | to_return = cswift_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1, | 773 | to_return = cswift_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1, |
| 750 | rsa->dmq1, rsa->iqmp, ctx); | 774 | rsa->dmq1, rsa->iqmp, ctx); |
| 751 | err: | 775 | err: |
| 752 | if(ctx) | ||
| 753 | BN_CTX_free(ctx); | ||
| 754 | return to_return; | 776 | return to_return; |
| 755 | } | 777 | } |
| 756 | #endif | ||
| 757 | 778 | ||
| 758 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | 779 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ |
| 759 | static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 780 | static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| @@ -781,6 +802,7 @@ static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | |||
| 781 | 802 | ||
| 782 | return cswift_mod_exp(r, a, p, m, ctx); | 803 | return cswift_mod_exp(r, a, p, m, ctx); |
| 783 | } | 804 | } |
| 805 | #endif /* OPENSSL_NO_RSA */ | ||
| 784 | 806 | ||
| 785 | #ifndef OPENSSL_NO_DSA | 807 | #ifndef OPENSSL_NO_DSA |
| 786 | static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa) | 808 | static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa) |
| @@ -1030,7 +1052,7 @@ static int cswift_rand_bytes(unsigned char *buf, int num) | |||
| 1030 | 1052 | ||
| 1031 | if (!get_context(&hac)) | 1053 | if (!get_context(&hac)) |
| 1032 | { | 1054 | { |
| 1033 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_UNIT_FAILURE); | 1055 | CSWIFTerr(CSWIFT_F_CSWIFT_RAND_BYTES, CSWIFT_R_UNIT_FAILURE); |
| 1034 | goto err; | 1056 | goto err; |
| 1035 | } | 1057 | } |
| 1036 | acquired = 1; | 1058 | acquired = 1; |
| @@ -1041,7 +1063,7 @@ static int cswift_rand_bytes(unsigned char *buf, int num) | |||
| 1041 | /* limitation of cswift with values not a multiple of 32 */ | 1063 | /* limitation of cswift with values not a multiple of 32 */ |
| 1042 | /************************************************************************/ | 1064 | /************************************************************************/ |
| 1043 | 1065 | ||
| 1044 | while(num >= sizeof(buf32)) | 1066 | while(num >= (int)sizeof(buf32)) |
| 1045 | { | 1067 | { |
| 1046 | largenum.value = buf; | 1068 | largenum.value = buf; |
| 1047 | largenum.nbytes = sizeof(buf32); | 1069 | largenum.nbytes = sizeof(buf32); |
| @@ -1052,7 +1074,7 @@ static int cswift_rand_bytes(unsigned char *buf, int num) | |||
| 1052 | if (swrc != SW_OK) | 1074 | if (swrc != SW_OK) |
| 1053 | { | 1075 | { |
| 1054 | char tmpbuf[20]; | 1076 | char tmpbuf[20]; |
| 1055 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_REQUEST_FAILED); | 1077 | CSWIFTerr(CSWIFT_F_CSWIFT_RAND_BYTES, CSWIFT_R_REQUEST_FAILED); |
| 1056 | sprintf(tmpbuf, "%ld", swrc); | 1078 | sprintf(tmpbuf, "%ld", swrc); |
| 1057 | ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf); | 1079 | ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf); |
| 1058 | goto err; | 1080 | goto err; |
| @@ -1068,7 +1090,7 @@ static int cswift_rand_bytes(unsigned char *buf, int num) | |||
| 1068 | if (swrc != SW_OK) | 1090 | if (swrc != SW_OK) |
| 1069 | { | 1091 | { |
| 1070 | char tmpbuf[20]; | 1092 | char tmpbuf[20]; |
| 1071 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_REQUEST_FAILED); | 1093 | CSWIFTerr(CSWIFT_F_CSWIFT_RAND_BYTES, CSWIFT_R_REQUEST_FAILED); |
| 1072 | sprintf(tmpbuf, "%ld", swrc); | 1094 | sprintf(tmpbuf, "%ld", swrc); |
| 1073 | ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf); | 1095 | ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf); |
| 1074 | goto err; | 1096 | goto err; |
| @@ -1092,7 +1114,7 @@ static int cswift_rand_status(void) | |||
| 1092 | 1114 | ||
| 1093 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | 1115 | /* This stuff is needed if this ENGINE is being compiled into a self-contained |
| 1094 | * shared-library. */ | 1116 | * shared-library. */ |
| 1095 | #ifdef ENGINE_DYNAMIC_SUPPORT | 1117 | #ifndef OPENSSL_NO_DYNAMIC_ENGINE |
| 1096 | static int bind_fn(ENGINE *e, const char *id) | 1118 | static int bind_fn(ENGINE *e, const char *id) |
| 1097 | { | 1119 | { |
| 1098 | if(id && (strcmp(id, engine_cswift_id) != 0)) | 1120 | if(id && (strcmp(id, engine_cswift_id) != 0)) |
| @@ -1103,7 +1125,7 @@ static int bind_fn(ENGINE *e, const char *id) | |||
| 1103 | } | 1125 | } |
| 1104 | IMPLEMENT_DYNAMIC_CHECK_FN() | 1126 | IMPLEMENT_DYNAMIC_CHECK_FN() |
| 1105 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | 1127 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) |
| 1106 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | 1128 | #endif /* OPENSSL_NO_DYNAMIC_ENGINE */ |
| 1107 | 1129 | ||
| 1108 | #endif /* !OPENSSL_NO_HW_CSWIFT */ | 1130 | #endif /* !OPENSSL_NO_HW_CSWIFT */ |
| 1109 | #endif /* !OPENSSL_NO_HW */ | 1131 | #endif /* !OPENSSL_NO_HW */ |
diff --git a/src/lib/libcrypto/engine/hw_cswift_err.h b/src/lib/libssl/src/engines/e_cswift_err.h index 7120c3216f..69c2a9f874 100644 --- a/src/lib/libcrypto/engine/hw_cswift_err.h +++ b/src/lib/libssl/src/engines/e_cswift_err.h | |||
| @@ -55,6 +55,10 @@ | |||
| 55 | #ifndef HEADER_CSWIFT_ERR_H | 55 | #ifndef HEADER_CSWIFT_ERR_H |
| 56 | #define HEADER_CSWIFT_ERR_H | 56 | #define HEADER_CSWIFT_ERR_H |
| 57 | 57 | ||
| 58 | #ifdef __cplusplus | ||
| 59 | extern "C" { | ||
| 60 | #endif | ||
| 61 | |||
| 58 | /* BEGIN ERROR CODES */ | 62 | /* BEGIN ERROR CODES */ |
| 59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 63 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
| 60 | * made after this point may be overwritten when the script is next run. | 64 | * made after this point may be overwritten when the script is next run. |
| @@ -74,6 +78,7 @@ static void ERR_CSWIFT_error(int function, int reason, char *file, int line); | |||
| 74 | #define CSWIFT_F_CSWIFT_INIT 104 | 78 | #define CSWIFT_F_CSWIFT_INIT 104 |
| 75 | #define CSWIFT_F_CSWIFT_MOD_EXP 105 | 79 | #define CSWIFT_F_CSWIFT_MOD_EXP 105 |
| 76 | #define CSWIFT_F_CSWIFT_MOD_EXP_CRT 106 | 80 | #define CSWIFT_F_CSWIFT_MOD_EXP_CRT 106 |
| 81 | #define CSWIFT_F_CSWIFT_RAND_BYTES 108 | ||
| 77 | #define CSWIFT_F_CSWIFT_RSA_MOD_EXP 107 | 82 | #define CSWIFT_F_CSWIFT_RSA_MOD_EXP 107 |
| 78 | 83 | ||
| 79 | /* Reason codes. */ | 84 | /* Reason codes. */ |
diff --git a/src/lib/libcrypto/engine/hw_nuron_err.h b/src/lib/libssl/src/engines/e_gmp_err.h index a56bfdf303..dd05dfd800 100644 --- a/src/lib/libcrypto/engine/hw_nuron_err.h +++ b/src/lib/libssl/src/engines/e_gmp_err.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* ==================================================================== | 1 | /* ==================================================================== |
| 2 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | 2 | * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved. |
| 3 | * | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without | 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions | 5 | * modification, are permitted provided that the following conditions |
| @@ -52,33 +52,32 @@ | |||
| 52 | * | 52 | * |
| 53 | */ | 53 | */ |
| 54 | 54 | ||
| 55 | #ifndef HEADER_NURON_ERR_H | 55 | #ifndef HEADER_GMP_ERR_H |
| 56 | #define HEADER_NURON_ERR_H | 56 | #define HEADER_GMP_ERR_H |
| 57 | |||
| 58 | #ifdef __cplusplus | ||
| 59 | extern "C" { | ||
| 60 | #endif | ||
| 57 | 61 | ||
| 58 | /* BEGIN ERROR CODES */ | 62 | /* BEGIN ERROR CODES */ |
| 59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 63 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
| 60 | * made after this point may be overwritten when the script is next run. | 64 | * made after this point may be overwritten when the script is next run. |
| 61 | */ | 65 | */ |
| 62 | static void ERR_load_NURON_strings(void); | 66 | static void ERR_load_GMP_strings(void); |
| 63 | static void ERR_unload_NURON_strings(void); | 67 | static void ERR_unload_GMP_strings(void); |
| 64 | static void ERR_NURON_error(int function, int reason, char *file, int line); | 68 | static void ERR_GMP_error(int function, int reason, char *file, int line); |
| 65 | #define NURONerr(f,r) ERR_NURON_error((f),(r),__FILE__,__LINE__) | 69 | #define GMPerr(f,r) ERR_GMP_error((f),(r),__FILE__,__LINE__) |
| 66 | 70 | ||
| 67 | /* Error codes for the NURON functions. */ | 71 | /* Error codes for the GMP functions. */ |
| 68 | 72 | ||
| 69 | /* Function codes. */ | 73 | /* Function codes. */ |
| 70 | #define NURON_F_NURON_CTRL 100 | 74 | #define GMP_F_E_GMP_CTRL 100 |
| 71 | #define NURON_F_NURON_FINISH 101 | 75 | #define GMP_F_E_GMP_RSA_MOD_EXP 101 |
| 72 | #define NURON_F_NURON_INIT 102 | ||
| 73 | #define NURON_F_NURON_MOD_EXP 103 | ||
| 74 | 76 | ||
| 75 | /* Reason codes. */ | 77 | /* Reason codes. */ |
| 76 | #define NURON_R_ALREADY_LOADED 100 | 78 | #define GMP_R_CTRL_COMMAND_NOT_IMPLEMENTED 100 |
| 77 | #define NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED 101 | 79 | #define GMP_R_KEY_CONTEXT_ERROR 101 |
| 78 | #define NURON_R_DSO_FAILURE 102 | 80 | #define GMP_R_MISSING_KEY_COMPONENTS 102 |
| 79 | #define NURON_R_DSO_FUNCTION_NOT_FOUND 103 | ||
| 80 | #define NURON_R_DSO_NOT_FOUND 104 | ||
| 81 | #define NURON_R_NOT_LOADED 105 | ||
| 82 | 81 | ||
| 83 | #ifdef __cplusplus | 82 | #ifdef __cplusplus |
| 84 | } | 83 | } |
diff --git a/src/lib/libcrypto/engine/hw_nuron.c b/src/lib/libssl/src/engines/e_nuron.c index fb9188bfe5..4c2537cbc3 100644 --- a/src/lib/libcrypto/engine/hw_nuron.c +++ b/src/lib/libssl/src/engines/e_nuron.c | |||
| @@ -57,17 +57,27 @@ | |||
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include <string.h> | ||
| 60 | #include <openssl/crypto.h> | 61 | #include <openssl/crypto.h> |
| 61 | #include "cryptlib.h" | 62 | #include <openssl/buffer.h> |
| 62 | #include <openssl/dso.h> | 63 | #include <openssl/dso.h> |
| 63 | #include <openssl/engine.h> | 64 | #include <openssl/engine.h> |
| 64 | 65 | #ifndef OPENSSL_NO_RSA | |
| 66 | #include <openssl/rsa.h> | ||
| 67 | #endif | ||
| 68 | #ifndef OPENSSL_NO_DSA | ||
| 69 | #include <openssl/dsa.h> | ||
| 70 | #endif | ||
| 71 | #ifndef OPENSSL_NO_DH | ||
| 72 | #include <openssl/dh.h> | ||
| 73 | #endif | ||
| 74 | #include <openssl/bn.h> | ||
| 65 | 75 | ||
| 66 | #ifndef OPENSSL_NO_HW | 76 | #ifndef OPENSSL_NO_HW |
| 67 | #ifndef OPENSSL_NO_HW_NURON | 77 | #ifndef OPENSSL_NO_HW_NURON |
| 68 | 78 | ||
| 69 | #define NURON_LIB_NAME "nuron engine" | 79 | #define NURON_LIB_NAME "nuron engine" |
| 70 | #include "hw_nuron_err.c" | 80 | #include "e_nuron_err.c" |
| 71 | 81 | ||
| 72 | static const char *NURON_LIBNAME = NULL; | 82 | static const char *NURON_LIBNAME = NULL; |
| 73 | static const char *get_NURON_LIBNAME(void) | 83 | static const char *get_NURON_LIBNAME(void) |
| @@ -155,7 +165,7 @@ static int nuron_finish(ENGINE *e) | |||
| 155 | return 1; | 165 | return 1; |
| 156 | } | 166 | } |
| 157 | 167 | ||
| 158 | static int nuron_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | 168 | static int nuron_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) |
| 159 | { | 169 | { |
| 160 | int initialised = ((pvDSOHandle == NULL) ? 0 : 1); | 170 | int initialised = ((pvDSOHandle == NULL) ? 0 : 1); |
| 161 | switch(cmd) | 171 | switch(cmd) |
| @@ -191,9 +201,9 @@ static int nuron_mod_exp(BIGNUM *r,const BIGNUM *a,const BIGNUM *p, | |||
| 191 | } | 201 | } |
| 192 | 202 | ||
| 193 | #ifndef OPENSSL_NO_RSA | 203 | #ifndef OPENSSL_NO_RSA |
| 194 | static int nuron_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | 204 | static int nuron_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) |
| 195 | { | 205 | { |
| 196 | return nuron_mod_exp(r0,I,rsa->d,rsa->n,NULL); | 206 | return nuron_mod_exp(r0,I,rsa->d,rsa->n,ctx); |
| 197 | } | 207 | } |
| 198 | #endif | 208 | #endif |
| 199 | 209 | ||
| @@ -238,11 +248,13 @@ static int nuron_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | |||
| 238 | #endif | 248 | #endif |
| 239 | 249 | ||
| 240 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | 250 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ |
| 251 | #ifndef OPENSSL_NO_RSA | ||
| 241 | static int nuron_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | 252 | static int nuron_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, |
| 242 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | 253 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) |
| 243 | { | 254 | { |
| 244 | return nuron_mod_exp(r, a, p, m, ctx); | 255 | return nuron_mod_exp(r, a, p, m, ctx); |
| 245 | } | 256 | } |
| 257 | #endif | ||
| 246 | 258 | ||
| 247 | #ifndef OPENSSL_NO_DH | 259 | #ifndef OPENSSL_NO_DH |
| 248 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | 260 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ |
| @@ -269,6 +281,7 @@ static RSA_METHOD nuron_rsa = | |||
| 269 | 0, | 281 | 0, |
| 270 | NULL, | 282 | NULL, |
| 271 | NULL, | 283 | NULL, |
| 284 | NULL, | ||
| 272 | NULL | 285 | NULL |
| 273 | }; | 286 | }; |
| 274 | #endif | 287 | #endif |
| @@ -285,7 +298,9 @@ static DSA_METHOD nuron_dsa = | |||
| 285 | NULL, /* init */ | 298 | NULL, /* init */ |
| 286 | NULL, /* finish */ | 299 | NULL, /* finish */ |
| 287 | 0, /* flags */ | 300 | 0, /* flags */ |
| 288 | NULL /* app_data */ | 301 | NULL, /* app_data */ |
| 302 | NULL, /* dsa_paramgen */ | ||
| 303 | NULL /* dsa_keygen */ | ||
| 289 | }; | 304 | }; |
| 290 | #endif | 305 | #endif |
| 291 | 306 | ||
| @@ -299,6 +314,7 @@ static DH_METHOD nuron_dh = | |||
| 299 | NULL, | 314 | NULL, |
| 300 | NULL, | 315 | NULL, |
| 301 | 0, | 316 | 0, |
| 317 | NULL, | ||
| 302 | NULL | 318 | NULL |
| 303 | }; | 319 | }; |
| 304 | #endif | 320 | #endif |
| @@ -374,7 +390,7 @@ static int bind_helper(ENGINE *e) | |||
| 374 | return 1; | 390 | return 1; |
| 375 | } | 391 | } |
| 376 | 392 | ||
| 377 | #ifndef ENGINE_DYNAMIC_SUPPORT | 393 | #ifdef OPENSSL_NO_DYNAMIC_ENGINE |
| 378 | static ENGINE *engine_nuron(void) | 394 | static ENGINE *engine_nuron(void) |
| 379 | { | 395 | { |
| 380 | ENGINE *ret = ENGINE_new(); | 396 | ENGINE *ret = ENGINE_new(); |
| @@ -401,7 +417,7 @@ void ENGINE_load_nuron(void) | |||
| 401 | 417 | ||
| 402 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | 418 | /* This stuff is needed if this ENGINE is being compiled into a self-contained |
| 403 | * shared-library. */ | 419 | * shared-library. */ |
| 404 | #ifdef ENGINE_DYNAMIC_SUPPORT | 420 | #ifndef OPENSSL_NO_DYNAMIC_ENGINE |
| 405 | static int bind_fn(ENGINE *e, const char *id) | 421 | static int bind_fn(ENGINE *e, const char *id) |
| 406 | { | 422 | { |
| 407 | if(id && (strcmp(id, engine_nuron_id) != 0)) | 423 | if(id && (strcmp(id, engine_nuron_id) != 0)) |
| @@ -412,7 +428,7 @@ static int bind_fn(ENGINE *e, const char *id) | |||
| 412 | } | 428 | } |
| 413 | IMPLEMENT_DYNAMIC_CHECK_FN() | 429 | IMPLEMENT_DYNAMIC_CHECK_FN() |
| 414 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | 430 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) |
| 415 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | 431 | #endif /* OPENSSL_NO_DYNAMIC_ENGINE */ |
| 416 | 432 | ||
| 417 | #endif /* !OPENSSL_NO_HW_NURON */ | 433 | #endif /* !OPENSSL_NO_HW_NURON */ |
| 418 | #endif /* !OPENSSL_NO_HW */ | 434 | #endif /* !OPENSSL_NO_HW */ |
diff --git a/src/lib/libcrypto/engine/hw_nuron_err.c b/src/lib/libssl/src/engines/e_nuron_err.c index df9d7bde76..9a7864f42f 100644 --- a/src/lib/libcrypto/engine/hw_nuron_err.c +++ b/src/lib/libssl/src/engines/e_nuron_err.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* hw_nuron_err.c */ | 1 | /* e_nuron_err.c */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| @@ -60,27 +60,31 @@ | |||
| 60 | 60 | ||
| 61 | #include <stdio.h> | 61 | #include <stdio.h> |
| 62 | #include <openssl/err.h> | 62 | #include <openssl/err.h> |
| 63 | #include "hw_nuron_err.h" | 63 | #include "e_nuron_err.h" |
| 64 | 64 | ||
| 65 | /* BEGIN ERROR CODES */ | 65 | /* BEGIN ERROR CODES */ |
| 66 | #ifndef OPENSSL_NO_ERR | 66 | #ifndef OPENSSL_NO_ERR |
| 67 | |||
| 68 | #define ERR_FUNC(func) ERR_PACK(0,func,0) | ||
| 69 | #define ERR_REASON(reason) ERR_PACK(0,0,reason) | ||
| 70 | |||
| 67 | static ERR_STRING_DATA NURON_str_functs[]= | 71 | static ERR_STRING_DATA NURON_str_functs[]= |
| 68 | { | 72 | { |
| 69 | {ERR_PACK(0,NURON_F_NURON_CTRL,0), "NURON_CTRL"}, | 73 | {ERR_FUNC(NURON_F_NURON_CTRL), "NURON_CTRL"}, |
| 70 | {ERR_PACK(0,NURON_F_NURON_FINISH,0), "NURON_FINISH"}, | 74 | {ERR_FUNC(NURON_F_NURON_FINISH), "NURON_FINISH"}, |
| 71 | {ERR_PACK(0,NURON_F_NURON_INIT,0), "NURON_INIT"}, | 75 | {ERR_FUNC(NURON_F_NURON_INIT), "NURON_INIT"}, |
| 72 | {ERR_PACK(0,NURON_F_NURON_MOD_EXP,0), "NURON_MOD_EXP"}, | 76 | {ERR_FUNC(NURON_F_NURON_MOD_EXP), "NURON_MOD_EXP"}, |
| 73 | {0,NULL} | 77 | {0,NULL} |
| 74 | }; | 78 | }; |
| 75 | 79 | ||
| 76 | static ERR_STRING_DATA NURON_str_reasons[]= | 80 | static ERR_STRING_DATA NURON_str_reasons[]= |
| 77 | { | 81 | { |
| 78 | {NURON_R_ALREADY_LOADED ,"already loaded"}, | 82 | {ERR_REASON(NURON_R_ALREADY_LOADED) ,"already loaded"}, |
| 79 | {NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | 83 | {ERR_REASON(NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED),"ctrl command not implemented"}, |
| 80 | {NURON_R_DSO_FAILURE ,"dso failure"}, | 84 | {ERR_REASON(NURON_R_DSO_FAILURE) ,"dso failure"}, |
| 81 | {NURON_R_DSO_FUNCTION_NOT_FOUND ,"dso function not found"}, | 85 | {ERR_REASON(NURON_R_DSO_FUNCTION_NOT_FOUND),"dso function not found"}, |
| 82 | {NURON_R_DSO_NOT_FOUND ,"dso not found"}, | 86 | {ERR_REASON(NURON_R_DSO_NOT_FOUND) ,"dso not found"}, |
| 83 | {NURON_R_NOT_LOADED ,"not loaded"}, | 87 | {ERR_REASON(NURON_R_NOT_LOADED) ,"not loaded"}, |
| 84 | {0,NULL} | 88 | {0,NULL} |
| 85 | }; | 89 | }; |
| 86 | 90 | ||
diff --git a/src/lib/libcrypto/engine/hw_sureware_err.c b/src/lib/libssl/src/engines/e_sureware_err.c index 69955dadbb..d4ca68c1db 100644 --- a/src/lib/libcrypto/engine/hw_sureware_err.c +++ b/src/lib/libssl/src/engines/e_sureware_err.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* hw_sureware_err.c */ | 1 | /* e_sureware_err.c */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| @@ -60,35 +60,43 @@ | |||
| 60 | 60 | ||
| 61 | #include <stdio.h> | 61 | #include <stdio.h> |
| 62 | #include <openssl/err.h> | 62 | #include <openssl/err.h> |
| 63 | #include "hw_sureware_err.h" | 63 | #include "e_sureware_err.h" |
| 64 | 64 | ||
| 65 | /* BEGIN ERROR CODES */ | 65 | /* BEGIN ERROR CODES */ |
| 66 | #ifndef OPENSSL_NO_ERR | 66 | #ifndef OPENSSL_NO_ERR |
| 67 | |||
| 68 | #define ERR_FUNC(func) ERR_PACK(0,func,0) | ||
| 69 | #define ERR_REASON(reason) ERR_PACK(0,0,reason) | ||
| 70 | |||
| 67 | static ERR_STRING_DATA SUREWARE_str_functs[]= | 71 | static ERR_STRING_DATA SUREWARE_str_functs[]= |
| 68 | { | 72 | { |
| 69 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_CTRL,0), "SUREWAREHK_CTRL"}, | 73 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_CTRL), "SUREWAREHK_CTRL"}, |
| 70 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,0), "SUREWAREHK_DSA_DO_SIGN"}, | 74 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_DH_EX_FREE), "SUREWAREHK_DH_EX_FREE"}, |
| 71 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_EX_FREE,0), "SUREWAREHK_EX_FREE"}, | 75 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN), "SUREWAREHK_DSA_DO_SIGN"}, |
| 72 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_FINISH,0), "SUREWAREHK_FINISH"}, | 76 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_EX_FREE), "SUREWAREHK_EX_FREE"}, |
| 73 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_INIT,0), "SUREWAREHK_INIT"}, | 77 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_FINISH), "SUREWAREHK_FINISH"}, |
| 74 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,0), "SUREWAREHK_LOAD_PRIVATE_KEY"}, | 78 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_INIT), "SUREWAREHK_INIT"}, |
| 75 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,0), "SUREWAREHK_LOAD_PUBLIC_KEY"}, | 79 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_LOAD_PRIVKEY), "SUREWAREHK_LOAD_PRIVKEY"}, |
| 76 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_MOD_EXP,0), "SUREWAREHK_MOD_EXP"}, | 80 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_LOAD_PUBKEY), "SUREWAREHK_LOAD_PUBKEY"}, |
| 77 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_BYTES,0), "SUREWAREHK_RAND_BYTES"}, | 81 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_MODEXP), "SUREWAREHK_MODEXP"}, |
| 78 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_SEED,0), "SUREWAREHK_RAND_SEED"}, | 82 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_RAND_BYTES), "SUREWAREHK_RAND_BYTES"}, |
| 79 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,0), "SUREWAREHK_RSA_PRIV_DEC"}, | 83 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_RAND_SEED), "SUREWAREHK_RAND_SEED"}, |
| 80 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,0), "SUREWAREHK_RSA_PRIV_ENC"}, | 84 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC), "SUREWAREHK_RSA_PRIV_DEC"}, |
| 85 | {ERR_FUNC(SUREWARE_F_SUREWAREHK_RSA_SIGN), "SUREWAREHK_RSA_SIGN"}, | ||
| 86 | {ERR_FUNC(SUREWARE_F_SUREWARE_LOAD_PUBLIC), "SUREWARE_LOAD_PUBLIC"}, | ||
| 81 | {0,NULL} | 87 | {0,NULL} |
| 82 | }; | 88 | }; |
| 83 | 89 | ||
| 84 | static ERR_STRING_DATA SUREWARE_str_reasons[]= | 90 | static ERR_STRING_DATA SUREWARE_str_reasons[]= |
| 85 | { | 91 | { |
| 86 | {SUREWARE_R_BIO_WAS_FREED ,"bio was freed"}, | 92 | {ERR_REASON(SUREWARE_R_BIO_WAS_FREED) ,"bio was freed"}, |
| 87 | {SUREWARE_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | 93 | {ERR_REASON(SUREWARE_R_MISSING_KEY_COMPONENTS),"missing key components"}, |
| 88 | {SUREWARE_R_REQUEST_FAILED ,"request failed"}, | 94 | {ERR_REASON(SUREWARE_R_PADDING_CHECK_FAILED),"padding check failed"}, |
| 89 | {SUREWARE_R_REQUEST_FALLBACK ,"request fallback"}, | 95 | {ERR_REASON(SUREWARE_R_REQUEST_FAILED) ,"request failed"}, |
| 90 | {SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"}, | 96 | {ERR_REASON(SUREWARE_R_REQUEST_FALLBACK) ,"request fallback"}, |
| 91 | {SUREWARE_R_UNIT_FAILURE ,"unit failure"}, | 97 | {ERR_REASON(SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL),"size too large or too small"}, |
| 98 | {ERR_REASON(SUREWARE_R_UNIT_FAILURE) ,"unit failure"}, | ||
| 99 | {ERR_REASON(SUREWARE_R_UNKNOWN_PADDING_TYPE),"unknown padding type"}, | ||
| 92 | {0,NULL} | 100 | {0,NULL} |
| 93 | }; | 101 | }; |
| 94 | 102 | ||
diff --git a/src/lib/libcrypto/engine/hw_ubsec_err.c b/src/lib/libssl/src/engines/e_ubsec_err.c index d707331fc2..14c3d61e24 100644 --- a/src/lib/libcrypto/engine/hw_ubsec_err.c +++ b/src/lib/libssl/src/engines/e_ubsec_err.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* hw_ubsec_err.c */ | 1 | /* e_ubsec_err.c */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| @@ -60,36 +60,42 @@ | |||
| 60 | 60 | ||
| 61 | #include <stdio.h> | 61 | #include <stdio.h> |
| 62 | #include <openssl/err.h> | 62 | #include <openssl/err.h> |
| 63 | #include "hw_ubsec_err.h" | 63 | #include "e_ubsec_err.h" |
| 64 | 64 | ||
| 65 | /* BEGIN ERROR CODES */ | 65 | /* BEGIN ERROR CODES */ |
| 66 | #ifndef OPENSSL_NO_ERR | 66 | #ifndef OPENSSL_NO_ERR |
| 67 | |||
| 68 | #define ERR_FUNC(func) ERR_PACK(0,func,0) | ||
| 69 | #define ERR_REASON(reason) ERR_PACK(0,0,reason) | ||
| 70 | |||
| 67 | static ERR_STRING_DATA UBSEC_str_functs[]= | 71 | static ERR_STRING_DATA UBSEC_str_functs[]= |
| 68 | { | 72 | { |
| 69 | {ERR_PACK(0,UBSEC_F_UBSEC_CTRL,0), "UBSEC_CTRL"}, | 73 | {ERR_FUNC(UBSEC_F_UBSEC_CTRL), "UBSEC_CTRL"}, |
| 70 | {ERR_PACK(0,UBSEC_F_UBSEC_DH_COMPUTE_KEY,0), "UBSEC_DH_COMPUTE_KEY"}, | 74 | {ERR_FUNC(UBSEC_F_UBSEC_DH_COMPUTE_KEY), "UBSEC_DH_COMPUTE_KEY"}, |
| 71 | {ERR_PACK(0,UBSEC_F_UBSEC_DSA_SIGN,0), "UBSEC_DSA_SIGN"}, | 75 | {ERR_FUNC(UBSEC_F_UBSEC_DH_GENERATE_KEY), "UBSEC_DH_GENERATE_KEY"}, |
| 72 | {ERR_PACK(0,UBSEC_F_UBSEC_DSA_VERIFY,0), "UBSEC_DSA_VERIFY"}, | 76 | {ERR_FUNC(UBSEC_F_UBSEC_DSA_DO_SIGN), "UBSEC_DSA_DO_SIGN"}, |
| 73 | {ERR_PACK(0,UBSEC_F_UBSEC_FINISH,0), "UBSEC_FINISH"}, | 77 | {ERR_FUNC(UBSEC_F_UBSEC_DSA_VERIFY), "UBSEC_DSA_VERIFY"}, |
| 74 | {ERR_PACK(0,UBSEC_F_UBSEC_INIT,0), "UBSEC_INIT"}, | 78 | {ERR_FUNC(UBSEC_F_UBSEC_FINISH), "UBSEC_FINISH"}, |
| 75 | {ERR_PACK(0,UBSEC_F_UBSEC_MOD_EXP,0), "UBSEC_MOD_EXP"}, | 79 | {ERR_FUNC(UBSEC_F_UBSEC_INIT), "UBSEC_INIT"}, |
| 76 | {ERR_PACK(0,UBSEC_F_UBSEC_RNG_BYTES,0), "UBSEC_RNG_BYTES"}, | 80 | {ERR_FUNC(UBSEC_F_UBSEC_MOD_EXP), "UBSEC_MOD_EXP"}, |
| 77 | {ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP,0), "UBSEC_RSA_MOD_EXP"}, | 81 | {ERR_FUNC(UBSEC_F_UBSEC_MOD_EXP_CRT), "UBSEC_MOD_EXP_CRT"}, |
| 78 | {ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP_CRT,0), "UBSEC_RSA_MOD_EXP_CRT"}, | 82 | {ERR_FUNC(UBSEC_F_UBSEC_RAND_BYTES), "UBSEC_RAND_BYTES"}, |
| 83 | {ERR_FUNC(UBSEC_F_UBSEC_RSA_MOD_EXP), "UBSEC_RSA_MOD_EXP"}, | ||
| 84 | {ERR_FUNC(UBSEC_F_UBSEC_RSA_MOD_EXP_CRT), "UBSEC_RSA_MOD_EXP_CRT"}, | ||
| 79 | {0,NULL} | 85 | {0,NULL} |
| 80 | }; | 86 | }; |
| 81 | 87 | ||
| 82 | static ERR_STRING_DATA UBSEC_str_reasons[]= | 88 | static ERR_STRING_DATA UBSEC_str_reasons[]= |
| 83 | { | 89 | { |
| 84 | {UBSEC_R_ALREADY_LOADED ,"already loaded"}, | 90 | {ERR_REASON(UBSEC_R_ALREADY_LOADED) ,"already loaded"}, |
| 85 | {UBSEC_R_BN_EXPAND_FAIL ,"bn expand fail"}, | 91 | {ERR_REASON(UBSEC_R_BN_EXPAND_FAIL) ,"bn expand fail"}, |
| 86 | {UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | 92 | {ERR_REASON(UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED),"ctrl command not implemented"}, |
| 87 | {UBSEC_R_DSO_FAILURE ,"dso failure"}, | 93 | {ERR_REASON(UBSEC_R_DSO_FAILURE) ,"dso failure"}, |
| 88 | {UBSEC_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | 94 | {ERR_REASON(UBSEC_R_MISSING_KEY_COMPONENTS),"missing key components"}, |
| 89 | {UBSEC_R_NOT_LOADED ,"not loaded"}, | 95 | {ERR_REASON(UBSEC_R_NOT_LOADED) ,"not loaded"}, |
| 90 | {UBSEC_R_REQUEST_FAILED ,"request failed"}, | 96 | {ERR_REASON(UBSEC_R_REQUEST_FAILED) ,"request failed"}, |
| 91 | {UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"}, | 97 | {ERR_REASON(UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL),"size too large or too small"}, |
| 92 | {UBSEC_R_UNIT_FAILURE ,"unit failure"}, | 98 | {ERR_REASON(UBSEC_R_UNIT_FAILURE) ,"unit failure"}, |
| 93 | {0,NULL} | 99 | {0,NULL} |
| 94 | }; | 100 | }; |
| 95 | 101 | ||
diff --git a/src/lib/libcrypto/engine/hw_ubsec_err.h b/src/lib/libssl/src/engines/e_ubsec_err.h index 023d3be771..b10b2387f2 100644 --- a/src/lib/libcrypto/engine/hw_ubsec_err.h +++ b/src/lib/libssl/src/engines/e_ubsec_err.h | |||
| @@ -55,6 +55,10 @@ | |||
| 55 | #ifndef HEADER_UBSEC_ERR_H | 55 | #ifndef HEADER_UBSEC_ERR_H |
| 56 | #define HEADER_UBSEC_ERR_H | 56 | #define HEADER_UBSEC_ERR_H |
| 57 | 57 | ||
| 58 | #ifdef __cplusplus | ||
| 59 | extern "C" { | ||
| 60 | #endif | ||
| 61 | |||
| 58 | /* BEGIN ERROR CODES */ | 62 | /* BEGIN ERROR CODES */ |
| 59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 63 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
| 60 | * made after this point may be overwritten when the script is next run. | 64 | * made after this point may be overwritten when the script is next run. |
| @@ -69,12 +73,14 @@ static void ERR_UBSEC_error(int function, int reason, char *file, int line); | |||
| 69 | /* Function codes. */ | 73 | /* Function codes. */ |
| 70 | #define UBSEC_F_UBSEC_CTRL 100 | 74 | #define UBSEC_F_UBSEC_CTRL 100 |
| 71 | #define UBSEC_F_UBSEC_DH_COMPUTE_KEY 101 | 75 | #define UBSEC_F_UBSEC_DH_COMPUTE_KEY 101 |
| 72 | #define UBSEC_F_UBSEC_DSA_SIGN 102 | 76 | #define UBSEC_F_UBSEC_DH_GENERATE_KEY 111 |
| 77 | #define UBSEC_F_UBSEC_DSA_DO_SIGN 102 | ||
| 73 | #define UBSEC_F_UBSEC_DSA_VERIFY 103 | 78 | #define UBSEC_F_UBSEC_DSA_VERIFY 103 |
| 74 | #define UBSEC_F_UBSEC_FINISH 104 | 79 | #define UBSEC_F_UBSEC_FINISH 104 |
| 75 | #define UBSEC_F_UBSEC_INIT 105 | 80 | #define UBSEC_F_UBSEC_INIT 105 |
| 76 | #define UBSEC_F_UBSEC_MOD_EXP 106 | 81 | #define UBSEC_F_UBSEC_MOD_EXP 106 |
| 77 | #define UBSEC_F_UBSEC_RNG_BYTES 107 | 82 | #define UBSEC_F_UBSEC_MOD_EXP_CRT 110 |
| 83 | #define UBSEC_F_UBSEC_RAND_BYTES 107 | ||
| 78 | #define UBSEC_F_UBSEC_RSA_MOD_EXP 108 | 84 | #define UBSEC_F_UBSEC_RSA_MOD_EXP 108 |
| 79 | #define UBSEC_F_UBSEC_RSA_MOD_EXP_CRT 109 | 85 | #define UBSEC_F_UBSEC_RSA_MOD_EXP_CRT 109 |
| 80 | 86 | ||
diff --git a/src/lib/libcrypto/engine/vendor_defns/aep.h b/src/lib/libssl/src/engines/vendor_defns/aep.h index 2b2792d2d6..5e9754fe43 100644 --- a/src/lib/libcrypto/engine/vendor_defns/aep.h +++ b/src/lib/libssl/src/engines/vendor_defns/aep.h | |||
| @@ -171,8 +171,8 @@ typedef AEP_RV t_AEP_GenRandom(AEP_CONNECTION_HNDL hConnection, | |||
| 171 | #endif | 171 | #endif |
| 172 | 172 | ||
| 173 | typedef AEP_RV t_AEP_Initialize(AEP_VOID_PTR pInitArgs); | 173 | typedef AEP_RV t_AEP_Initialize(AEP_VOID_PTR pInitArgs); |
| 174 | typedef AEP_RV t_AEP_Finalize(); | 174 | typedef AEP_RV t_AEP_Finalize(void); |
| 175 | typedef AEP_RV t_AEP_SetBNCallBacks(AEP_RV (*GetBigNumSizeFunc)(), | 175 | typedef AEP_RV t_AEP_SetBNCallBacks(AEP_RV (*GetBigNumSizeFunc)(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize), |
| 176 | AEP_RV (*MakeAEPBigNumFunc)(), | 176 | AEP_RV (*MakeAEPBigNumFunc)(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize, unsigned char* AEP_BigNum), |
| 177 | AEP_RV (*ConverAEPBigNumFunc)()); | 177 | AEP_RV (*ConverAEPBigNumFunc)(void* ArbBigNum, AEP_U32 BigNumSize, unsigned char* AEP_BigNum)); |
| 178 | 178 | ||
diff --git a/src/lib/libcrypto/engine/vendor_defns/atalla.h b/src/lib/libssl/src/engines/vendor_defns/atalla.h index 149970d441..149970d441 100644 --- a/src/lib/libcrypto/engine/vendor_defns/atalla.h +++ b/src/lib/libssl/src/engines/vendor_defns/atalla.h | |||
diff --git a/src/lib/libcrypto/engine/vendor_defns/cswift.h b/src/lib/libssl/src/engines/vendor_defns/cswift.h index 60079326bb..60079326bb 100644 --- a/src/lib/libcrypto/engine/vendor_defns/cswift.h +++ b/src/lib/libssl/src/engines/vendor_defns/cswift.h | |||
diff --git a/src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h b/src/lib/libssl/src/engines/vendor_defns/hw_4758_cca.h index 296636e81a..296636e81a 100644 --- a/src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h +++ b/src/lib/libssl/src/engines/vendor_defns/hw_4758_cca.h | |||
diff --git a/src/lib/libcrypto/engine/vendor_defns/hw_ubsec.h b/src/lib/libssl/src/engines/vendor_defns/hw_ubsec.h index b6619d40f2..b6619d40f2 100644 --- a/src/lib/libcrypto/engine/vendor_defns/hw_ubsec.h +++ b/src/lib/libssl/src/engines/vendor_defns/hw_ubsec.h | |||
diff --git a/src/lib/libcrypto/engine/vendor_defns/hwcryptohook.h b/src/lib/libssl/src/engines/vendor_defns/hwcryptohook.h index aaa4d4575e..3c32feda62 100644 --- a/src/lib/libcrypto/engine/vendor_defns/hwcryptohook.h +++ b/src/lib/libssl/src/engines/vendor_defns/hwcryptohook.h | |||
| @@ -65,7 +65,7 @@ | |||
| 65 | * please contact nCipher. | 65 | * please contact nCipher. |
| 66 | * | 66 | * |
| 67 | * | 67 | * |
| 68 | * $Id: hwcryptohook.h,v 1.1.1.1 2003/05/11 21:35:16 markus Exp $ | 68 | * $Id: hwcryptohook.h,v 1.1.1.1 2008/09/06 12:15:50 djm Exp $ |
| 69 | */ | 69 | */ |
| 70 | 70 | ||
| 71 | #ifndef HWCRYPTOHOOK_H | 71 | #ifndef HWCRYPTOHOOK_H |
