blob: 749ce9d4c2a6ec18494a705d9ed5f944ecce4a3e [file] [log] [blame]
Damien Miller05e82c32014-05-15 14:33:43 +10001/* $OpenBSD: bufec.c,v 1.4 2014/04/30 05:29:56 djm Exp $ */
2
Damien Millereb8b60e2010-08-31 22:41:14 +10003/*
Damien Miller05e82c32014-05-15 14:33:43 +10004 * Copyright (c) 2012 Damien Miller <djm@mindrot.org>
Damien Millereb8b60e2010-08-31 22:41:14 +10005 *
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 */
Damien Millerc79ff072010-08-31 22:50:48 +100018
Damien Miller05e82c32014-05-15 14:33:43 +100019/* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */
Damien Miller6af914a2010-09-10 11:39:26 +100020
Darren Tucker58538d72014-06-11 13:39:24 +100021#include "includes.h"
22
Damien Millereb8b60e2010-08-31 22:41:14 +100023#include <sys/types.h>
24
Damien Millereb8b60e2010-08-31 22:41:14 +100025#include "buffer.h"
26#include "log.h"
Damien Miller05e82c32014-05-15 14:33:43 +100027#include "ssherr.h"
Damien Millereb8b60e2010-08-31 22:41:14 +100028
Damien Millered126de2014-08-26 08:37:47 +100029#ifdef OPENSSL_HAS_ECC
30
Damien Millereb8b60e2010-08-31 22:41:14 +100031int
32buffer_put_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve,
33 const EC_POINT *point)
34{
Damien Miller05e82c32014-05-15 14:33:43 +100035 int ret;
Damien Millereb8b60e2010-08-31 22:41:14 +100036
Damien Miller05e82c32014-05-15 14:33:43 +100037 if ((ret = sshbuf_put_ec(buffer, point, curve)) != 0) {
38 error("%s: %s", __func__, ssh_err(ret));
39 return -1;
Damien Millereb8b60e2010-08-31 22:41:14 +100040 }
Damien Miller05e82c32014-05-15 14:33:43 +100041 return 0;
Damien Millereb8b60e2010-08-31 22:41:14 +100042}
43
44void
45buffer_put_ecpoint(Buffer *buffer, const EC_GROUP *curve,
46 const EC_POINT *point)
47{
48 if (buffer_put_ecpoint_ret(buffer, curve, point) == -1)
49 fatal("%s: buffer error", __func__);
50}
51
52int
53buffer_get_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve,
54 EC_POINT *point)
55{
Damien Miller05e82c32014-05-15 14:33:43 +100056 int ret;
Damien Millereb8b60e2010-08-31 22:41:14 +100057
Damien Miller05e82c32014-05-15 14:33:43 +100058 if ((ret = sshbuf_get_ec(buffer, point, curve)) != 0) {
59 error("%s: %s", __func__, ssh_err(ret));
Damien Millereb8b60e2010-08-31 22:41:14 +100060 return -1;
61 }
Damien Miller05e82c32014-05-15 14:33:43 +100062 return 0;
Damien Millereb8b60e2010-08-31 22:41:14 +100063}
64
65void
66buffer_get_ecpoint(Buffer *buffer, const EC_GROUP *curve,
67 EC_POINT *point)
68{
69 if (buffer_get_ecpoint_ret(buffer, curve, point) == -1)
70 fatal("%s: buffer error", __func__);
71}
72
Damien Millered126de2014-08-26 08:37:47 +100073#endif /* OPENSSL_HAS_ECC */
Damien Miller05e82c32014-05-15 14:33:43 +100074