blob: c89dd25947ecd368d5be3787f127a8fe7bc8fc9e [file] [log] [blame]
Giovanni Bajod322de02012-04-23 00:30:00 +02001#ifndef DNSSEC_CRYPTO_H
2#define DNSSEC_CRYPTO_H
3
4/*
5 * vtable for a signature verification algorithm.
6 *
7 * Each algorithm verifies that a certain signature over a (possibly non-contigous)
8 * array of data has been made with the specified key.
9 *
10 * Sample of usage:
11 *
12 * // First, set the signature we need to check. Notice: data is not copied
13 * // nor consumed, so the pointer must stay valid.
14 * alg->set_signature(sig, 16);
15 *
16 * // Second, push the data in; data is consumed immediately, so the buffer
17 * // can be freed or modified.
18 * alg->begin_data();
19 * alg->add_data(buf1, 123);
20 * alg->add_data(buf2, 45);
21 * alg->add_data(buf3, 678);
22 * alg->end_data();
23 *
24 * // Third, verify if we got the correct key for this signature.
25 * alg->verify(key1, 16);
26 * alg->verify(key2, 16);
27 */
Giovanni Bajo366dfcb2012-04-25 17:40:47 +020028
29typedef struct VerifyAlgCtx VerifyAlgCtx;
30
Giovanni Bajod322de02012-04-23 00:30:00 +020031typedef struct
32{
Giovanni Bajo366dfcb2012-04-25 17:40:47 +020033 int (*set_signature)(VerifyAlgCtx *ctx, unsigned char *data, unsigned len);
34 void (*begin_data)(VerifyAlgCtx *ctx);
35 void (*add_data)(VerifyAlgCtx *ctx, void *data, unsigned len);
36 void (*end_data)(VerifyAlgCtx *ctx);
37 int (*verify)(VerifyAlgCtx *ctx, unsigned char *key, unsigned key_len);
Giovanni Bajod322de02012-04-23 00:30:00 +020038} VerifyAlg;
39
Giovanni Bajo366dfcb2012-04-25 17:40:47 +020040struct VerifyAlgCtx
41{
42 const VerifyAlg *vtbl;
43};
Giovanni Bajod322de02012-04-23 00:30:00 +020044
Giovanni Bajo366dfcb2012-04-25 17:40:47 +020045int verifyalg_supported(int algo);
46VerifyAlgCtx* verifyalg_alloc(int algo);
47void verifyalg_free(VerifyAlgCtx *a);
Giovanni Bajo6759b992012-04-25 18:03:24 +020048int verifyalg_algonum(VerifyAlgCtx *a);
Giovanni Bajod322de02012-04-23 00:30:00 +020049
50#endif /* DNSSEC_CRYPTO_H */