Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 1 | /* $OpenBSD: bufbn.c,v 1.12 2014/04/30 05:29:56 djm Exp $ */ |
| 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 | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 23 | #include <sys/types.h> |
| 24 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 25 | #include "buffer.h" |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 26 | #include "log.h" |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 27 | #include "ssherr.h" |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 28 | |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 29 | int |
| 30 | buffer_put_bignum_ret(Buffer *buffer, const BIGNUM *value) |
| 31 | { |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 32 | int ret; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 33 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 34 | if ((ret = sshbuf_put_bignum1(buffer, value)) != 0) { |
| 35 | error("%s: %s", __func__, ssh_err(ret)); |
| 36 | return -1; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 37 | } |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 38 | return 0; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void |
| 42 | buffer_put_bignum(Buffer *buffer, const BIGNUM *value) |
| 43 | { |
| 44 | if (buffer_put_bignum_ret(buffer, value) == -1) |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 45 | fatal("%s: buffer error", __func__); |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 46 | } |
| 47 | |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 48 | int |
| 49 | buffer_get_bignum_ret(Buffer *buffer, BIGNUM *value) |
| 50 | { |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 51 | int ret; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 52 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 53 | if ((ret = sshbuf_get_bignum1(buffer, value)) != 0) { |
| 54 | error("%s: %s", __func__, ssh_err(ret)); |
| 55 | return -1; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 56 | } |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 57 | return 0; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void |
| 61 | buffer_get_bignum(Buffer *buffer, BIGNUM *value) |
| 62 | { |
| 63 | if (buffer_get_bignum_ret(buffer, value) == -1) |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 64 | fatal("%s: buffer error", __func__); |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 65 | } |
| 66 | |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 67 | int |
| 68 | buffer_put_bignum2_ret(Buffer *buffer, const BIGNUM *value) |
| 69 | { |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 70 | int ret; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 71 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 72 | if ((ret = sshbuf_put_bignum2(buffer, value)) != 0) { |
| 73 | error("%s: %s", __func__, ssh_err(ret)); |
| 74 | return -1; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 75 | } |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 76 | return 0; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void |
| 80 | buffer_put_bignum2(Buffer *buffer, const BIGNUM *value) |
| 81 | { |
| 82 | if (buffer_put_bignum2_ret(buffer, value) == -1) |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 83 | fatal("%s: buffer error", __func__); |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | int |
| 87 | buffer_get_bignum2_ret(Buffer *buffer, BIGNUM *value) |
| 88 | { |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 89 | int ret; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 90 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 91 | if ((ret = sshbuf_get_bignum2(buffer, value)) != 0) { |
| 92 | error("%s: %s", __func__, ssh_err(ret)); |
| 93 | return -1; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 94 | } |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 95 | return 0; |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void |
| 99 | buffer_get_bignum2(Buffer *buffer, BIGNUM *value) |
| 100 | { |
| 101 | if (buffer_get_bignum2_ret(buffer, value) == -1) |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 102 | fatal("%s: buffer error", __func__); |
Damien Miller | 58629fa | 2006-04-23 12:08:19 +1000 | [diff] [blame] | 103 | } |