aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/pkcs12/p12_utl.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2001-01-14 14:07:10 +0000
committerDr. Stephen Henson <steve@openssl.org>2001-01-14 14:07:10 +0000
commit6308af199d97d1163d4317557e2d655d7aa211ae (patch)
treeb51511bb05522efb3853cad6b75f4a4332cc5ba1 /crypto/pkcs12/p12_utl.c
parent8e5b6314ef3dd6de9188614ff356c0388fc37134 (diff)
downloadopenssl-6308af199d97d1163d4317557e2d655d7aa211ae.tar.gz
Change PKCS#12 key derivation routines to cope with
non null terminated passwords.
Diffstat (limited to 'crypto/pkcs12/p12_utl.c')
-rw-r--r--crypto/pkcs12/p12_utl.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/crypto/pkcs12/p12_utl.c b/crypto/pkcs12/p12_utl.c
index 8ed3e0d0c7..4409e5c1a8 100644
--- a/crypto/pkcs12/p12_utl.c
+++ b/crypto/pkcs12/p12_utl.c
@@ -62,22 +62,26 @@
/* Cheap and nasty Unicode stuff */
-unsigned char *asc2uni (const char *asc, unsigned char **uni, int *unilen)
+unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen)
{
int ulen, i;
unsigned char *unitmp;
- ulen = strlen(asc)*2 + 2;
- if (!(unitmp = OPENSSL_malloc (ulen))) return NULL;
- for (i = 0; i < ulen; i+=2) {
+ if (asclen == -1) asclen = strlen(asc);
+ ulen = asclen*2 + 2;
+ if (!(unitmp = OPENSSL_malloc(ulen))) return NULL;
+ for (i = 0; i < ulen - 2; i+=2) {
unitmp[i] = 0;
unitmp[i + 1] = asc[i>>1];
}
+ /* Make result double null terminated */
+ unitmp[ulen - 2] = 0;
+ unitmp[ulen - 1] = 0;
if (unilen) *unilen = ulen;
if (uni) *uni = unitmp;
return unitmp;
}
-char *uni2asc (unsigned char *uni, int unilen)
+char *uni2asc(unsigned char *uni, int unilen)
{
int asclen, i;
char *asctmp;
@@ -85,7 +89,7 @@ char *uni2asc (unsigned char *uni, int unilen)
/* If no terminating zero allow for one */
if (!unilen || uni[unilen - 1]) asclen++;
uni++;
- if (!(asctmp = OPENSSL_malloc (asclen))) return NULL;
+ if (!(asctmp = OPENSSL_malloc(asclen))) return NULL;
for (i = 0; i < unilen; i+=2) asctmp[i>>1] = uni[i];
asctmp[asclen - 1] = 0;
return asctmp;