diff options
| author | tb <> | 2018-03-17 15:19:12 +0000 |
|---|---|---|
| committer | tb <> | 2018-03-17 15:19:12 +0000 |
| commit | 36729dfed048bc0fe100881beaa75ee443855fe4 (patch) | |
| tree | b098ccdac17cb9ccf01e46859b80d5ce671af779 /src/lib/libcrypto/dsa/dsa_meth.c | |
| parent | 70a27b396f5f0474f8fd3b9dc443176a0d82f759 (diff) | |
| download | openbsd-36729dfed048bc0fe100881beaa75ee443855fe4.tar.gz openbsd-36729dfed048bc0fe100881beaa75ee443855fe4.tar.bz2 openbsd-36729dfed048bc0fe100881beaa75ee443855fe4.zip | |
Add DSA_meth_{dup,free,new,set_{finish,sign}}()
As in RSA_meth_*, note that these functions return NULL in
out-of-memory situations, but they do not set an error explicitly.
ok jsing
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_meth.c')
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_meth.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_meth.c b/src/lib/libcrypto/dsa/dsa_meth.c new file mode 100644 index 0000000000..e6f043f830 --- /dev/null +++ b/src/lib/libcrypto/dsa/dsa_meth.c | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | /* $OpenBSD: dsa_meth.c,v 1.1 2018/03/17 15:19:12 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <stdlib.h> | ||
| 19 | #include <string.h> | ||
| 20 | |||
| 21 | #include <openssl/dsa.h> | ||
| 22 | #include <openssl/err.h> | ||
| 23 | |||
| 24 | DSA_METHOD * | ||
| 25 | DSA_meth_new(const char *name, int flags) | ||
| 26 | { | ||
| 27 | DSA_METHOD *meth; | ||
| 28 | |||
| 29 | if ((meth = calloc(1, sizeof(*meth))) == NULL) | ||
| 30 | return NULL; | ||
| 31 | if ((meth->name = strdup(name)) == NULL) { | ||
| 32 | free(meth); | ||
| 33 | return NULL; | ||
| 34 | } | ||
| 35 | meth->flags = flags; | ||
| 36 | |||
| 37 | return meth; | ||
| 38 | } | ||
| 39 | |||
| 40 | void | ||
| 41 | DSA_meth_free(DSA_METHOD *meth) | ||
| 42 | { | ||
| 43 | if (meth != NULL) { | ||
| 44 | free((char *)meth->name); | ||
| 45 | free(meth); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | DSA_METHOD * | ||
| 50 | DSA_meth_dup(const DSA_METHOD *meth) | ||
| 51 | { | ||
| 52 | DSA_METHOD *copy; | ||
| 53 | |||
| 54 | if ((copy = calloc(1, sizeof(*copy))) == NULL) | ||
| 55 | return NULL; | ||
| 56 | memcpy(copy, meth, sizeof(*copy)); | ||
| 57 | if ((copy->name = strdup(meth->name)) == NULL) { | ||
| 58 | free(copy); | ||
| 59 | return NULL; | ||
| 60 | } | ||
| 61 | |||
| 62 | return copy; | ||
| 63 | } | ||
| 64 | |||
| 65 | int | ||
| 66 | DSA_meth_set_sign(DSA_METHOD *meth, | ||
| 67 | DSA_SIG *(*sign)(const unsigned char *, int, DSA *)) | ||
| 68 | { | ||
| 69 | meth->dsa_do_sign = sign; | ||
| 70 | return 1; | ||
| 71 | } | ||
| 72 | |||
| 73 | int | ||
| 74 | DSA_meth_set_finish(DSA_METHOD *meth, int (*finish)(DSA *)) | ||
| 75 | { | ||
| 76 | meth->finish = finish; | ||
| 77 | return 1; | ||
| 78 | } | ||
