djm@openbsd.org | 3d6d09f | 2017-04-30 23:23:54 +0000 | [diff] [blame] | 1 | /* $OpenBSD: bufbn.c,v 1.13 2017/04/30 23:23:54 djm Exp $ */ |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 2 | |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 3 | /* |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 4 | * Copyright (c) 2012 Damien Miller <djm@mindrot.org> |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 5 | * |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 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. |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 9 | * |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 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. |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 17 | */ |
| 18 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 19 | /* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */ |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 20 | |
Darren Tucker | 58538d7 | 2014-06-11 13:39:24 +1000 | [diff] [blame] | 21 | #include "includes.h" |
| 22 | |
Damien Miller | 72ef7c1 | 2015-01-15 02:21:31 +1100 | [diff] [blame] | 23 | #ifdef WITH_OPENSSL |
| 24 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 25 | #include <sys/types.h> |
| 26 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 27 | #include "buffer.h" |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 28 | #include "log.h" |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 29 | #include "ssherr.h" |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 30 | |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 31 | int |
| 32 | buffer_put_bignum2_ret(Buffer *buffer, const BIGNUM *value) |
| 33 | { |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 34 | int ret; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 35 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 36 | if ((ret = sshbuf_put_bignum2(buffer, value)) != 0) { |
| 37 | error("%s: %s", __func__, ssh_err(ret)); |
| 38 | return -1; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 39 | } |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 40 | return 0; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void |
| 44 | buffer_put_bignum2(Buffer *buffer, const BIGNUM *value) |
| 45 | { |
| 46 | if (buffer_put_bignum2_ret(buffer, value) == -1) |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 47 | fatal("%s: buffer error", __func__); |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | int |
| 51 | buffer_get_bignum2_ret(Buffer *buffer, BIGNUM *value) |
| 52 | { |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 53 | int ret; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 54 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 55 | if ((ret = sshbuf_get_bignum2(buffer, value)) != 0) { |
| 56 | error("%s: %s", __func__, ssh_err(ret)); |
| 57 | return -1; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 58 | } |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 59 | return 0; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void |
| 63 | buffer_get_bignum2(Buffer *buffer, BIGNUM *value) |
| 64 | { |
| 65 | if (buffer_get_bignum2_ret(buffer, value) == -1) |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 66 | fatal("%s: buffer error", __func__); |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 67 | } |
Damien Miller | 72ef7c1 | 2015-01-15 02:21:31 +1100 | [diff] [blame] | 68 | |
| 69 | #endif /* WITH_OPENSSL */ |