Giovanni Bajo | d322de0 | 2012-04-23 00:30:00 +0200 | [diff] [blame] | 1 | #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 Bajo | 366dfcb | 2012-04-25 17:40:47 +0200 | [diff] [blame] | 28 | |
| 29 | typedef struct VerifyAlgCtx VerifyAlgCtx; |
| 30 | |
Giovanni Bajo | d322de0 | 2012-04-23 00:30:00 +0200 | [diff] [blame] | 31 | typedef struct |
| 32 | { |
Giovanni Bajo | 366dfcb | 2012-04-25 17:40:47 +0200 | [diff] [blame] | 33 | 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 Bajo | d322de0 | 2012-04-23 00:30:00 +0200 | [diff] [blame] | 38 | } VerifyAlg; |
| 39 | |
Giovanni Bajo | 366dfcb | 2012-04-25 17:40:47 +0200 | [diff] [blame] | 40 | struct VerifyAlgCtx |
| 41 | { |
| 42 | const VerifyAlg *vtbl; |
| 43 | }; |
Giovanni Bajo | d322de0 | 2012-04-23 00:30:00 +0200 | [diff] [blame] | 44 | |
Giovanni Bajo | 366dfcb | 2012-04-25 17:40:47 +0200 | [diff] [blame] | 45 | int verifyalg_supported(int algo); |
| 46 | VerifyAlgCtx* verifyalg_alloc(int algo); |
| 47 | void verifyalg_free(VerifyAlgCtx *a); |
Giovanni Bajo | 6759b99 | 2012-04-25 18:03:24 +0200 | [diff] [blame] | 48 | int verifyalg_algonum(VerifyAlgCtx *a); |
Giovanni Bajo | d322de0 | 2012-04-23 00:30:00 +0200 | [diff] [blame] | 49 | |
| 50 | #endif /* DNSSEC_CRYPTO_H */ |