1 /* $OpenBSD: bufbn.c,v 1.12 2014/04/30 05:29:56 djm Exp $ */ 2 3 /* 4 * Copyright (c) 2012 Damien Miller <djm (at) mindrot.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */ 20 21 #include "includes.h" 22 23 #ifdef WITH_OPENSSL 24 25 #include <sys/types.h> 26 27 #include "buffer.h" 28 #include "log.h" 29 #include "ssherr.h" 30 31 #ifdef WITH_SSH1 32 int 33 buffer_put_bignum_ret(Buffer *buffer, const BIGNUM *value) 34 { 35 int ret; 36 37 if ((ret = sshbuf_put_bignum1(buffer, value)) != 0) { 38 error("%s: %s", __func__, ssh_err(ret)); 39 return -1; 40 } 41 return 0; 42 } 43 44 void 45 buffer_put_bignum(Buffer *buffer, const BIGNUM *value) 46 { 47 if (buffer_put_bignum_ret(buffer, value) == -1) 48 fatal("%s: buffer error", __func__); 49 } 50 51 int 52 buffer_get_bignum_ret(Buffer *buffer, BIGNUM *value) 53 { 54 int ret; 55 56 if ((ret = sshbuf_get_bignum1(buffer, value)) != 0) { 57 error("%s: %s", __func__, ssh_err(ret)); 58 return -1; 59 } 60 return 0; 61 } 62 63 void 64 buffer_get_bignum(Buffer *buffer, BIGNUM *value) 65 { 66 if (buffer_get_bignum_ret(buffer, value) == -1) 67 fatal("%s: buffer error", __func__); 68 } 69 #endif /* WITH_SSH1 */ 70 71 int 72 buffer_put_bignum2_ret(Buffer *buffer, const BIGNUM *value) 73 { 74 int ret; 75 76 if ((ret = sshbuf_put_bignum2(buffer, value)) != 0) { 77 error("%s: %s", __func__, ssh_err(ret)); 78 return -1; 79 } 80 return 0; 81 } 82 83 void 84 buffer_put_bignum2(Buffer *buffer, const BIGNUM *value) 85 { 86 if (buffer_put_bignum2_ret(buffer, value) == -1) 87 fatal("%s: buffer error", __func__); 88 } 89 90 int 91 buffer_get_bignum2_ret(Buffer *buffer, BIGNUM *value) 92 { 93 int ret; 94 95 if ((ret = sshbuf_get_bignum2(buffer, value)) != 0) { 96 error("%s: %s", __func__, ssh_err(ret)); 97 return -1; 98 } 99 return 0; 100 } 101 102 void 103 buffer_get_bignum2(Buffer *buffer, BIGNUM *value) 104 { 105 if (buffer_get_bignum2_ret(buffer, value) == -1) 106 fatal("%s: buffer error", __func__); 107 } 108 109 #endif /* WITH_OPENSSL */ 110