blob: 98f9466bc8a2b80b71f121c0c3b17f90378f1183 [file] [log] [blame]
djm@openbsd.org3d6d09f2017-04-30 23:23:54 +00001/* $OpenBSD: bufbn.c,v 1.13 2017/04/30 23:23:54 djm Exp $ */
Damien Miller05e82c32014-05-15 14:33:43 +10002
Damien Miller58629fa2006-04-23 12:08:19 +10003/*
Damien Miller05e82c32014-05-15 14:33:43 +10004 * Copyright (c) 2012 Damien Miller <djm@mindrot.org>
Damien Miller58629fa2006-04-23 12:08:19 +10005 *
Damien Miller05e82c32014-05-15 14:33:43 +10006 * 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 Miller58629fa2006-04-23 12:08:19 +10009 *
Damien Miller05e82c32014-05-15 14:33:43 +100010 * 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 Miller58629fa2006-04-23 12:08:19 +100017 */
18
Damien Miller05e82c32014-05-15 14:33:43 +100019/* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */
Damien Miller58629fa2006-04-23 12:08:19 +100020
Darren Tucker58538d72014-06-11 13:39:24 +100021#include "includes.h"
22
Damien Miller72ef7c12015-01-15 02:21:31 +110023#ifdef WITH_OPENSSL
24
Damien Millerd7834352006-08-05 12:39:39 +100025#include <sys/types.h>
26
Damien Millerd7834352006-08-05 12:39:39 +100027#include "buffer.h"
Damien Miller58629fa2006-04-23 12:08:19 +100028#include "log.h"
Damien Miller05e82c32014-05-15 14:33:43 +100029#include "ssherr.h"
Damien Miller58629fa2006-04-23 12:08:19 +100030
Damien Miller58629fa2006-04-23 12:08:19 +100031int
32buffer_put_bignum2_ret(Buffer *buffer, const BIGNUM *value)
33{
Damien Miller05e82c32014-05-15 14:33:43 +100034 int ret;
Damien Miller58629fa2006-04-23 12:08:19 +100035
Damien Miller05e82c32014-05-15 14:33:43 +100036 if ((ret = sshbuf_put_bignum2(buffer, value)) != 0) {
37 error("%s: %s", __func__, ssh_err(ret));
38 return -1;
Damien Miller58629fa2006-04-23 12:08:19 +100039 }
Damien Miller05e82c32014-05-15 14:33:43 +100040 return 0;
Damien Miller58629fa2006-04-23 12:08:19 +100041}
42
43void
44buffer_put_bignum2(Buffer *buffer, const BIGNUM *value)
45{
46 if (buffer_put_bignum2_ret(buffer, value) == -1)
Damien Miller05e82c32014-05-15 14:33:43 +100047 fatal("%s: buffer error", __func__);
Damien Miller58629fa2006-04-23 12:08:19 +100048}
49
50int
51buffer_get_bignum2_ret(Buffer *buffer, BIGNUM *value)
52{
Damien Miller05e82c32014-05-15 14:33:43 +100053 int ret;
Damien Miller58629fa2006-04-23 12:08:19 +100054
Damien Miller05e82c32014-05-15 14:33:43 +100055 if ((ret = sshbuf_get_bignum2(buffer, value)) != 0) {
56 error("%s: %s", __func__, ssh_err(ret));
57 return -1;
Damien Miller58629fa2006-04-23 12:08:19 +100058 }
Damien Miller05e82c32014-05-15 14:33:43 +100059 return 0;
Damien Miller58629fa2006-04-23 12:08:19 +100060}
61
62void
63buffer_get_bignum2(Buffer *buffer, BIGNUM *value)
64{
65 if (buffer_get_bignum2_ret(buffer, value) == -1)
Damien Miller05e82c32014-05-15 14:33:43 +100066 fatal("%s: buffer error", __func__);
Damien Miller58629fa2006-04-23 12:08:19 +100067}
Damien Miller72ef7c12015-01-15 02:21:31 +110068
69#endif /* WITH_OPENSSL */