Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 1 | /* $OpenBSD: bufec.c,v 1.4 2014/04/30 05:29:56 djm Exp $ */ |
| 2 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +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 | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 5 | * |
| 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 Miller | c79ff07 | 2010-08-31 22:50:48 +1000 | [diff] [blame] | 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 | 6af914a | 2010-09-10 11:39:26 +1000 | [diff] [blame] | 20 | |
Darren Tucker | 58538d7 | 2014-06-11 13:39:24 +1000 | [diff] [blame] | 21 | #include "includes.h" |
| 22 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 23 | #include <sys/types.h> |
| 24 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 25 | #include "buffer.h" |
| 26 | #include "log.h" |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 27 | #include "ssherr.h" |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 28 | |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 29 | int |
| 30 | buffer_put_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve, |
| 31 | const EC_POINT *point) |
| 32 | { |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 33 | int ret; |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 34 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 35 | if ((ret = sshbuf_put_ec(buffer, point, curve)) != 0) { |
| 36 | error("%s: %s", __func__, ssh_err(ret)); |
| 37 | return -1; |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 38 | } |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 39 | return 0; |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void |
| 43 | buffer_put_ecpoint(Buffer *buffer, const EC_GROUP *curve, |
| 44 | const EC_POINT *point) |
| 45 | { |
| 46 | if (buffer_put_ecpoint_ret(buffer, curve, point) == -1) |
| 47 | fatal("%s: buffer error", __func__); |
| 48 | } |
| 49 | |
| 50 | int |
| 51 | buffer_get_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve, |
| 52 | EC_POINT *point) |
| 53 | { |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 54 | int ret; |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 55 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 56 | if ((ret = sshbuf_get_ec(buffer, point, curve)) != 0) { |
| 57 | error("%s: %s", __func__, ssh_err(ret)); |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 58 | return -1; |
| 59 | } |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 60 | return 0; |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void |
| 64 | buffer_get_ecpoint(Buffer *buffer, const EC_GROUP *curve, |
| 65 | EC_POINT *point) |
| 66 | { |
| 67 | if (buffer_get_ecpoint_ret(buffer, curve, point) == -1) |
| 68 | fatal("%s: buffer error", __func__); |
| 69 | } |
| 70 | |
Damien Miller | 05e82c3 | 2014-05-15 14:33:43 +1000 | [diff] [blame] | 71 | |