Version 0.5.0 of tinydtls
Dependents: tinydtls_test_cellular tinydtls_test_ethernet tiny-dtls
ccm.h@1:598a56fe116e, 2014-02-12 (annotated)
- Committer:
- ashleymills
- Date:
- Wed Feb 12 09:30:16 2014 +0000
- Revision:
- 1:598a56fe116e
- Parent:
- 0:ff9ebe0cf0e9
Explicitly removed something instead of relying on MACRO to disable it. Mbed can't use it.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:ff9ebe0cf0e9 | 1 | /* dtls -- a very basic DTLS implementation |
ashleymills | 0:ff9ebe0cf0e9 | 2 | * |
ashleymills | 0:ff9ebe0cf0e9 | 3 | * Copyright (C) 2011--2012 Olaf Bergmann <bergmann@tzi.org> |
ashleymills | 0:ff9ebe0cf0e9 | 4 | * |
ashleymills | 0:ff9ebe0cf0e9 | 5 | * Permission is hereby granted, free of charge, to any person |
ashleymills | 0:ff9ebe0cf0e9 | 6 | * obtaining a copy of this software and associated documentation |
ashleymills | 0:ff9ebe0cf0e9 | 7 | * files (the "Software"), to deal in the Software without |
ashleymills | 0:ff9ebe0cf0e9 | 8 | * restriction, including without limitation the rights to use, copy, |
ashleymills | 0:ff9ebe0cf0e9 | 9 | * modify, merge, publish, distribute, sublicense, and/or sell copies |
ashleymills | 0:ff9ebe0cf0e9 | 10 | * of the Software, and to permit persons to whom the Software is |
ashleymills | 0:ff9ebe0cf0e9 | 11 | * furnished to do so, subject to the following conditions: |
ashleymills | 0:ff9ebe0cf0e9 | 12 | * |
ashleymills | 0:ff9ebe0cf0e9 | 13 | * The above copyright notice and this permission notice shall be |
ashleymills | 0:ff9ebe0cf0e9 | 14 | * included in all copies or substantial portions of the Software. |
ashleymills | 0:ff9ebe0cf0e9 | 15 | * |
ashleymills | 0:ff9ebe0cf0e9 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
ashleymills | 0:ff9ebe0cf0e9 | 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
ashleymills | 0:ff9ebe0cf0e9 | 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ashleymills | 0:ff9ebe0cf0e9 | 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
ashleymills | 0:ff9ebe0cf0e9 | 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
ashleymills | 0:ff9ebe0cf0e9 | 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
ashleymills | 0:ff9ebe0cf0e9 | 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
ashleymills | 0:ff9ebe0cf0e9 | 23 | * SOFTWARE. |
ashleymills | 0:ff9ebe0cf0e9 | 24 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 25 | |
ashleymills | 0:ff9ebe0cf0e9 | 26 | #ifndef _CCM_H_ |
ashleymills | 0:ff9ebe0cf0e9 | 27 | #define _CCM_H_ |
ashleymills | 0:ff9ebe0cf0e9 | 28 | |
ashleymills | 0:ff9ebe0cf0e9 | 29 | #include "config.h" |
ashleymills | 0:ff9ebe0cf0e9 | 30 | #include "aes/rijndael.h" |
ashleymills | 0:ff9ebe0cf0e9 | 31 | |
ashleymills | 0:ff9ebe0cf0e9 | 32 | /* implementation of Counter Mode CBC-MAC, RFC 3610 */ |
ashleymills | 0:ff9ebe0cf0e9 | 33 | |
ashleymills | 0:ff9ebe0cf0e9 | 34 | #define DTLS_CCM_BLOCKSIZE 16 /**< size of hmac blocks */ |
ashleymills | 0:ff9ebe0cf0e9 | 35 | #define DTLS_CCM_MAX 16 /**< max number of bytes in digest */ |
ashleymills | 0:ff9ebe0cf0e9 | 36 | #define DTLS_CCM_NONCE_SIZE 12 /**< size of nonce */ |
ashleymills | 0:ff9ebe0cf0e9 | 37 | |
ashleymills | 0:ff9ebe0cf0e9 | 38 | /** |
ashleymills | 0:ff9ebe0cf0e9 | 39 | * Authenticates and encrypts a message using AES in CCM mode. Please |
ashleymills | 0:ff9ebe0cf0e9 | 40 | * see also RFC 3610 for the meaning of \p M, \p L, \p lm and \p la. |
ashleymills | 0:ff9ebe0cf0e9 | 41 | * |
ashleymills | 0:ff9ebe0cf0e9 | 42 | * \param ctx The initialized rijndael_ctx object to be used for AES operations. |
ashleymills | 0:ff9ebe0cf0e9 | 43 | * \param M The number of authentication octets. |
ashleymills | 0:ff9ebe0cf0e9 | 44 | * \param L The number of bytes used to encode the message length. |
ashleymills | 0:ff9ebe0cf0e9 | 45 | * \param N The nonce value to use. You must provide \c DTLS_CCM_BLOCKSIZE |
ashleymills | 0:ff9ebe0cf0e9 | 46 | * nonce octets, although only the first \c 16 - \p L are used. |
ashleymills | 0:ff9ebe0cf0e9 | 47 | * \param msg The message to encrypt. The first \p la octets are additional |
ashleymills | 0:ff9ebe0cf0e9 | 48 | * authentication data that will be cleartext. Note that the |
ashleymills | 0:ff9ebe0cf0e9 | 49 | * encryption operation modifies the contents of \p msg and adds |
ashleymills | 0:ff9ebe0cf0e9 | 50 | * \p M bytes MAC. Therefore, the buffer must be at least |
ashleymills | 0:ff9ebe0cf0e9 | 51 | * \p lm + \p M bytes large. |
ashleymills | 0:ff9ebe0cf0e9 | 52 | * \param lm The actual length of \p msg. |
ashleymills | 0:ff9ebe0cf0e9 | 53 | * \param aad A pointer to the additional authentication data (can be \c NULL if |
ashleymills | 0:ff9ebe0cf0e9 | 54 | * \p la is zero). |
ashleymills | 0:ff9ebe0cf0e9 | 55 | * \param la The number of additional authentication octets (may be zero). |
ashleymills | 0:ff9ebe0cf0e9 | 56 | * \return FIXME |
ashleymills | 0:ff9ebe0cf0e9 | 57 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 58 | long int |
ashleymills | 0:ff9ebe0cf0e9 | 59 | dtls_ccm_encrypt_message(rijndael_ctx *ctx, size_t M, size_t L, |
ashleymills | 0:ff9ebe0cf0e9 | 60 | unsigned char nonce[DTLS_CCM_BLOCKSIZE], |
ashleymills | 0:ff9ebe0cf0e9 | 61 | unsigned char *msg, size_t lm, |
ashleymills | 0:ff9ebe0cf0e9 | 62 | const unsigned char *aad, size_t la); |
ashleymills | 0:ff9ebe0cf0e9 | 63 | |
ashleymills | 0:ff9ebe0cf0e9 | 64 | long int |
ashleymills | 0:ff9ebe0cf0e9 | 65 | dtls_ccm_decrypt_message(rijndael_ctx *ctx, size_t M, size_t L, |
ashleymills | 0:ff9ebe0cf0e9 | 66 | unsigned char nonce[DTLS_CCM_BLOCKSIZE], |
ashleymills | 0:ff9ebe0cf0e9 | 67 | unsigned char *msg, size_t lm, |
ashleymills | 0:ff9ebe0cf0e9 | 68 | const unsigned char *aad, size_t la); |
ashleymills | 0:ff9ebe0cf0e9 | 69 | |
ashleymills | 0:ff9ebe0cf0e9 | 70 | #endif /* _CCM_H_ */ |