blob: b33ede38560428c41803f63219592f06b3de4e55 [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
Damien Millereb8b60e2010-08-31 22:41:14 +100021#include <sys/types.h>
22
Damien Millereb8b60e2010-08-31 22:41:14 +100023#include "buffer.h"
24#include "log.h"
Damien Miller05e82c32014-05-15 14:33:43 +100025#include "ssherr.h"
Damien Millereb8b60e2010-08-31 22:41:14 +100026
Damien Millereb8b60e2010-08-31 22:41:14 +100027int
28buffer_put_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve,
29 const EC_POINT *point)
30{
Damien Miller05e82c32014-05-15 14:33:43 +100031 int ret;
Damien Millereb8b60e2010-08-31 22:41:14 +100032
Damien Miller05e82c32014-05-15 14:33:43 +100033 if ((ret = sshbuf_put_ec(buffer, point, curve)) != 0) {
34 error("%s: %s", __func__, ssh_err(ret));
35 return -1;
Damien Millereb8b60e2010-08-31 22:41:14 +100036 }
Damien Miller05e82c32014-05-15 14:33:43 +100037 return 0;
Damien Millereb8b60e2010-08-31 22:41:14 +100038}
39
40void
41buffer_put_ecpoint(Buffer *buffer, const EC_GROUP *curve,
42 const EC_POINT *point)
43{
44 if (buffer_put_ecpoint_ret(buffer, curve, point) == -1)
45 fatal("%s: buffer error", __func__);
46}
47
48int
49buffer_get_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve,
50 EC_POINT *point)
51{
Damien Miller05e82c32014-05-15 14:33:43 +100052 int ret;
Damien Millereb8b60e2010-08-31 22:41:14 +100053
Damien Miller05e82c32014-05-15 14:33:43 +100054 if ((ret = sshbuf_get_ec(buffer, point, curve)) != 0) {
55 error("%s: %s", __func__, ssh_err(ret));
Damien Millereb8b60e2010-08-31 22:41:14 +100056 return -1;
57 }
Damien Miller05e82c32014-05-15 14:33:43 +100058 return 0;
Damien Millereb8b60e2010-08-31 22:41:14 +100059}
60
61void
62buffer_get_ecpoint(Buffer *buffer, const EC_GROUP *curve,
63 EC_POINT *point)
64{
65 if (buffer_get_ecpoint_ret(buffer, curve, point) == -1)
66 fatal("%s: buffer error", __func__);
67}
68
Damien Miller05e82c32014-05-15 14:33:43 +100069