diff options
author | beck <> | 2002-05-15 02:29:21 +0000 |
---|---|---|
committer | beck <> | 2002-05-15 02:29:21 +0000 |
commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/evp/evp_key.c | |
parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/evp/evp_key.c')
-rw-r--r-- | src/lib/libcrypto/evp/evp_key.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c index e7434ef9b2..4271393069 100644 --- a/src/lib/libcrypto/evp/evp_key.c +++ b/src/lib/libcrypto/evp/evp_key.c | |||
@@ -61,6 +61,7 @@ | |||
61 | #include <openssl/x509.h> | 61 | #include <openssl/x509.h> |
62 | #include <openssl/objects.h> | 62 | #include <openssl/objects.h> |
63 | #include <openssl/evp.h> | 63 | #include <openssl/evp.h> |
64 | #include <openssl/ui.h> | ||
64 | 65 | ||
65 | /* should be init to zeros. */ | 66 | /* should be init to zeros. */ |
66 | static char prompt_string[80]; | 67 | static char prompt_string[80]; |
@@ -70,7 +71,10 @@ void EVP_set_pw_prompt(char *prompt) | |||
70 | if (prompt == NULL) | 71 | if (prompt == NULL) |
71 | prompt_string[0]='\0'; | 72 | prompt_string[0]='\0'; |
72 | else | 73 | else |
74 | { | ||
73 | strncpy(prompt_string,prompt,79); | 75 | strncpy(prompt_string,prompt,79); |
76 | prompt_string[79]='\0'; | ||
77 | } | ||
74 | } | 78 | } |
75 | 79 | ||
76 | char *EVP_get_pw_prompt(void) | 80 | char *EVP_get_pw_prompt(void) |
@@ -86,18 +90,26 @@ char *EVP_get_pw_prompt(void) | |||
86 | * this function will fail */ | 90 | * this function will fail */ |
87 | int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify) | 91 | int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify) |
88 | { | 92 | { |
89 | #ifndef NO_DES | 93 | int ret; |
94 | char buff[BUFSIZ]; | ||
95 | UI *ui; | ||
96 | |||
90 | if ((prompt == NULL) && (prompt_string[0] != '\0')) | 97 | if ((prompt == NULL) && (prompt_string[0] != '\0')) |
91 | prompt=prompt_string; | 98 | prompt=prompt_string; |
92 | return(des_read_pw_string(buf,len,prompt,verify)); | 99 | ui = UI_new(); |
93 | #else | 100 | UI_add_input_string(ui,prompt,0,buf,0,(len>=BUFSIZ)?BUFSIZ-1:len); |
94 | return -1; | 101 | if (verify) |
95 | #endif | 102 | UI_add_verify_string(ui,prompt,0, |
103 | buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf); | ||
104 | ret = UI_process(ui); | ||
105 | UI_free(ui); | ||
106 | memset(buff,0,BUFSIZ); | ||
107 | return ret; | ||
96 | } | 108 | } |
97 | 109 | ||
98 | int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, | 110 | int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, |
99 | const unsigned char *salt, const unsigned char *data, int datal, | 111 | const unsigned char *salt, const unsigned char *data, int datal, |
100 | int count, unsigned char *key, unsigned char *iv) | 112 | int count, unsigned char *key, unsigned char *iv) |
101 | { | 113 | { |
102 | EVP_MD_CTX c; | 114 | EVP_MD_CTX c; |
103 | unsigned char md_buf[EVP_MAX_MD_SIZE]; | 115 | unsigned char md_buf[EVP_MAX_MD_SIZE]; |
@@ -109,21 +121,22 @@ int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, | |||
109 | 121 | ||
110 | if (data == NULL) return(nkey); | 122 | if (data == NULL) return(nkey); |
111 | 123 | ||
124 | EVP_MD_CTX_init(&c); | ||
112 | for (;;) | 125 | for (;;) |
113 | { | 126 | { |
114 | EVP_DigestInit(&c,md); | 127 | EVP_DigestInit_ex(&c,md, NULL); |
115 | if (addmd++) | 128 | if (addmd++) |
116 | EVP_DigestUpdate(&c,&(md_buf[0]),mds); | 129 | EVP_DigestUpdate(&c,&(md_buf[0]),mds); |
117 | EVP_DigestUpdate(&c,data,datal); | 130 | EVP_DigestUpdate(&c,data,datal); |
118 | if (salt != NULL) | 131 | if (salt != NULL) |
119 | EVP_DigestUpdate(&c,salt,PKCS5_SALT_LEN); | 132 | EVP_DigestUpdate(&c,salt,PKCS5_SALT_LEN); |
120 | EVP_DigestFinal(&c,&(md_buf[0]),&mds); | 133 | EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds); |
121 | 134 | ||
122 | for (i=1; i<(unsigned int)count; i++) | 135 | for (i=1; i<(unsigned int)count; i++) |
123 | { | 136 | { |
124 | EVP_DigestInit(&c,md); | 137 | EVP_DigestInit_ex(&c,md, NULL); |
125 | EVP_DigestUpdate(&c,&(md_buf[0]),mds); | 138 | EVP_DigestUpdate(&c,&(md_buf[0]),mds); |
126 | EVP_DigestFinal(&c,&(md_buf[0]),&mds); | 139 | EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds); |
127 | } | 140 | } |
128 | i=0; | 141 | i=0; |
129 | if (nkey) | 142 | if (nkey) |
@@ -152,7 +165,7 @@ int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, | |||
152 | } | 165 | } |
153 | if ((nkey == 0) && (niv == 0)) break; | 166 | if ((nkey == 0) && (niv == 0)) break; |
154 | } | 167 | } |
155 | memset(&c,0,sizeof(c)); | 168 | EVP_MD_CTX_cleanup(&c); |
156 | memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE); | 169 | memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE); |
157 | return(type->key_len); | 170 | return(type->key_len); |
158 | } | 171 | } |