1 /* $OpenBSD: dsa_meth.c,v 1.2 2022/01/07 09:35:36 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 #include "dsa_locl.h" 25 26 DSA_METHOD * 27 DSA_meth_new(const char *name, int flags) 28 { 29 DSA_METHOD *meth; 30 31 if ((meth = calloc(1, sizeof(*meth))) == NULL) 32 return NULL; 33 if ((meth->name = strdup(name)) == NULL) { 34 free(meth); 35 return NULL; 36 } 37 meth->flags = flags; 38 39 return meth; 40 } 41 42 void 43 DSA_meth_free(DSA_METHOD *meth) 44 { 45 if (meth != NULL) { 46 free((char *)meth->name); 47 free(meth); 48 } 49 } 50 51 DSA_METHOD * 52 DSA_meth_dup(const DSA_METHOD *meth) 53 { 54 DSA_METHOD *copy; 55 56 if ((copy = calloc(1, sizeof(*copy))) == NULL) 57 return NULL; 58 memcpy(copy, meth, sizeof(*copy)); 59 if ((copy->name = strdup(meth->name)) == NULL) { 60 free(copy); 61 return NULL; 62 } 63 64 return copy; 65 } 66 67 int 68 DSA_meth_set_sign(DSA_METHOD *meth, 69 DSA_SIG *(*sign)(const unsigned char *, int, DSA *)) 70 { 71 meth->dsa_do_sign = sign; 72 return 1; 73 } 74 75 int 76 DSA_meth_set_finish(DSA_METHOD *meth, int (*finish)(DSA *)) 77 { 78 meth->finish = finish; 79 return 1; 80 } 81