OpenCoverage

p5_pbe.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/p5_pbe.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (the "License"). You may not use-
5 * this file except in compliance with the License. You can obtain a copy-
6 * in the file LICENSE in the source distribution or at-
7 * https://www.openssl.org/source/license.html-
8 */-
9-
10#include <stdio.h>-
11#include "internal/cryptlib.h"-
12#include <openssl/asn1t.h>-
13#include <openssl/x509.h>-
14#include <openssl/rand.h>-
15-
16/* PKCS#5 password based encryption structure */-
17-
18ASN1_SEQUENCE(PBEPARAM) = {-
19 ASN1_SIMPLE(PBEPARAM, salt, ASN1_OCTET_STRING),-
20 ASN1_SIMPLE(PBEPARAM, iter, ASN1_INTEGER)-
21} ASN1_SEQUENCE_END(PBEPARAM)-
22-
23IMPLEMENT_ASN1_FUNCTIONS(PBEPARAM)
never executed: end of block
never executed: return (PBEPARAM *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(PBEPARAM_it)));
never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(PBEPARAM_it)));
never executed: return (PBEPARAM *)ASN1_item_new((&(PBEPARAM_it)));
0
24-
25/* Set an algorithm identifier for a PKCS#5 PBE algorithm */-
26-
27int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,-
28 const unsigned char *salt, int saltlen)-
29{-
30 PBEPARAM *pbe = NULL;-
31 ASN1_STRING *pbe_str = NULL;-
32 unsigned char *sstr = NULL;-
33-
34 pbe = PBEPARAM_new();-
35 if (pbe == NULL) {
pbe == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
36 ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE);-
37 goto err;
never executed: goto err;
0
38 }-
39 if (iter <= 0)
iter <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
40 iter = PKCS5_DEFAULT_ITER;
never executed: iter = 2048;
0
41 if (!ASN1_INTEGER_set(pbe->iter, iter)) {
!ASN1_INTEGER_...e->iter, iter)Description
TRUEnever evaluated
FALSEnever evaluated
0
42 ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE);-
43 goto err;
never executed: goto err;
0
44 }-
45 if (!saltlen)
!saltlenDescription
TRUEnever evaluated
FALSEnever evaluated
0
46 saltlen = PKCS5_SALT_LEN;
never executed: saltlen = 8;
0
47-
48 sstr = OPENSSL_malloc(saltlen);-
49 if (sstr == NULL) {
sstr == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
50 ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE);-
51 goto err;
never executed: goto err;
0
52 }-
53 if (salt)
saltDescription
TRUEnever evaluated
FALSEnever evaluated
0
54 memcpy(sstr, salt, saltlen);
never executed: memcpy(sstr, salt, saltlen);
0
55 else if (RAND_bytes(sstr, saltlen) <= 0)
RAND_bytes(sstr, saltlen) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
56 goto err;
never executed: goto err;
0
57-
58 ASN1_STRING_set0(pbe->salt, sstr, saltlen);-
59 sstr = NULL;-
60-
61 if (!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) {
!ASN1_item_pac...t)), &pbe_str)Description
TRUEnever evaluated
FALSEnever evaluated
0
62 ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE);-
63 goto err;
never executed: goto err;
0
64 }-
65-
66 PBEPARAM_free(pbe);-
67 pbe = NULL;-
68-
69 if (X509_ALGOR_set0(algor, OBJ_nid2obj(alg), V_ASN1_SEQUENCE, pbe_str))
X509_ALGOR_set..., 16, pbe_str)Description
TRUEnever evaluated
FALSEnever evaluated
0
70 return 1;
never executed: return 1;
0
71-
72 err:
code before this statement never executed: err:
0
73 OPENSSL_free(sstr);-
74 PBEPARAM_free(pbe);-
75 ASN1_STRING_free(pbe_str);-
76 return 0;
never executed: return 0;
0
77}-
78-
79/* Return an algorithm identifier for a PKCS#5 PBE algorithm */-
80-
81X509_ALGOR *PKCS5_pbe_set(int alg, int iter,-
82 const unsigned char *salt, int saltlen)-
83{-
84 X509_ALGOR *ret;-
85 ret = X509_ALGOR_new();-
86 if (ret == NULL) {
ret == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
87 ASN1err(ASN1_F_PKCS5_PBE_SET, ERR_R_MALLOC_FAILURE);-
88 return NULL;
never executed: return ((void *)0) ;
0
89 }-
90-
91 if (PKCS5_pbe_set0_algor(ret, alg, iter, salt, saltlen))
PKCS5_pbe_set0...salt, saltlen)Description
TRUEnever evaluated
FALSEnever evaluated
0
92 return ret;
never executed: return ret;
0
93-
94 X509_ALGOR_free(ret);-
95 return NULL;
never executed: return ((void *)0) ;
0
96}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2