blob: 8d1bc23c2f7ab40268bf4e3e400ae95e22442f3a [file] [log] [blame]
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05001/*
2 * Copyright (C) 2012 Werner Dittmann
3 * All rights reserved. For licensing and other legal details, see the file legal.c.
4 *
5 * @author Werner Dittmann <Werner.Dittmann@t-online.de>
6 *
7 */
8
9#include <ec/ec.h>
10#include <ec/ecdh.h>
11
12int ecdhGeneratePublic(const EcCurve *curve, EcPoint *Q, const BigNum *d)
13{
14 EcPoint G;
15
16 INIT_EC_POINT(&G);
17 SET_EC_BASE_POINT(curve, &G);
18
19 ecMulPointScalar(curve, Q, &G, d);
20 ecGetAffine(curve, Q, Q);
21
22 FREE_EC_POINT(&G);
23
24 return ecCheckPubKey(curve, Q);
25}
26
27int ecdhComputeAgreement(const EcCurve *curve, BigNum *agreement, const EcPoint *Q, const BigNum *d)
28{
29 EcPoint t0;
30
31 INIT_EC_POINT(&t0);
32
33 ecMulPointScalar(curve, &t0, Q, d);
34 ecGetAffine(curve, &t0, &t0);
35 /* TODO: check for infinity here */
36
37 bnCopy(agreement, t0.x);
38
39 FREE_EC_POINT(&t0);
40
41 return 0;
42}