]> git.saurik.com Git - apple/xnu.git/blame - libkern/crypto/corecrypto_chacha20poly1305.c
xnu-4903.270.47.tar.gz
[apple/xnu.git] / libkern / crypto / corecrypto_chacha20poly1305.c
CommitLineData
5ba3f43e
A
1/*
2 * Copyright (c) 2017 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#include <corecrypto/ccchacha20poly1305.h>
30#include <libkern/crypto/crypto_internal.h>
31#include <libkern/crypto/chacha20poly1305.h>
32
0a7de745
A
33static ccchacha20poly1305_fns_t
34fns(void)
5ba3f43e 35{
0a7de745 36 return g_crypto_funcs->ccchacha20poly1305_fns;
5ba3f43e
A
37}
38
0a7de745
A
39static const struct ccchacha20poly1305_info *
40info(void)
5ba3f43e 41{
0a7de745 42 return fns()->info();
5ba3f43e
A
43}
44
0a7de745
A
45int
46chacha20poly1305_init(chacha20poly1305_ctx *ctx, const uint8_t *key)
5ba3f43e 47{
0a7de745 48 return fns()->init(info(), ctx, key);
5ba3f43e
A
49}
50
0a7de745
A
51int
52chacha20poly1305_reset(chacha20poly1305_ctx *ctx)
5ba3f43e 53{
0a7de745 54 return fns()->reset(info(), ctx);
5ba3f43e
A
55}
56
0a7de745
A
57int
58chacha20poly1305_setnonce(chacha20poly1305_ctx *ctx, const uint8_t *nonce)
5ba3f43e 59{
0a7de745 60 return fns()->setnonce(info(), ctx, nonce);
5ba3f43e
A
61}
62
0a7de745
A
63int
64chacha20poly1305_incnonce(chacha20poly1305_ctx *ctx, uint8_t *nonce)
5ba3f43e 65{
0a7de745 66 return fns()->incnonce(info(), ctx, nonce);
5ba3f43e
A
67}
68
0a7de745
A
69int
70chacha20poly1305_aad(chacha20poly1305_ctx *ctx, size_t nbytes, const void *aad)
5ba3f43e 71{
0a7de745 72 return fns()->aad(info(), ctx, nbytes, aad);
5ba3f43e
A
73}
74
0a7de745
A
75int
76chacha20poly1305_encrypt(chacha20poly1305_ctx *ctx, size_t nbytes, const void *ptext, void *ctext)
5ba3f43e 77{
0a7de745 78 return fns()->encrypt(info(), ctx, nbytes, ptext, ctext);
5ba3f43e
A
79}
80
0a7de745
A
81int
82chacha20poly1305_finalize(chacha20poly1305_ctx *ctx, uint8_t *tag)
5ba3f43e 83{
0a7de745 84 return fns()->finalize(info(), ctx, tag);
5ba3f43e
A
85}
86
0a7de745
A
87int
88chacha20poly1305_decrypt(chacha20poly1305_ctx *ctx, size_t nbytes, const void *ctext, void *ptext)
5ba3f43e 89{
0a7de745 90 return fns()->decrypt(info(), ctx, nbytes, ctext, ptext);
5ba3f43e
A
91}
92
0a7de745
A
93int
94chacha20poly1305_verify(chacha20poly1305_ctx *ctx, const uint8_t *tag)
5ba3f43e 95{
0a7de745 96 return fns()->verify(info(), ctx, tag);
5ba3f43e 97}