kernel - Bring in dff23c692 from FreeBSD
[dragonfly.git] / crypto / openssh / bufbn.c
blobb7f7cb122a228faa50c43c7a1bdb0970077a0cf7
1 /* $OpenBSD: bufbn.c,v 1.12 2014/04/30 05:29:56 djm Exp $ */
3 /*
4 * Copyright (c) 2012 Damien Miller <djm@mindrot.org>
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.
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.
19 /* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */
21 #include "includes.h"
23 #include <sys/types.h>
25 #include "buffer.h"
26 #include "log.h"
27 #include "ssherr.h"
29 int
30 buffer_put_bignum_ret(Buffer *buffer, const BIGNUM *value)
32 int ret;
34 if ((ret = sshbuf_put_bignum1(buffer, value)) != 0) {
35 error("%s: %s", __func__, ssh_err(ret));
36 return -1;
38 return 0;
41 void
42 buffer_put_bignum(Buffer *buffer, const BIGNUM *value)
44 if (buffer_put_bignum_ret(buffer, value) == -1)
45 fatal("%s: buffer error", __func__);
48 int
49 buffer_get_bignum_ret(Buffer *buffer, BIGNUM *value)
51 int ret;
53 if ((ret = sshbuf_get_bignum1(buffer, value)) != 0) {
54 error("%s: %s", __func__, ssh_err(ret));
55 return -1;
57 return 0;
60 void
61 buffer_get_bignum(Buffer *buffer, BIGNUM *value)
63 if (buffer_get_bignum_ret(buffer, value) == -1)
64 fatal("%s: buffer error", __func__);
67 int
68 buffer_put_bignum2_ret(Buffer *buffer, const BIGNUM *value)
70 int ret;
72 if ((ret = sshbuf_put_bignum2(buffer, value)) != 0) {
73 error("%s: %s", __func__, ssh_err(ret));
74 return -1;
76 return 0;
79 void
80 buffer_put_bignum2(Buffer *buffer, const BIGNUM *value)
82 if (buffer_put_bignum2_ret(buffer, value) == -1)
83 fatal("%s: buffer error", __func__);
86 int
87 buffer_get_bignum2_ret(Buffer *buffer, BIGNUM *value)
89 int ret;
91 if ((ret = sshbuf_get_bignum2(buffer, value)) != 0) {
92 error("%s: %s", __func__, ssh_err(ret));
93 return -1;
95 return 0;
98 void
99 buffer_get_bignum2(Buffer *buffer, BIGNUM *value)
101 if (buffer_get_bignum2_ret(buffer, value) == -1)
102 fatal("%s: buffer error", __func__);