This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 3d2f0c0e275e34d592aeb727069d309e665b8e2d Author: anjiahao <anjia...@xiaomi.com> AuthorDate: Thu Jul 28 17:52:21 2022 +0800 crypto:support nuttx /dev/crypto Signed-off-by: anjiahao <anjia...@xiaomi.com> --- LICENSE | 1136 +++++++++++++++++++++++++++ boards/sim/sim/sim/configs/crypto/defconfig | 72 ++ crypto/Kconfig | 1 + crypto/Makefile | 25 +- crypto/aes.c | 3 +- crypto/blf.c | 1 - crypto/cast.c | 3 +- crypto/chacha_private.h | 3 +- crypto/chachapoly.c | 3 +- crypto/cmac.c | 7 +- crypto/crypto.c | 252 +++--- crypto/cryptodev.c | 442 +++++------ crypto/cryptosoft.c | 678 +++------------- crypto/des_locl.h | 1 - crypto/gmac.c | 4 +- crypto/hmac.c | 3 +- crypto/idgen.c | 10 +- crypto/key_wrap.c | 4 +- crypto/md5.c | 3 +- crypto/poly1305.c | 1 - crypto/rijndael.c | 1 - crypto/rmd160.c | 4 +- crypto/set_key.c | 2 + crypto/sha1.c | 3 +- crypto/sha2.c | 3 +- crypto/siphash.c | 3 +- crypto/sk.h | 6 + crypto/spr.h | 6 + crypto/xform.c | 44 +- include/crypto/aes.h | 6 + include/crypto/blf.h | 6 + include/crypto/cmac.h | 6 + include/crypto/cryptodev.h | 31 +- include/crypto/cryptosoft.h | 11 +- include/crypto/gmac.h | 1 + include/crypto/hmac.h | 6 + include/crypto/key_wrap.h | 6 + include/crypto/md5.h | 6 + include/crypto/poly1305.h | 6 + include/crypto/rijndael.h | 6 + include/crypto/rmd160.h | 6 + include/crypto/sha1.h | 6 + include/crypto/sha2.h | 6 + include/crypto/siphash.h | 6 + include/crypto/xform.h | 3 +- 45 files changed, 1769 insertions(+), 1073 deletions(-) diff --git a/LICENSE b/LICENSE index 83a7aca8a9..7e37018223 100644 --- a/LICENSE +++ b/LICENSE @@ -6681,3 +6681,1139 @@ include/sys/queue.h LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include/crypto/cryptodev.h +==================== + $OpenBSD: cryptodev.h,v 1.58 2013/10/31 10:32:38 mikeb Exp $ + The author of this code is Angelos D. Keromytis (ange...@cis.upenn.edu) + * + This code was written by Angelos D. Keromytis in Athens, Greece, in + February 2000. Network Security Technologies Inc. (NSTI) kindly + supported the development of this code. + * + Copyright (c) 2000 Angelos D. Keromytis + * +Permission to use, copy, and modify this software with or without fee +is hereby granted, provided that this entire notice is included in +all source code copies of any software which is or includes a copy or +modification of this software. + * +THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR +IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY +REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE +MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR +PURPOSE. + +Copyright (c) 2001 Theo de Raadt + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Effort sponsored in part by the Defense Advanced Research Projects +Agency (DARPA) and Air Force Research Laboratory, Air Force +Materiel Command, USAF, under agreement number F30602-01-2-0537. + +include/crypto/blf.h +==================== + $OpenBSD: blf.h,v 1.7 2021/11/29 01:04:45 djm Exp $ + + Blowfish - a fast block cipher designed by Bruce Schneier + + Copyright 1997 Niels Provos <pro...@physnet.uni-hamburg.de> + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAG + +include/crypto/cast.h +==================== + $OpenBSD: cast.h,v 1.2 2002/03/14 01:26:51 millert Exp $ + + CAST-128 in C + Written by Steve Reid <sr...@sea-to-sky.net> + 100% Public Domain - no warranty + Released 1997.10.11 + +include/crypto/chachapoly.h +==================== + $OpenBSD: chachapoly.h,v 1.4 2020/07/22 13:54:30 tobhe Exp $ + Copyright (c) 2015 Mike Belopuhov + + Permission to use, copy, modify, and distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +include/crypto/cryptosoft.h +==================== + $OpenBSD: cryptosoft.h,v 1.14 2012/12/07 17:03:22 mikeb Exp $ + + The author of this code is Angelos D. Keromytis (ange...@cis.upenn.edu) + + This code was written by Angelos D. Keromytis in Athens, Greece, in + February 2000. Network Security Technologies Inc. (NSTI) kindly + supported the development of this code. + + Copyright (c) 2000 Angelos D. Keromytis + +Permission to use, copy, and modify this software with or without fee +is hereby granted, provided that this entire notice is included in +all source code copies of any software which is or includes a copy or +modification of this software. + +THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR +IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY +REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE +MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR +PURPOSE. + + include/crypto/gmac.h +==================== + $OpenBSD: gmac.h,v 1.6 2017/05/02 11:44:32 mikeb Exp $ + + Copyright (c) 2010 Mike Belopuhov + + Permission to use, copy, modify, and distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + include/crypto/md5.h +==================== + $OpenBSD: md5.h,v 1.3 2014/11/16 17:39:09 tedu Exp $ + + This code implements the MD5 message-digest algorithm. + The algorithm is due to Ron Rivest. This code was + written by Colin Plumb in 1993, no copyright is claimed. + This code is in the public domain; do with it what you wish. + + Equivalent code is available from RSA Data Security, Inc. + This code has been tested against that, and is equivalent, + except that you don't need to include two pages of legalese + with every copy. + +include/crypto/poly1305.h +==================== + $OpenBSD: poly1305.h,v 1.2 2020/07/22 13:54:30 tobhe Exp $ + + Public Domain poly1305 from Andrew Moon + + poly1305 implementation using 32 bit 32 bit = 64 bit multiplication + and 64 bit addition from https://github.com/floodyberry/poly1305-donna + +include/crypto/rijndael.h +==================== + $OpenBSD: rijndael.h,v 1.13 2008/06/09 07:49:45 djm Exp $ + + rijndael-alg-fst.h + + @version 3.0 (December 2000) + + Optimised ANSI C code for the Rijndael cipher (now AES) + + @author Vincent Rijmen <vincent.rij...@esat.kuleuven.ac.be> + @author Antoon Bosselaers <antoon.bossela...@esat.kuleuven.ac.be> + @author Paulo Barreto <paulo.barr...@terra.com.br> + + This code is hereby placed in the public domain. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include/crypto/rmd160.h +==================== + $OpenBSD: rmd160.h,v 1.5 2009/07/05 19:33:46 millert Exp $ + + Copyright (c) 2001 Markus Friedl. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include/crypto/sha1.h +==================== + $OpenBSD: sha1.h,v 1.6 2014/11/16 17:39:09 tedu Exp $ + SHA-1 in C + By Steve Reid <st...@edmweb.com> + 100% Public Domain + +include/crypto/sha2.h +==================== + $OpenBSD: sha2.h,v 1.5 2014/11/16 17:39:09 tedu Exp $ + + FILE: sha2.h + AUTHOR: Aaron D. Gifford <m...@aarongifford.com> + + Copyright (c) 2000-2001, Aaron D. Gifford + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holder nor the names of contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ + +include/crypto/xform.h +==================== + $OpenBSD: xform.h,v 1.32 2021/10/22 12:30:53 bluhm Exp $ + + The author of this code is Angelos D. Keromytis (ange...@cis.upenn.edu) + + This code was written by Angelos D. Keromytis in Athens, Greece, in + February 2000. Network Security Technologies Inc. (NSTI) kindly + supported the development of this code. + + Copyright (c) 2000 Angelos D. Keromytis + + Permission to use, copy, and modify this software with or without fee + is hereby granted, provided that this entire notice is included in + all source code copies of any software which is or includes a copy or + modification of this software. + + THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR + IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY + REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE + MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR + PURPOSE. + +crypto/blf.c +==================== + $OpenBSD: blf.c,v 1.8 2021/11/29 01:04:45 djm Exp $ * + + Blowfish block cipher for OpenBSD + Copyright 1997 Niels Provos <pro...@physnet.uni-hamburg.de> + All rights reserved. + + Implementation advice by David Mazieres <d...@lcs.mit.edu>. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +crypto/cast.c +==================== + $OpenBSD: cast.c,v 1.4 2012/04/25 04:12:27 matthew Exp $ + + CAST-128 in C + Written by Steve Reid <sr...@sea-to-sky.net> + 100% Public Domain - no warranty + Released 1997.10.11 + +crypto/castsb.h +==================== + $OpenBSD: castsb.h,v 1.1 2000/02/28 23:13:04 deraadt Exp $ + + CAST-128 in C + Written by Steve Reid <sr...@sea-to-sky.net> + 100% Public Domain - no warranty + Released 1997.10.11 + +crypto/chacha_private.h +==================== + $OpenBSD: chacha_private.h,v 1.4 2020/07/22 13:54:30 tobhe Exp $ + + chacha-merged.c version 20080118 + D. J. Bernstein + Public domain. + +crypto/chachapoly.c +==================== + $OpenBSD: chachapoly.c,v 1.6 2020/07/22 13:54:30 tobhe Exp $ + + Copyright (c) 2015 Mike Belopuhov + + Permission to use, copy, modify, and distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +crypto/crypto.c +==================== + $OpenBSD: crypto.c,v 1.65 2014/07/13 23:24:47 deraadt Exp $ + The author of this code is Angelos D. Keromytis (ange...@cis.upenn.edu) + +This code was written by Angelos D. Keromytis in Athens, Greece, in +February 2000. Network Security Technologies Inc. (NSTI) kindly +supported the development of this code. + +Copyright (c) 2000, 2001 Angelos D. Keromytis + +Permission to use, copy, and modify this software with or without fee +is hereby granted, provided that this entire notice is included in +all source code copies of any software which is or includes a copy or +modification of this software. + +THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR +IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY +REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE +MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR +PURPOSE. + +crypto/cryptodev.c +==================== + $OpenBSD: cryptodev.c,v 1.82 2014/08/18 05:11:03 dlg Exp $ + Copyright (c) 2001 Theo de Raadt + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Effort sponsored in part by the Defense Advanced Research Projects + Agency (DARPA) and Air Force Research Laboratory, Air Force + Materiel Command, USAF, under agreement number F30602-01-2-0537. + +crypto/cryptosoft.c +==================== + $OpenBSD: cryptosoft.c,v 1.71 2014/07/13 23:24:47 deraadt Exp $ + The author of this code is Angelos D. Keromytis (ange...@cis.upenn.edu) + +This code was written by Angelos D. Keromytis in Athens, Greece, in +February 2000. Network Security Technologies Inc. (NSTI) kindly +supported the development of this code. + +Copyright (c) 2000, 2001 Angelos D. Keromytis + +Permission to use, copy, and modify this software with or without fee +is hereby granted, provided that this entire notice is included in +all source code copies of any software which is or includes a copy or +modification of this software. + +THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR +IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY +REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE +MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR +PURPOSE. + +crypto/des_locl.h +==================== + $OpenBSD: des_locl.h,v 1.7 2015/12/10 21:00:51 naddy Exp $ + + lib/des/des_locl.h + Copyright (C) 1995 Eric Young (e...@mincom.oz.au) + All rights reserved. + + This file is part of an SSL implementation written + by Eric Young (e...@mincom.oz.au). + The implementation was written so as to conform with Netscapes SSL + specification. This library and applications are + FREE FOR COMMERCIAL AND NON-COMMERCIAL USE + as long as the following conditions are aheared to. + + Copyright remains Eric Young's, and as such any Copyright notices in + the code are not to be removed. If this code is used in a product, + Eric Young should be given attribution as the author of the parts used. + This can be in the form of a textual message at program startup or + in documentation (online or textual) provided with the package. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: + This product includes software developed by + Eric Young (e...@mincom.oz.au) + + THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + The licence and distribution terms for any publically available version or + derivative of this code cannot be changed. + i.e. this code cannot simply be + copied and put under another distribution licence + [including the GNU Public Licence.] + +crypto/ecb_enc.c +==================== + $OpenBSD: ecb_enc.c,v 1.6 2015/12/10 21:00:51 naddy Exp $ + lib/des/ecb_enc.c + Copyright (C) 1995 Eric Young (e...@mincom.oz.au) + All rights reserved. + + This file is part of an SSL implementation written + by Eric Young (e...@mincom.oz.au). + The implementation was written so as to conform with Netscapes SSL + specification. This library and applications are + FREE FOR COMMERCIAL AND NON-COMMERCIAL USE + as long as the following conditions are aheared to. + + Copyright remains Eric Young's, and as such any Copyright notices in + the code are not to be removed. If this code is used in a product, + Eric Young should be given attribution as the author of the parts used. + This can be in the form of a textual message at program startup or + in documentation (online or textual) provided with the package. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: + This product includes software developed by + Eric Young (e...@mincom.oz.au) + + THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + The licence and distribution terms for any publically available version or + derivative of this code cannot be changed. + i.e. this code cannot simply be + copied and put under another distribution licence + [including the GNU Public Licence.] + +crypto/ecb3_enc.c +==================== + $OpenBSD: ecb3_enc.c,v 1.3 2013/11/18 18:49:53 brad Exp $ + lib/des/ecb3_enc.c + Copyright (C) 1995 Eric Young (e...@mincom.oz.au) + All rights reserved. + + This file is part of an SSL implementation written + by Eric Young (e...@mincom.oz.au). + The implementation was written so as to conform with Netscapes SSL + specification. This library and applications are + FREE FOR COMMERCIAL AND NON-COMMERCIAL USE + as long as the following conditions are aheared to. + + Copyright remains Eric Young's, and as such any Copyright notices in + the code are not to be removed. If this code is used in a product, + Eric Young should be given attribution as the author of the parts used. + This can be in the form of a textual message at program startup or + in documentation (online or textual) provided with the package. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: + This product includes software developed + by Eric Young (e...@mincom.oz.au) + * + THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + The licence and distribution terms for any publically available version or + derivative of this code cannot be changed. + i.e. this code cannot simply be + copied and put under another distribution licence + [including the GNU Public Licence.] + +crypto/gmac.c +==================== + $OpenBSD: gmac.c,v 1.10 2017/05/02 11:44:32 mikeb Exp $ + + Copyright (c) 2010 Mike Belopuhov + + Permission to use, copy, modify, and distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + This code implements the Message Authentication part of the + Galois/Counter Mode (as being described in the RFC 4543) using + the AES cipher. FIPS SP 800-38D describes the algorithm details. + +crypto/md5.c +==================== + $OpenBSD: md5.c,v 1.4 2014/12/28 10:04:35 tedu Exp $ + + This code implements the MD5 message-digest algorithm. + The algorithm is due to Ron Rivest. This code was + written by Colin Plumb in 1993, no copyright is claimed. + This code is in the public domain; do with it what you wish. + + Equivalent code is available from RSA Data Security, Inc. + This code has been tested against that, and is equivalent, + except that you don't need to include two pages of legalese + with every copy. + + To compute the message digest of a chunk of bytes, declare an + MD5Context structure, pass it to MD5Init, call MD5Update as + needed on buffers full of bytes, and then call MD5Final, which + will fill a supplied 16-byte array with the digest. + +crypto/podd.h +==================== + $OpenBSD: podd.h,v 1.1 2000/02/28 23:13:05 deraadt Exp $ + lib/des/podd.h + Copyright (C) 1995 Eric Young (e...@mincom.oz.au) + All rights reserved. + + This file is part of an SSL implementation written + by Eric Young (e...@mincom.oz.au). + The implementation was written so as to conform with Netscapes SSL + specification. This library and applications are + FREE FOR COMMERCIAL AND NON-COMMERCIAL USE + as long as the following conditions are aheared to. + + Copyright remains Eric Young's, and as such any Copyright notices in + the code are not to be removed. If this code is used in a product, + Eric Young should be given attribution as the author of the parts used. + This can be in the form of a textual message at program startup or + in documentation (online or textual) provided with the package. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: + This product includes software developed + by Eric Young (e...@mincom.oz.au) + + THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + The licence and distribution terms for any publically available version or + derivative of this code cannot be changed. + i.e. this code cannot simply be + copied and put under another distribution licence + [including the GNU Public Licence.] + +crypto/poly1305.c +==================== + $OpenBSD: poly1305.c,v 1.2 2020/07/22 13:54:30 tobhe Exp $ + + Public Domain poly1305 from Andrew Moon + Based on poly1305-donna.c, poly1305-donna-32.h and poly1305-donna.h from: + https://github.com/floodyberry/poly1305-donna + +crypto/random_pool.c +==================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. The + ASF licenses this file to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance with the + License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + License for the specific language governing permissions and limitations + under the License. + + crypto/rijndael.c +==================== + $OpenBSD: rijndael.c,v 1.20 2014/11/17 12:27:47 mikeb Exp $ + + rijndael-alg-fst.c + + @version 3.0 (December 2000) + + Optimised ANSI C code for the Rijndael cipher (now AES) + + @author Vincent Rijmen <vincent.rij...@esat.kuleuven.ac.be> + @author Antoon Bosselaers <antoon.bossela...@esat.kuleuven.ac.be> + @author Paulo Barreto <paulo.barr...@terra.com.br> + + This code is hereby placed in the public domain. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + crypto/rmd160.c +==================== + $OpenBSD: rmd160.c,v 1.5 2011/01/11 15:42:05 deraadt Exp $ + + Copyright (c) 2001 Markus Friedl. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Preneel, Bosselaers, Dobbertin, + "The Cryptographic Hash Function RIPEMD-160", + RSA Laboratories, CryptoBytes, Volume 3, Number 2, Autumn 1997, + ftp://ftp.rsasecurity.com/pub/cryptobytes/crypto3n2.pdf + +crypto/set_key.c +==================== + $OpenBSD: set_key.c,v 1.5 2021/03/12 10:22:46 jsg Exp $ + lib/des/set_key.c + Copyright (C) 1995 Eric Young (e...@mincom.oz.au) + All rights reserved. + + This file is part of an SSL implementation written + by Eric Young (e...@mincom.oz.au). + The implementation was written so as to conform with Netscapes SSL + specification. This library and applications are + FREE FOR COMMERCIAL AND NON-COMMERCIAL USE + as long as the following conditions are aheared to. + + Copyright remains Eric Young's, and as such any Copyright notices in + the code are not to be removed. If this code is used in a product, + Eric Young should be given attribution as the author of the parts used. + This can be in the form of a textual message at program startup or + in documentation (online or textual) provided with the package. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: + This product includes software developed by + Eric Young (e...@mincom.oz.au) + + THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + The licence and distribution terms for any publically available version or + derivative of this code cannot be changed. + i.e. this code cannot simply be + copied and put under another distribution licence + [including the GNU Public Licence.] + + set_key.c v 1.4 eay 24/9/91 + 1.4 Speed up by 400% :-) + 1.3 added register declarations. + 1.2 unrolled make_key_sched a bit more + 1.1 added norm_expand_bits + 1.0 First working version + +crypto/sha1.c +==================== + $OpenBSD: sha1.c,v 1.11 2014/12/28 10:04:35 tedu Exp $ + + SHA-1 in C + By Steve Reid <st...@edmweb.com> + 100% Public Domain + +crypto/sha2.c +==================== + $OpenBSD: sha2.c,v 1.19 2021/03/12 10:22:46 jsg Exp $ + FILE: sha2.c + AUTHOR: Aaron D. Gifford <m...@aarongifford.com> + + Copyright (c) 2000-2001, Aaron D. Gifford + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holder nor the names of contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $ + +crypto/sk.h +==================== + $OpenBSD: sk.h,v 1.2 2002/10/27 13:24:26 miod Exp $ + lib/des/sk.h + Copyright (C) 1995 Eric Young (e...@mincom.oz.au) + All rights reserved. + + This file is part of an SSL implementation written + by Eric Young (e...@mincom.oz.au). + The implementation was written so as to conform with Netscapes SSL + specification. This library and applications are + FREE FOR COMMERCIAL AND NON-COMMERCIAL USE + as long as the following conditions are aheared to. + + Copyright remains Eric Young's, and as such any Copyright notices in + the code are not to be removed. If this code is used in a product, + Eric Young should be given attribution as the author of the parts used. + This can be in the form of a textual message at program startup or + in documentation (online or textual) provided with the package. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: + This product includes software developed + by Eric Young (e...@mincom.oz.au) + + THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAl, SPECIAl, + EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + The licence and distribution terms for any publically + available version or derivative of this code cannot be changed. + i.e. this code cannot simply be + copied and put under another distribution licence + [including the GNU Public Licence.] + +crypto/spr.h +==================== + $OpenBSD: spr.h,v 1.2 2002/10/27 13:24:26 miod Exp $ + lib/des/spr.h + Copyright (C) 1995 Eric Young (e...@mincom.oz.au) + All rights reserved. + + This file is part of an SSL implementation written + by Eric Young (e...@mincom.oz.au). + The implementation was written so as to conform with Netscapes SSL + specification. This library and applications are + FREE FOR COMMERCIAL AND NON-COMMERCIAL USE + as long as the following conditions are aheared to. + + Copyright remains Eric Young's, and as such any Copyright notices in + the code are not to be removed. If this code is used in a product, + Eric Young should be given attribution as the author of the parts used. + This can be in the form of a textual message at program startup or + in documentation (online or textual) provided with the package. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: + This product includes software developed + by Eric Young (e...@mincom.oz.au) + + THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + The licence and distribution terms for any publically available version or + derivative of this code cannot be changed. + i.e. this code cannot simply be + copied and put under another distribution licence + [including the GNU Public Licence.] + +crypto/xform.c +==================== + $OpenBSD: xform.c,v 1.61 2021/10/22 12:30:53 bluhm Exp $ + + The authors of this code are John Ioannidis (j...@tla.org), + Angelos D. Keromytis (ker...@csd.uch.gr), + Niels Provos (pro...@physnet.uni-hamburg.de), + Damien Miller (d...@mindrot.org) and + Mike Belopuhov (mi...@openbsd.org). + + This code was written by John Ioannidis for BSD/OS in Athens, Greece, + in November 1995. + + Ported to OpenBSD and NetBSD, with additional transforms, + in December 1996, + by Angelos D. Keromytis. + + Additional transforms and features in 1997 and 1998 by + Angelos D. Keromytis and Niels Provos. + + Additional features in 1999 by Angelos D. Keromytis. + + AES XTS implementation in 2008 by Damien Miller + + AES-GCM-16 and Chacha20-Poly1305 AEAD modes by Mike Belopuhov. + + Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis, + Angelos D. Keromytis and Niels Provos. + + Copyright (C) 2001, Angelos D. Keromytis. + + Copyright (C) 2008, Damien Miller + + Copyright (C) 2010, 2015, Mike Belopuhov + + Permission to use, copy, and modify this software with or without fee + is hereby granted, provided that this entire notice is included in + all copies of any software which is or includes a copy or + modification of this software. + You may use this code under the GNU public license if you so wish. Please + contribute changes back to the authors under this freer than GPL license + so that we may further the use of strong encryption without limitations to + all. + + THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR + IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY + REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE + MERCHANTABILIT + +crypto/key_wrap.c +include/crypto/key_wrap.h +========================= + $OpenBSD: key_wrap.c,v 1.5 2017/05/02 17:07:06 mikeb Exp $ + $OpenBSD: key_wrap.h,v 1.5 2017/05/02 17:07:06 mikeb Exp $ + + Copyright (c) 2008 Damien Bergamini <damien.bergam...@free.fr> + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +crypto/cmac.c +include/crypto/cmac.h +===================== + $OpenBSD: cmac.c,v 1.3 2017/05/02 17:07:06 mikeb Exp $ + $OpenBSD: cmac.h,v 1.3 2017/05/02 17:07:06 mikeb Exp $ + + Copyright (c) 2008 Damien Bergamini <damien.bergam...@free.fr> + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +crypto/siphash.c +include/crypto/siphash.h +======================== + $OpenBSD: siphash.c,v 1.5 2018/01/05 19:05:09 mikeb Exp $ + $OpenBSD: siphash.h,v 1.5 2018/01/05 19:05:09 mikeb Exp $ + + Copyright (c) 2013 Andre Oppermann <an...@freebsd.org> + All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. The name of the author may not be used to endorse or promote + products derived from this software without specific prior written + permission. + * +THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +crypto/hmac.c +include/crypto/hmac.h +====================== + $OpenBSD: hmac.c,v 1.4 2016/09/19 18:09:40 tedu Exp $ + $OpenBSD: hmac.h,v 1.4 2016/09/19 18:09:40 tedu Exp $ + + Copyright (c) 2008 Damien Bergamini <damien.bergam...@free.fr> + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +crypto/idgen.c +include/crypto/idgen.h +====================== + $OpenBSD: idgen.c,v 1.8 2020/07/22 13:54:30 tobhe Exp $ + $OpenBSD: idgen.h,v 1.8 2020/07/22 13:54:30 tobhe Exp $ + + Copyright (c) 2008 Damien Miller <d...@mindrot.org> + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/boards/sim/sim/sim/configs/crypto/defconfig b/boards/sim/sim/sim/configs/crypto/defconfig new file mode 100644 index 0000000000..ee852a6de1 --- /dev/null +++ b/boards/sim/sim/sim/configs/crypto/defconfig @@ -0,0 +1,72 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ALLOW_BSD_COMPONENTS=y +CONFIG_ALLSYMS=y +CONFIG_ARCH="sim" +CONFIG_ARCH_BOARD="sim" +CONFIG_ARCH_BOARD_SIM=y +CONFIG_ARCH_CHIP="sim" +CONFIG_ARCH_SIM=y +CONFIG_BOARDCTL_APP_SYMTAB=y +CONFIG_BOARDCTL_POWEROFF=y +CONFIG_BOARD_LOOPSPERMSEC=0 +CONFIG_BOOT_RUNFROMEXTSRAM=y +CONFIG_BUILTIN=y +CONFIG_CRYPTO=y +CONFIG_CRYPTO_CRYPTODEV=y +CONFIG_CRYPTO_RANDOM_POOL=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEV_GPIO=y +CONFIG_DEV_LOOP=y +CONFIG_DEV_ZERO=y +CONFIG_EXAMPLES_GPIO=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_FAT_LCNAMES=y +CONFIG_FAT_LFN=y +CONFIG_FSUTILS_PASSWD=y +CONFIG_FSUTILS_PASSWD_READONLY=y +CONFIG_FS_BINFS=y +CONFIG_FS_FAT=y +CONFIG_FS_PROCFS=y +CONFIG_FS_RAMMAP=y +CONFIG_FS_ROMFS=y +CONFIG_GPIO_LOWER_HALF=y +CONFIG_IDLETHREAD_STACKSIZE=4096 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_IOEXPANDER=y +CONFIG_IOEXPANDER_DUMMY=y +CONFIG_LIBC_ENVPATH=y +CONFIG_LIBC_EXECFUNCS=y +CONFIG_LIBC_LOCALE=y +CONFIG_LIBC_LOCALE_CATALOG=y +CONFIG_LIBC_LOCALE_GETTEXT=y +CONFIG_LIBC_MAX_EXITFUNS=1 +CONFIG_LIBC_NUMBERED_ARGS=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_ARCHROMFS=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FATDEVNO=2 +CONFIG_NSH_FILE_APPS=y +CONFIG_NSH_READLINE=y +CONFIG_NSH_ROMFSDEVNO=1 +CONFIG_NSH_ROMFSETC=y +CONFIG_PATH_INITIAL="/bin" +CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=2048 +CONFIG_PSEUDOFS_ATTRIBUTES=y +CONFIG_PSEUDOFS_SOFTLINKS=y +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_SCHED_BACKTRACE=y +CONFIG_SCHED_HAVE_PARENT=y +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_START_MONTH=6 +CONFIG_START_YEAR=2008 +CONFIG_SYSTEM_DUMPSTACK=y +CONFIG_SYSTEM_NSH=y +CONFIG_TESTING_CRYPTO=y diff --git a/crypto/Kconfig b/crypto/Kconfig index b40c6206e1..5dd465eac3 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -37,6 +37,7 @@ endif # CRYPTO_ALGTEST config CRYPTO_CRYPTODEV bool "cryptodev support" + depends on ALLOW_BSD_COMPONENTS default n config CRYPTO_SW_AES diff --git a/crypto/Makefile b/crypto/Makefile index e3878c7a3b..1029620f5c 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -30,12 +30,27 @@ CRYPTO_CSRCS += crypto.c testmngr.c ifeq ($(CONFIG_CRYPTO_CRYPTODEV),y) CRYPTO_CSRCS += cryptodev.c -endif - -# Software AES library - -ifeq ($(CONFIG_CRYPTO_SW_AES),y) + CRYPTO_CSRCS += cryptosoft.c + CRYPTO_CSRCS += xform.c CRYPTO_CSRCS += aes.c + CRYPTO_CSRCS += blf.c + CRYPTO_CSRCS += cast.c + CRYPTO_CSRCS += chachapoly.c + CRYPTO_CSRCS += ecb_enc.c + CRYPTO_CSRCS += ecb3_enc.c + CRYPTO_CSRCS += set_key.c + CRYPTO_CSRCS += md5.c + CRYPTO_CSRCS += poly1305.c + CRYPTO_CSRCS += rijndael.c + CRYPTO_CSRCS += rmd160.c + CRYPTO_CSRCS += sha1.c + CRYPTO_CSRCS += sha2.c + CRYPTO_CSRCS += gmac.c + CRYPTO_CSRCS += cmac.c + CRYPTO_CSRCS += hmac.c + CRYPTO_CSRCS += idgen.c + CRYPTO_CSRCS += key_wrap.c + CRYPTO_CSRCS += siphash.c endif # BLAKE2s hash algorithm diff --git a/crypto/aes.c b/crypto/aes.c index 2f4f049a5b..5790093139 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -31,9 +31,8 @@ * Included Files ****************************************************************************/ +#include <string.h> #include <sys/types.h> -#include <sys/systm.h> -#include <sys/stdint.h> #include <crypto/aes.h> /**************************************************************************** diff --git a/crypto/blf.c b/crypto/blf.c index 6d49b32b4d..52969be073 100644 --- a/crypto/blf.c +++ b/crypto/blf.c @@ -42,7 +42,6 @@ ****************************************************************************/ #include <sys/param.h> -#include <sys/systm.h> #include <crypto/blf.h> diff --git a/crypto/cast.c b/crypto/cast.c index 836d5db661..c9540764ac 100644 --- a/crypto/cast.c +++ b/crypto/cast.c @@ -12,9 +12,10 @@ * Included Files ****************************************************************************/ +#include <string.h> #include <sys/types.h> -#include <sys/systm.h> #include <crypto/cast.h> + #include "castsb.h" /* Macros to access 8-bit bytes out of a 32-bit word */ diff --git a/crypto/chacha_private.h b/crypto/chacha_private.h index 48b4031bda..392e378833 100644 --- a/crypto/chacha_private.h +++ b/crypto/chacha_private.h @@ -11,7 +11,8 @@ * Included Files ****************************************************************************/ -#include <sys/systm.h> +#include <string.h> +#include <sys/types.h> typedef struct { diff --git a/crypto/chachapoly.c b/crypto/chachapoly.c index 8e5e6b913b..321b7997ad 100644 --- a/crypto/chachapoly.c +++ b/crypto/chachapoly.c @@ -21,9 +21,8 @@ * Included Files ****************************************************************************/ +#include <endian.h> #include <sys/param.h> -#include <sys/systm.h> -#include <lib/libkern/libkern.h> #include <crypto/poly1305.h> #include <crypto/chachapoly.h> diff --git a/crypto/cmac.c b/crypto/cmac.c index 04e038809a..fc6f3b4168 100644 --- a/crypto/cmac.c +++ b/crypto/cmac.c @@ -26,12 +26,15 @@ * Included Files ****************************************************************************/ +#include <string.h> #include <sys/param.h> -#include <sys/systm.h> - #include <crypto/aes.h> #include <crypto/cmac.h> +#ifndef MIN +# define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif + #define LSHIFT(v, r) do \ { \ int i; \ diff --git a/crypto/crypto.c b/crypto/crypto.c index 5037f6718c..5c58629cdb 100644 --- a/crypto/crypto.c +++ b/crypto/crypto.c @@ -26,31 +26,36 @@ * Included Files ****************************************************************************/ -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/malloc.h> -#include <sys/proc.h> -#include <sys/pool.h> - +#include <nuttx/config.h> + +#include <sys/types.h> +#include <stdbool.h> +#include <string.h> +#include <poll.h> +#include <debug.h> +#include <errno.h> #include <crypto/cryptodev.h> +#include <nuttx/fs/fs.h> +#include <nuttx/mutex.h> +#include <nuttx/kmalloc.h> +#include <nuttx/crypto/crypto.h> /**************************************************************************** - * Public Functions + * Public Data ****************************************************************************/ -void crypto_init(void); +FAR struct cryptocap *crypto_drivers = NULL; +int crypto_drivers_num = 0; /**************************************************************************** - * Public Data + * Private Data ****************************************************************************/ -FAR static struct cryptocap *crypto_drivers = NULL; -int crypto_drivers_num = 0; - -struct pool cryptop_pool; -struct pool cryptodesc_pool; +static mutex_t g_crypto_lock = NXMUTEX_INITIALIZER; -FAR struct taskq *crypto_taskq; +/**************************************************************************** + * Public Functions + ****************************************************************************/ /* Create a new session. */ @@ -65,14 +70,13 @@ int crypto_newsession(FAR uint64_t *sid, FAR struct cryptoini *cr; int turn = 0; int err; - int s; if (crypto_drivers == NULL) { - return EINVAL; + return -EINVAL; } - s = splvm(); + nxmutex_lock(&g_crypto_lock); /* The algorithm we use here is pretty stupid; just use the * first driver that supports all the algorithms we need. Do @@ -196,8 +200,8 @@ int crypto_newsession(FAR uint64_t *sid, if (hid == -1) { - splx(s); - return EINVAL; + nxmutex_unlock(&g_crypto_lock); + return -EINVAL; } /* Call the driver initialization routine. */ @@ -212,7 +216,7 @@ int crypto_newsession(FAR uint64_t *sid, crypto_drivers[hid].cc_sessions++; } - splx(s); + nxmutex_unlock(&g_crypto_lock); return err; } @@ -223,12 +227,11 @@ int crypto_newsession(FAR uint64_t *sid, int crypto_freesession(uint64_t sid) { int err = 0; - int s; uint32_t hid; if (crypto_drivers == NULL) { - return EINVAL; + return -EINVAL; } /* Determine two IDs. */ @@ -237,10 +240,10 @@ int crypto_freesession(uint64_t sid) if (hid >= crypto_drivers_num) { - return ENOENT; + return -ENOENT; } - s = splvm(); + nxmutex_lock(&g_crypto_lock); if (crypto_drivers[hid].cc_sessions) { @@ -264,7 +267,7 @@ int crypto_freesession(uint64_t sid) explicit_bzero(&crypto_drivers[hid], sizeof(struct cryptocap)); } - splx(s); + nxmutex_unlock(&g_crypto_lock); return err; } @@ -274,20 +277,18 @@ int crypto_get_driverid(uint8_t flags) { FAR struct cryptocap *newdrv; int i; - int s; - s = splvm(); + nxmutex_lock(&g_crypto_lock); if (crypto_drivers_num == 0) { crypto_drivers_num = CRYPTO_DRIVERS_INITIAL; - crypto_drivers = mallocarray(crypto_drivers_num, - sizeof(struct cryptocap), - M_CRYPTO_DATA, M_NOWAIT); + crypto_drivers = kmm_calloc(crypto_drivers_num, + sizeof(struct cryptocap)); if (crypto_drivers == NULL) { crypto_drivers_num = 0; - splx(s); + nxmutex_unlock(&g_crypto_lock); return -1; } @@ -303,7 +304,7 @@ int crypto_get_driverid(uint8_t flags) { crypto_drivers[i].cc_sessions = 1; /* Mark */ crypto_drivers[i].cc_flags = flags; - splx(s); + nxmutex_unlock(&g_crypto_lock); return i; } } @@ -314,16 +315,15 @@ int crypto_get_driverid(uint8_t flags) { if (crypto_drivers_num >= CRYPTO_DRIVERS_MAX) { - splx(s); + nxmutex_unlock(&g_crypto_lock); return -1; } - newdrv = mallocarray(crypto_drivers_num, - 2 * sizeof(struct cryptocap), - M_CRYPTO_DATA, M_NOWAIT); + newdrv = kmm_calloc(crypto_drivers_num * 2, + sizeof(struct cryptocap)); if (newdrv == NULL) { - splx(s); + nxmutex_unlock(&g_crypto_lock); return -1; } @@ -336,15 +336,15 @@ int crypto_get_driverid(uint8_t flags) newdrv[i].cc_flags = flags; crypto_drivers_num *= 2; - free(crypto_drivers, M_CRYPTO_DATA, 0); + kmm_free(crypto_drivers); crypto_drivers = newdrv; - splx(s); + nxmutex_unlock(&g_crypto_lock); return i; } /* Shouldn't really get here... */ - splx(s); + nxmutex_unlock(&g_crypto_lock); return -1; } @@ -355,16 +355,15 @@ int crypto_get_driverid(uint8_t flags) int crypto_kregister(uint32_t driverid, FAR int *kalg, CODE int (*kprocess)(FAR struct cryptkop *)) { - int s; int i; if (driverid >= crypto_drivers_num || kalg == NULL || crypto_drivers == NULL) { - return EINVAL; + return -EINVAL; } - s = splvm(); + nxmutex_lock(&g_crypto_lock); for (i = 0; i <= CRK_ALGORITHM_MAX; i++) { @@ -378,7 +377,7 @@ int crypto_kregister(uint32_t driverid, FAR int *kalg, crypto_drivers[driverid].cc_kprocess = kprocess; - splx(s); + nxmutex_unlock(&g_crypto_lock); return 0; } @@ -390,16 +389,15 @@ int crypto_register(uint32_t driverid, FAR int *alg, CODE int (*freeses)(uint64_t), CODE int (*process)(FAR struct cryptop *)) { - int s; int i; if (driverid >= crypto_drivers_num || alg == NULL || crypto_drivers == NULL) { - return EINVAL; + return -EINVAL; } - s = splvm(); + nxmutex_lock(&g_crypto_lock); for (i = 0; i <= CRYPTO_ALGORITHM_MAX; i++) { @@ -416,7 +414,7 @@ int crypto_register(uint32_t driverid, FAR int *alg, crypto_drivers[driverid].cc_freesession = freeses; crypto_drivers[driverid].cc_sessions = 0; /* Unmark */ - splx(s); + nxmutex_unlock(&g_crypto_lock); return 0; } @@ -430,10 +428,9 @@ int crypto_register(uint32_t driverid, FAR int *alg, int crypto_unregister(uint32_t driverid, int alg) { int i = CRYPTO_ALGORITHM_MAX + 1; - int s; uint32_t ses; - s = splvm(); + nxmutex_lock(&g_crypto_lock); /* Sanity checks. */ @@ -442,8 +439,8 @@ int crypto_unregister(uint32_t driverid, int alg) alg != CRYPTO_ALGORITHM_MAX + 1) || crypto_drivers[driverid].cc_alg[alg] == 0) { - splx(s); - return EINVAL; + nxmutex_unlock(&g_crypto_lock); + return -EINVAL; } if (alg != CRYPTO_ALGORITHM_MAX + 1) @@ -478,39 +475,7 @@ int crypto_unregister(uint32_t driverid, int alg) } } - splx(s); - return 0; -} - -/* Add crypto request to a queue, to be processed by a kernel thread. */ - -int crypto_dispatch(FAR struct cryptop *crp) -{ - if (crypto_taskq && !(crp->crp_flags & CRYPTO_F_NOQUEUE)) - { - task_set(&crp->crp_task, (void (*))crypto_invoke, crp, NULL); - task_add(crypto_taskq, &crp->crp_task); - } - else - { - crypto_invoke(crp); - } - - return 0; -} - -int crypto_kdispatch(FAR struct cryptkop *krp) -{ - if (crypto_taskq) - { - task_set(&krp->krp_task, (void (*))crypto_kinvoke, krp, NULL); - task_add(crypto_taskq, &krp->krp_task); - } - else - { - crypto_kinvoke(krp); - } - + nxmutex_unlock(&g_crypto_lock); return 0; } @@ -521,16 +486,15 @@ int crypto_kinvoke(FAR struct cryptkop *krp) extern int cryptodevallowsoft; uint32_t hid; int error; - int s; /* Sanity checks. */ - if (krp == NULL || krp->krp_callback == NULL) + if (krp == NULL) { - return EINVAL; + return -EINVAL; } - s = splvm(); + nxmutex_lock(&g_crypto_lock); for (hid = 0; hid < crypto_drivers_num; hid++) { if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) && @@ -555,9 +519,8 @@ int crypto_kinvoke(FAR struct cryptkop *krp) if (hid == crypto_drivers_num) { - krp->krp_status = ENODEV; - crypto_kdone(krp); - splx(s); + krp->krp_status = -ENODEV; + nxmutex_unlock(&g_crypto_lock); return 0; } @@ -569,10 +532,9 @@ int crypto_kinvoke(FAR struct cryptkop *krp) if (error) { krp->krp_status = error; - crypto_kdone(krp); } - splx(s); + nxmutex_unlock(&g_crypto_lock); return 0; } @@ -584,21 +546,19 @@ int crypto_invoke(FAR struct cryptop *crp) uint64_t nid; uint32_t hid; int error; - int s; /* Sanity checks. */ - if (crp == NULL || crp->crp_callback == NULL) + if (crp == NULL) { - return EINVAL; + return -EINVAL; } - s = splvm(); + nxmutex_lock(&g_crypto_lock); if (crp->crp_desc == NULL || crypto_drivers == NULL) { - crp->crp_etype = EINVAL; - crypto_done(crp); - splx(s); + crp->crp_etype = -EINVAL; + nxmutex_unlock(&g_crypto_lock); return 0; } @@ -625,7 +585,7 @@ int crypto_invoke(FAR struct cryptop *crp) error = crypto_drivers[hid].cc_process(crp); if (error) { - if (error == ERESTART) + if (error == -ERESTART) { /* Unregister driver and migrate session. */ @@ -638,7 +598,7 @@ int crypto_invoke(FAR struct cryptop *crp) } } - splx(s); + nxmutex_unlock(&g_crypto_lock); return 0; migrate: @@ -655,9 +615,8 @@ migrate: crp->crp_sid = nid; } - crp->crp_etype = EAGAIN; - crypto_done(crp); - splx(s); + crp->crp_etype = -EAGAIN; + nxmutex_unlock(&g_crypto_lock); return 0; } @@ -666,23 +625,22 @@ migrate: void crypto_freereq(FAR struct cryptop *crp) { FAR struct cryptodesc *crd; - int s; if (crp == NULL) { return; } - s = splvm(); + nxmutex_lock(&g_crypto_lock); while ((crd = crp->crp_desc) != NULL) { crp->crp_desc = crd->crd_next; - pool_put(&cryptodesc_pool, crd); + kmm_free(crd); } - pool_put(&cryptop_pool, crp); - splx(s); + kmm_free(crp); + nxmutex_unlock(&g_crypto_lock); } /* Acquire a set of crypto descriptors. */ @@ -691,14 +649,13 @@ FAR struct cryptop *crypto_getreq(int num) { FAR struct cryptodesc *crd; FAR struct cryptop *crp; - int s; - s = splvm(); + nxmutex_lock(&g_crypto_lock); - crp = pool_get(&cryptop_pool, PR_NOWAIT); + crp = kmm_malloc(sizeof(struct cryptop)); if (crp == NULL) { - splx(s); + nxmutex_unlock(&g_crypto_lock); return NULL; } @@ -706,60 +663,22 @@ FAR struct cryptop *crypto_getreq(int num) while (num--) { - crd = pool_get(&cryptodesc_pool, PR_NOWAIT); + crd = kmm_calloc(1, sizeof(struct cryptodesc)); if (crd == NULL) { - splx(s); + nxmutex_unlock(&g_crypto_lock); crypto_freereq(crp); return NULL; } - bzero(crd, sizeof(struct cryptodesc)); crd->crd_next = crp->crp_desc; crp->crp_desc = crd; } - splx(s); + nxmutex_unlock(&g_crypto_lock); return crp; } -void crypto_init(void) -{ - crypto_taskq = taskq_create("crypto", 1, IPL_HIGH); - - pool_init(&cryptop_pool, sizeof(struct cryptop), 0, 0, - 0, "cryptop", NULL); - pool_init(&cryptodesc_pool, sizeof(struct cryptodesc), 0, 0, - 0, "cryptodesc", NULL); -} - -/* Invoke the callback on behalf of the driver. */ - -void crypto_done(FAR struct cryptop *crp) -{ - crp->crp_flags |= CRYPTO_F_DONE; - if (crp->crp_flags & CRYPTO_F_NOQUEUE) - { - /* not from the crypto queue, wakeup the userland process */ - - crp->crp_callback(crp); - } - else - { - task_set(&crp->crp_task, (void (*))crp->crp_callback, - crp, NULL); - task_add(crypto_taskq, &crp->crp_task); - } -} - -/* Invoke the callback on behalf of the driver. */ - -void crypto_kdone(FAR struct cryptkop *krp) -{ - task_set(&krp->krp_task, (void (*))krp->krp_callback, krp, NULL); - task_add(crypto_taskq, &krp->krp_task); -} - int crypto_getfeat(FAR int *featp) { extern int cryptodevallowsoft; @@ -800,3 +719,22 @@ out: *featp = feat; return 0; } + +int up_cryptoinitialize(void) +{ +#ifdef CONFIG_CRYPTO_ALGTEST + int ret = crypto_test(); + if (ret) + { + crypterr("ERROR: crypto test failed\n"); + } + else + { + cryptinfo("crypto test OK\n"); + } + + return ret; +#else + return OK; +#endif +} diff --git a/crypto/cryptodev.c b/crypto/cryptodev.c index db55eeac0a..b524804b2f 100644 --- a/crypto/cryptodev.c +++ b/crypto/cryptodev.c @@ -33,25 +33,23 @@ * Included Files ****************************************************************************/ -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/malloc.h> -#include <sys/pool.h> -#include <sys/mbuf.h> -#include <sys/proc.h> -#include <sys/file.h> -#include <sys/filedesc.h> -#include <sys/errno.h> -#include <dev/rndvar.h> -#include <sys/conf.h> -#include <sys/device.h> -#include <crypto/md5.h> -#include <crypto/sha1.h> -#include <crypto/rmd160.h> -#include <crypto/cast.h> -#include <crypto/blf.h> -#include <crypto/cryptodev.h> +#include <nuttx/config.h> + +#include <sys/types.h> +#include <sys/queue.h> +#include <stdbool.h> +#include <string.h> +#include <poll.h> +#include <errno.h> + +#include <nuttx/kmalloc.h> +#include <nuttx/fs/fs.h> +#include <nuttx/crypto/crypto.h> +#include <nuttx/drivers/drivers.h> + #include <crypto/xform.h> +#include <crypto/cryptodev.h> +#include <crypto/cryptosoft.h> /**************************************************************************** * Public Data @@ -59,9 +57,11 @@ extern FAR struct cryptocap *crypto_drivers; extern int crypto_drivers_num; -int usercrypto = 0; /* userland may do crypto requests */ -int userasymcrypto = 0; /* userland may do asymmetric crypto reqs */ -int cryptodevallowsoft = 0; /* only use hardware crypto */ +int usercrypto = 1; /* userland may do crypto requests */ +int userasymcrypto = 1; /* userland may do asymmetric crypto reqs */ +int cryptodevallowsoft = 1; /* 0 is only use hardware crypto + * 1 is use hardware & software crypto + */ /**************************************************************************** * Private Types @@ -84,8 +84,6 @@ struct csession caddr_t mackey; int mackeylen; - struct iovec iovec[IOV_MAX]; - struct uio uio; int error; }; @@ -99,31 +97,52 @@ struct fcrypt * Private Function Prototypes ****************************************************************************/ -void cryptoattach(int); +/* Character driver methods */ + +static ssize_t cryptof_read(FAR struct file *filep, + FAR char *buffer, size_t len); +static ssize_t cryptof_write(FAR struct file *filep, + FAR const char *buffer, size_t len); +static int cryptof_ioctl(FAR struct file *filep, + int cmd, unsigned long arg); +static int cryptof_poll(FAR struct file *filep, + struct pollfd *fds, bool setup); +static int cryptof_close(FAR struct file *filep); -int cryptof_read(FAR struct file *, FAR off_t *, - FAR struct uio *, FAR struct ucred *); -int cryptof_write(FAR struct file *, FAR off_t *, - FAR struct uio *, FAR struct ucred *); -int cryptof_ioctl(FAR struct file *, u_long, caddr_t, FAR struct proc *p); -int cryptof_poll(FAR struct file *, int, FAR struct proc *); -int cryptof_kqfilter(FAR struct file *, FAR struct knote *); -int cryptof_stat(FAR struct file *, FAR struct stat *, FAR struct proc *); -int cryptof_close(FAR struct file *, FAR struct proc *); +static int cryptoopen(FAR struct file *filep); +static int cryptoclose(FAR struct file *filep); +static int cryptoioctl(FAR struct file *filep, int cmd, unsigned long arg); /**************************************************************************** * Private Data ****************************************************************************/ -static struct fileops g_cryptofops = +static const struct file_operations g_cryptofops = { - cryptof_read, - cryptof_write, - cryptof_ioctl, - cryptof_poll, - cryptof_kqfilter, - cryptof_stat, - cryptof_close + NULL, /* open */ + cryptof_close, /* close */ + cryptof_read, /* read */ + cryptof_write, /* write */ + NULL, /* seek */ + cryptof_ioctl, /* ioctl */ + cryptof_poll /* poll */ +}; + +static const struct file_operations g_cryptoops = +{ + cryptoopen, /* open */ + cryptoclose, /* close */ + NULL, /* read */ + NULL, /* write */ + NULL, /* seek */ + cryptoioctl, /* ioctl */ + NULL /* poll */ +}; + +static struct inode g_cryptoinode = +{ + .i_crefs = 1, + .u.i_ops = &g_cryptofops }; /**************************************************************************** @@ -141,7 +160,7 @@ FAR struct csession *csecreate(FAR struct fcrypt *, uint64_t, int csefree(FAR struct csession *); int cryptodev_op(FAR struct csession *, - FAR struct crypt_op *, FAR struct proc *); + FAR struct crypt_op *); int cryptodev_key(FAR struct crypt_kop *); int cryptodev_dokey(FAR struct crypt_kop *kop, FAR struct crparam *kvp); @@ -150,28 +169,28 @@ int cryptodevkey_cb(FAR struct cryptkop *); /* ARGSUSED */ -int cryptof_read(FAR struct file *fp, FAR off_t *poff, - FAR struct uio *uio, FAR struct ucred *cred) +static ssize_t cryptof_read(FAR struct file *filep, + FAR char *buffer, size_t len) { - return EIO; + return -EIO; } /* ARGSUSED */ -int cryptof_write(FAR struct file *fp, FAR off_t *poff, - FAR struct uio *uio, FAR struct ucred *cred) +static ssize_t cryptof_write(FAR struct file *filep, + FAR const char *buffer, size_t len) { - return EIO; + return -EIO; } /* ARGSUSED */ -int cryptof_ioctl(FAR struct file *fp, u_long cmd, - caddr_t data, FAR struct proc *p) +static int cryptof_ioctl(FAR struct file *filep, + int cmd, unsigned long arg) { struct cryptoini cria; struct cryptoini crie; - FAR struct fcrypt *fcr = fp->f_data; + FAR struct fcrypt *fcr = filep->f_priv; FAR struct csession *cse; FAR struct session_op *sop; FAR struct crypt_op *cop; @@ -184,7 +203,7 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd, switch (cmd) { case CIOCGSESSION: - sop = (FAR struct session_op *)data; + sop = (FAR struct session_op *)arg; switch (sop->cipher) { case 0: @@ -211,7 +230,7 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd, txform = &enc_xform_null; break; default: - return EINVAL; + return -EINVAL; } switch (sop->mac) @@ -240,7 +259,7 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd, thash = &auth_hash_gmac_aes_128; break; default: - return EINVAL; + return -EINVAL; } bzero(&crie, sizeof(crie)); @@ -253,18 +272,18 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd, if (sop->keylen > txform->maxkey || sop->keylen < txform->minkey) { - error = EINVAL; + error = -EINVAL; goto bail; } - crie.cri_key = malloc(crie.cri_klen / 8, M_XDATA, - M_WAITOK); - if ((error = copyin(sop->key, crie.cri_key, - crie.cri_klen / 8))) + crie.cri_key = kmm_malloc(crie.cri_klen / 8); + if (crie.cri_key == NULL) { + error = -ENOMEM; goto bail; } + memcpy(crie.cri_key, sop->key, crie.cri_klen / 8); if (thash) { crie.cri_next = &cria; @@ -277,19 +296,20 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd, cria.cri_klen = sop->mackeylen * 8; if (sop->mackeylen > thash->keysize) { - error = EINVAL; + error = -EINVAL; goto bail; } if (cria.cri_klen) { - cria.cri_key = malloc(cria.cri_klen / 8, - M_XDATA, M_WAITOK); - if ((error = copyin(sop->mackey, cria.cri_key, - cria.cri_klen / 8))) + cria.cri_key = kmm_malloc(cria.cri_klen / 8); + if (cria.cri_key == NULL) { + error = -ENOMEM; goto bail; } + + memcpy(cria.cri_key, sop->mackey, cria.cri_klen / 8); } } @@ -308,7 +328,7 @@ int cryptof_ioctl(FAR struct file *fp, u_long cmd, if (cse == NULL) { crypto_freesession(sid); - error = EINVAL; + error = -EINVAL; goto bail; } @@ -320,92 +340,79 @@ bail: if (crie.cri_key) { explicit_bzero(crie.cri_key, crie.cri_klen / 8); - free(crie.cri_key, M_XDATA, 0); + kmm_free(crie.cri_key); } if (cria.cri_key) { explicit_bzero(cria.cri_key, cria.cri_klen / 8); - free(cria.cri_key, M_XDATA, 0); + kmm_free(cria.cri_key); } } break; case CIOCFSESSION: - ses = *(FAR uint32_t *)data; + ses = *(FAR uint32_t *)arg; cse = csefind(fcr, ses); if (cse == NULL) { - return EINVAL; + return -EINVAL; } csedelete(fcr, cse); error = csefree(cse); break; case CIOCCRYPT: - cop = (FAR struct crypt_op *)data; + cop = (FAR struct crypt_op *)arg; cse = csefind(fcr, cop->ses); if (cse == NULL) { - return EINVAL; + return -EINVAL; } - error = cryptodev_op(cse, cop, p); + error = cryptodev_op(cse, cop); break; case CIOCKEY: - error = cryptodev_key((FAR struct crypt_kop *)data); + error = cryptodev_key((FAR struct crypt_kop *)arg); break; case CIOCASYMFEAT: - error = crypto_getfeat((FAR int *)data); + error = crypto_getfeat((FAR int *)arg); break; default: - error = EINVAL; + error = -EINVAL; } return error; } int cryptodev_op(FAR struct csession *cse, - FAR struct crypt_op *cop, - FAR struct proc *p) + FAR struct crypt_op *cop) { FAR struct cryptop *crp = NULL; FAR struct cryptodesc *crde = NULL; FAR struct cryptodesc *crda = NULL; - int s; - int error; + int error = OK; uint32_t hid; if (cop->len > 64 * 1024 - 4) { - return E2BIG; + return -E2BIG; } if (cse->txform) { if (cop->len == 0 || (cop->len % cse->txform->blocksize) != 0) { - return EINVAL; + return -EINVAL; } } - bzero(&cse->uio, sizeof(cse->uio)); - cse->uio.uio_iovcnt = 1; - cse->uio.uio_segflg = UIO_SYSSPACE; - cse->uio.uio_rw = UIO_WRITE; - cse->uio.uio_procp = p; - cse->uio.uio_iov = cse->iovec; - bzero(&cse->iovec, sizeof(cse->iovec)); - cse->uio.uio_iov[0].iov_len = cop->len; - cse->uio.uio_iov[0].iov_base = dma_alloc(cop->len, M_WAITOK); - cse->uio.uio_resid = cse->uio.uio_iov[0].iov_len; - /* number of requests, not logical and */ crp = crypto_getreq((cse->txform != NULL) + (cse->thash != NULL)); if (crp == NULL) { - error = ENOMEM; + error = -ENOMEM; goto bail; } @@ -423,16 +430,11 @@ int cryptodev_op(FAR struct csession *cse, } else { - error = EINVAL; + error = -EINVAL; goto bail; } } - if ((error = copyin(cop->src, cse->uio.uio_iov[0].iov_base, cop->len))) - { - goto bail; - } - if (crda) { crda->crd_skip = 0; @@ -463,8 +465,7 @@ int cryptodev_op(FAR struct csession *cse, } crp->crp_ilen = cop->len; - crp->crp_buf = (caddr_t)&cse->uio; - crp->crp_callback = cryptodev_cb; + crp->crp_buf = cop->src; crp->crp_sid = cse->sid; crp->crp_opaque = cse; @@ -472,15 +473,11 @@ int cryptodev_op(FAR struct csession *cse, { if (crde == NULL) { - error = EINVAL; - goto bail; - } - - if ((error = copyin(cop->iv, cse->tmp_iv, cse->txform->blocksize))) - { + error = -EINVAL; goto bail; } + memcpy(cse->tmp_iv, cop->iv, cse->txform->blocksize); bcopy(cse->tmp_iv, crde->crd_iv, cse->txform->blocksize); crde->crd_flags |= CRD_F_IV_EXPLICIT | CRD_F_IV_PRESENT; crde->crd_skip = 0; @@ -492,11 +489,22 @@ int cryptodev_op(FAR struct csession *cse, crde->crd_len -= cse->txform->blocksize; } + if (cop->dst) + { + if (crde == NULL) + { + error = -EINVAL; + goto bail; + } + + crp->crp_dst = cop->dst; + } + if (cop->mac) { if (crda == NULL) { - error = EINVAL; + error = -EINVAL; goto bail; } @@ -534,21 +542,8 @@ int cryptodev_op(FAR struct csession *cse, goto processed; dispatch: crp->crp_flags = CRYPTO_F_IOV; - crypto_dispatch(crp); + crypto_invoke(crp); processed: - s = splnet(); - while (!(crp->crp_flags & CRYPTO_F_DONE)) - { - error = tsleep(cse, PSOCK, "crydev", 0); - } - - splx(s); - if (error) - { - /* XXX can this happen? if so, how do we recover? */ - - goto bail; - } if (cse->error) { @@ -562,57 +557,19 @@ processed: goto bail; } - if (cop->dst && - (error = copyout(cse->uio.uio_iov[0].iov_base, cop->dst, cop->len))) - { - goto bail; - } - - if (cop->mac && - (error = copyout(crp->crp_mac, cop->mac, cse->thash->hashsize))) - { - goto bail; - } - bail: if (crp) { crypto_freereq(crp); } - if (cse->uio.uio_iov[0].iov_base) - { - dma_free(cse->uio.uio_iov[0].iov_base, cop->len); - } - return error; } -int cryptodev_cb(FAR struct cryptop *crp) -{ - FAR struct csession *cse = crp->crp_opaque; - - cse->error = crp->crp_etype; - if (crp->crp_etype == EAGAIN) - { - crp->crp_flags = CRYPTO_F_IOV; - return crypto_dispatch(crp); - } - - wakeup(cse); - return (0); -} - -int cryptodevkey_cb(FAR struct cryptkop *krp) -{ - wakeup(krp); - return (0); -} - int cryptodev_key(FAR struct crypt_kop *kop) { FAR struct cryptkop *krp = NULL; - int error = EINVAL; + int error = -EINVAL; int in; int out; int size; @@ -620,7 +577,7 @@ int cryptodev_key(FAR struct crypt_kop *kop) if (kop->crk_iparams + kop->crk_oparams > CRK_MAXPARAM) { - return EFBIG; + return -EFBIG; } in = kop->crk_iparams; @@ -630,34 +587,33 @@ int cryptodev_key(FAR struct crypt_kop *kop) case CRK_MOD_EXP: if (in == 3 && out == 1) break; - return EINVAL; + return -EINVAL; case CRK_MOD_EXP_CRT: if (in == 6 && out == 1) break; - return EINVAL; + return -EINVAL; case CRK_DSA_SIGN: if (in == 5 && out == 2) break; - return EINVAL; + return -EINVAL; case CRK_DSA_VERIFY: if (in == 7 && out == 0) break; - return EINVAL; + return -EINVAL; case CRK_DH_COMPUTE_KEY: if (in == 3 && out == 1) break; - return EINVAL; + return -EINVAL; default: - return EINVAL; + return -EINVAL; } - krp = malloc(sizeof *krp, M_XDATA, M_WAITOK | M_ZERO); + krp = kmm_malloc(sizeof *krp); krp->krp_op = kop->crk_op; krp->krp_status = kop->crk_status; krp->krp_iparams = kop->crk_iparams; krp->krp_oparams = kop->crk_oparams; krp->krp_status = 0; - krp->krp_callback = cryptodevkey_cb; for (i = 0; i < CRK_MAXPARAM; i++) { @@ -678,34 +634,25 @@ int cryptodev_key(FAR struct crypt_kop *kop) continue; } - krp->krp_param[i].crp_p = malloc(size, M_XDATA, M_WAITOK); + krp->krp_param[i].crp_p = kmm_malloc(size); if (i >= krp->krp_iparams) { continue; } - error = copyin(kop->crk_param[i].crp_p, - krp->krp_param[i].crp_p, size); + memcpy(krp->krp_param[i].crp_p, kop->crk_param[i].crp_p, size); if (error) { goto fail; } } - error = crypto_kdispatch(krp); + error = crypto_kinvoke(krp); if (error) { goto fail; } - error = tsleep(krp, PSOCK, "crydev", 0); - if (error) - { - /* XXX can this happen? if so, how do we recover? */ - - goto fail; - } - if (krp->krp_status != 0) { error = krp->krp_status; @@ -720,12 +667,8 @@ int cryptodev_key(FAR struct crypt_kop *kop) continue; } - error = copyout(krp->krp_param[i].crp_p, - kop->crk_param[i].crp_p, size); - if (error) - { - goto fail; - } + memcpy(kop->crk_param[i].crp_p, + krp->krp_param[i].crp_p, size); } fail: @@ -738,11 +681,11 @@ fail: { explicit_bzero(krp->krp_param[i].crp_p, (krp->krp_param[i].crp_nbits + 7) / 8); - free(krp->krp_param[i].crp_p, M_XDATA, 0); + kmm_free(krp->krp_param[i].crp_p); } } - free(krp, M_XDATA, 0); + kmm_free(krp); } return error; @@ -750,32 +693,17 @@ fail: /* ARGSUSED */ -int cryptof_poll(FAR struct file *fp, int events, FAR struct proc *p) +static int cryptof_poll(FAR struct file *filep, + struct pollfd *fds, bool setup) { return 0; } /* ARGSUSED */ -int cryptof_kqfilter(FAR struct file *fp, FAR struct knote *kn) +static int cryptof_close(FAR struct file *filep) { - return 0; -} - -/* ARGSUSED */ - -int cryptof_stat(FAR struct file *fp, - FAR struct stat *sb, - FAR struct proc *p) -{ - return EOPNOTSUPP; -} - -/* ARGSUSED */ - -int cryptof_close(FAR struct file *fp, FAR struct proc *p) -{ - FAR struct fcrypt *fcr = fp->f_data; + FAR struct fcrypt *fcr = filep->f_priv; FAR struct csession *cse; while ((cse = TAILQ_FIRST(&fcr->csessions))) @@ -784,38 +712,29 @@ int cryptof_close(FAR struct file *fp, FAR struct proc *p) (void)csefree(cse); } - free(fcr, M_XDATA, 0); - fp->f_data = NULL; - return 0; -} + kmm_free(fcr); + filep->f_priv = NULL; -void cryptoattach(int n) -{ + return 0; } -int cryptoopen(dev_t dev, int flag, int mode, FAR struct proc *p) +static int cryptoopen(FAR struct file *filep) { if (usercrypto == 0) { - return ENXIO; + return -ENXIO; } -#ifdef CRYPTO return 0; -#else - return ENXIO; -#endif } -int cryptoclose(dev_t dev, int flag, int mode, FAR struct proc *p) +static int cryptoclose(FAR struct file *filep) { - return (0); + return 0; } -int cryptoioctl(dev_t dev, u_long cmd, - caddr_t data, int flag, FAR struct proc *p) +static int cryptoioctl(FAR struct file *filep, int cmd, unsigned long arg) { - FAR struct file *f; FAR struct fcrypt *fcr; int fd; int error = 0; @@ -823,28 +742,22 @@ int cryptoioctl(dev_t dev, u_long cmd, switch (cmd) { case CRIOGET: - fcr = malloc(sizeof(struct fcrypt), M_XDATA, M_WAITOK); + fcr = kmm_malloc(sizeof(struct fcrypt)); TAILQ_INIT(&fcr->csessions); - fcr->sesn = 0; - fdplock(p->p_fd); - error = falloc(p, &f, &fd); - fdpunlock(p->p_fd); - if (error) + fd = file_allocate(&g_cryptoinode, 0, + 0, fcr, 0, true); + if (fd < 0) { - free(fcr, M_XDATA, 0); - return error; + kmm_free(fcr); + return fd; } - f->f_flag = FREAD | FWRITE; - f->f_type = DTYPE_CRYPTO; - f->f_ops = &cryptofops; - f->f_data = fcr; - *(FAR uint32_t *)data = fd; - FILE_SET_MATURE(f, p); + fcr->sesn = 0; + *(FAR uint32_t *)arg = fd; break; default: - error = EINVAL; + error = -EINVAL; break; } @@ -897,23 +810,22 @@ FAR struct csession *csecreate(FAR struct fcrypt *fcr, uint64_t sid, { FAR struct csession *cse; - cse = malloc(sizeof(struct csession), M_XDATA, M_NOWAIT); - if (cse == NULL) + cse = kmm_malloc(sizeof(struct csession)); + if (cse != NULL) { - return NULL; + cse->key = key; + cse->keylen = keylen / 8; + cse->mackey = mackey; + cse->mackeylen = mackeylen / 8; + cse->sid = sid; + cse->cipher = cipher; + cse->mac = mac; + cse->txform = txform; + cse->thash = thash; + cse->error = 0; + cseadd(fcr, cse); } - cse->key = key; - cse->keylen = keylen / 8; - cse->mackey = mackey; - cse->mackeylen = mackeylen / 8; - cse->sid = sid; - cse->cipher = cipher; - cse->mac = mac; - cse->txform = txform; - cse->thash = thash; - cse->error = 0; - cseadd(fcr, cse); return cse; } @@ -924,14 +836,28 @@ int csefree(FAR struct csession *cse) error = crypto_freesession(cse->sid); if (cse->key) { - free(cse->key, M_XDATA, 0); + kmm_free(cse->key); } if (cse->mackey) { - free(cse->mackey, M_XDATA, 0); + kmm_free(cse->mackey); } - free(cse, M_XDATA, 0); + kmm_free(cse); return error; } + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void devcrypto_register(void) +{ + register_driver("/dev/crypto", &g_cryptoops, 0666, NULL); + swcr_init(); + +#ifdef CONFIG_CRYPTO_CRYPTODEV_HARDWARE + hwcr_init(); +#endif +} diff --git a/crypto/cryptosoft.c b/crypto/cryptosoft.c index 7beb81a31b..77d011f901 100644 --- a/crypto/cryptosoft.c +++ b/crypto/cryptosoft.c @@ -25,21 +25,24 @@ * Included Files ****************************************************************************/ -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/malloc.h> -#include <sys/mbuf.h> -#include <sys/errno.h> -#include <dev/rndvar.h> -#include <crypto/md5.h> -#include <crypto/sha1.h> -#include <crypto/rmd160.h> -#include <crypto/cast.h> -#include <crypto/blf.h> +#include <assert.h> +#include <errno.h> +#include <endian.h> +#include <nuttx/kmalloc.h> #include <crypto/cryptodev.h> #include <crypto/cryptosoft.h> #include <crypto/xform.h> +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef howmany +# define howmany(x, y) (((x) + ((y) - 1)) / (y)) +#endif + +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) + /**************************************************************************** * Private Data ****************************************************************************/ @@ -88,46 +91,25 @@ FAR struct swcr_data **swcr_sessions = NULL; uint32_t swcr_sesnum = 0; int swcr_id = -1; -#define COPYBACK(x, a, b, c, d) \ - do { \ - if ((x) == CRYPTO_BUF_MBUF) \ - m_copyback((FAR struct mbuf *)a,b,c,d,M_NOWAIT); \ - else \ - cuio_copyback((FAR struct uio *)a,b,c,d); \ - } while (0) -#define COPYDATA(x, a, b, c, d) \ - do { \ - if ((x) == CRYPTO_BUF_MBUF) \ - m_copydata((FAR struct mbuf *)a,b,c,d); \ - else \ - cuio_copydata((FAR struct uio *)a,b,c,d); \ - } while (0) - /**************************************************************************** * Public Functions ****************************************************************************/ /* Apply a symmetric encryption/decryption algorithm. */ -int swcr_encdec(FAR struct cryptodesc *crd, FAR struct swcr_data *sw, - caddr_t buf, int outtype) +int swcr_encdec(FAR struct cryptop *crp, FAR struct cryptodesc *crd, + FAR struct swcr_data *sw, caddr_t buf) { unsigned char iv[EALG_MAX_BLOCK_LEN]; unsigned char blk[EALG_MAX_BLOCK_LEN]; - FAR unsigned char *idat; FAR unsigned char *ivp; FAR unsigned char *nivp; unsigned char iv2[EALG_MAX_BLOCK_LEN]; FAR const struct enc_xform *exf; int i; - int k; int j; int blks; - int ind; - int count; int ivlen; - FAR struct mbuf *m = NULL; - FAR struct uio *uio = NULL; exf = sw->sw_exf; blks = exf->blocksize; @@ -137,16 +119,7 @@ int swcr_encdec(FAR struct cryptodesc *crd, FAR struct swcr_data *sw, if (crd->crd_len % blks) { - return EINVAL; - } - - if (outtype == CRYPTO_BUF_MBUF) - { - m = (FAR struct mbuf *) buf; - } - else - { - uio = (FAR struct uio *) buf; + return -EINVAL; } /* Initialize the IV */ @@ -168,7 +141,7 @@ int swcr_encdec(FAR struct cryptodesc *crd, FAR struct swcr_data *sw, if (!(crd->crd_flags & CRD_F_IV_PRESENT)) { - COPYBACK(outtype, buf, crd->crd_inject, ivlen, iv); + bcopy(iv, buf + crd->crd_inject, ivlen); } } else @@ -185,7 +158,7 @@ int swcr_encdec(FAR struct cryptodesc *crd, FAR struct swcr_data *sw, { /* Get IV off buf */ - COPYDATA(outtype, buf, crd->crd_inject, ivlen, iv); + bcopy(iv, buf + crd->crd_inject, ivlen); } } @@ -200,369 +173,74 @@ int swcr_encdec(FAR struct cryptodesc *crd, FAR struct swcr_data *sw, exf->reinit((caddr_t)sw->sw_kschedule, iv); } - if (outtype == CRYPTO_BUF_MBUF) - { - /* Find beginning of data */ - - m = m_getptr(m, crd->crd_skip, &k); - if (m == NULL) - { - return EINVAL; - } - - i = crd->crd_len; + i = crd->crd_len; - while (i > 0) + while (i > 0) + { + bcopy(buf, blk, exf->blocksize); + buf += exf->blocksize; + if (exf->reinit) { - /* If there's insufficient data at the end of - * an mbuf, we have to do some copying. - */ - - if (m->m_len < k + blks && m->m_len != k) + if (crd->crd_flags & CRD_F_ENCRYPT) { - m_copydata(m, k, blks, blk); - - /* Actual encryption/decryption */ - - if (exf->reinit) - { - if (crd->crd_flags & CRD_F_ENCRYPT) - { - exf->encrypt((caddr_t)sw->sw_kschedule, - blk); - } - else - { - exf->decrypt((caddr_t)sw->sw_kschedule, - blk); - } - } - else if (crd->crd_flags & CRD_F_ENCRYPT) - { - /* XOR with previous block */ - - for (j = 0; j < blks; j++) - { - blk[j] ^= ivp[j]; - } - - exf->encrypt((caddr_t)sw->sw_kschedule, blk); - - /* Keep encrypted block for XOR'ing - * with next block - */ - - bcopy(blk, iv, blks); - ivp = iv; - } - else - { - /* decrypt */ - - /* Keep encrypted block for XOR'ing - * with next block - */ - - nivp = (ivp == iv) ? iv2 : iv; - bcopy(blk, nivp, blks); - - exf->decrypt(sw->sw_kschedule, blk); - - /* XOR with previous block */ - - for (j = 0; j < blks; j++) - { - blk[j] ^= ivp[j]; - } - - ivp = nivp; - } - - /* Copy back decrypted block */ - - m_copyback(m, k, blks, blk, M_NOWAIT); - - /* Advance pointer */ - - m = m_getptr(m, k + blks, &k); - if (m == NULL) - { - return EINVAL; - } - - i -= blks; - - /* Could be done... */ - - if (i == 0) - { - break; - } + exf->encrypt((caddr_t)sw->sw_kschedule, + blk); } - - /* Skip possibly empty mbufs */ - - if (k == m->m_len) + else { - for (m = m->m_next; m && m->m_len == 0; - m = m->m_next) - ; - k = 0; + exf->decrypt((caddr_t)sw->sw_kschedule, + blk); } + } + else if (crd->crd_flags & CRD_F_ENCRYPT) + { + /* XOR with previous block */ - /* Sanity check */ + for (j = 0; j < blks; j++) + blk[j] ^= ivp[j]; - if (m == NULL) - { - return EINVAL; - } + exf->encrypt((caddr_t)sw->sw_kschedule, blk); - /* Warning: idat may point to garbage here, but - * we only use it in the while() loop, only if - * there are indeed enough data. + /* Keep encrypted block for XOR'ng + * with next block */ - idat = mtod(m, FAR unsigned char *) + k; - - while (m->m_len >= k + blks && i > 0) - { - if (exf->reinit) - { - if (crd->crd_flags & CRD_F_ENCRYPT) - { - exf->encrypt(sw->sw_kschedule, - idat); - } - else - { - exf->decrypt(sw->sw_kschedule, - idat); - } - } - else if (crd->crd_flags & CRD_F_ENCRYPT) - { - /* XOR with previous block/IV */ - - for (j = 0; j < blks; j++) - { - idat[j] ^= ivp[j]; - } - - exf->encrypt(sw->sw_kschedule, idat); - ivp = idat; - } - else - { - /* decrypt */ - - /* Keep encrypted block to be used - * in next block's processing. - */ - - nivp = (ivp == iv) ? iv2 : iv; - bcopy(idat, nivp, blks); - - exf->decrypt(sw->sw_kschedule, idat); - - /* XOR with previous block/IV */ - - for (j = 0; j < blks; j++) - { - idat[j] ^= ivp[j]; - } - - ivp = nivp; - } - - idat += blks; - k += blks; - i -= blks; - } + bcopy(blk, iv, blks); + ivp = iv; } - } - else - { - /* Find beginning of data */ - - count = crd->crd_skip; - ind = cuio_getptr(uio, count, &k); - if (ind == -1) + else { - return EINVAL; - } - - i = crd->crd_len; + /* decrypt */ - while (i > 0) - { - /* If there's insufficient data at the end, - * we have to do some copying. + /* Keep encrypted block for XOR'ing + * with next block */ - if (uio->uio_iov[ind].iov_len < k + blks && - uio->uio_iov[ind].iov_len != k) - { - cuio_copydata(uio, count, blks, blk); - - /* Actual encryption/decryption */ - - if (exf->reinit) - { - if (crd->crd_flags & CRD_F_ENCRYPT) - { - exf->encrypt(sw->sw_kschedule, - blk); - } - else - { - exf->decrypt(sw->sw_kschedule, - blk); - } - } - else if (crd->crd_flags & CRD_F_ENCRYPT) - { - /* XOR with previous block */ - - for (j = 0; j < blks; j++) - { - blk[j] ^= ivp[j]; - } - - exf->encrypt(sw->sw_kschedule, blk); - - /* Keep encrypted block for XOR'ing - * with next block - */ - - bcopy(blk, iv, blks); - ivp = iv; - } - else - { - /* decrypt */ - - /* Keep encrypted block for XOR'ing - * with next block - */ - - nivp = (ivp == iv) ? iv2 : iv; - bcopy(blk, nivp, blks); - - exf->decrypt(sw->sw_kschedule, blk); - - /* XOR with previous block */ - - for (j = 0; j < blks; j++) - { - blk[j] ^= ivp[j]; - } - - ivp = nivp; - } + nivp = (ivp == iv) ? iv2 : iv; + bcopy(blk, nivp, blks); - /* Copy back decrypted block */ + exf->decrypt((caddr_t)sw->sw_kschedule, blk); - cuio_copyback(uio, count, blks, blk); + /* XOR with previous block */ - count += blks; - - /* Advance pointer */ - - ind = cuio_getptr(uio, count, &k); - if (ind == -1) - { - return EINVAL; - } - - i -= blks; - - /* Could be done... */ - - if (i == 0) - { - break; - } + for (j = 0; j < blks; j++) + { + blk[j] ^= ivp[j]; } - /* Warning: idat may point to garbage here, but - * we only use it in the while() loop, only if - * there are indeed enough data. - */ + ivp = nivp; + } - idat = (FAR char *)uio->uio_iov[ind].iov_base + k; + bcopy(blk, crp->crp_dst, exf->blocksize); + crp->crp_dst += exf->blocksize; - while (uio->uio_iov[ind].iov_len >= k + blks && - i > 0) - { - if (exf->reinit) - { - if (crd->crd_flags & CRD_F_ENCRYPT) - { - exf->encrypt(sw->sw_kschedule, - idat); - } - else - { - exf->decrypt(sw->sw_kschedule, - idat); - } - } - else if (crd->crd_flags & CRD_F_ENCRYPT) - { - /* XOR with previous block/IV */ - - for (j = 0; j < blks; j++) - { - idat[j] ^= ivp[j]; - } - - exf->encrypt(sw->sw_kschedule, idat); - ivp = idat; - } - else - { - /* decrypt */ - - /* Keep encrypted block to be used - * in next block's processing. - */ - - nivp = (ivp == iv) ? iv2 : iv; - bcopy(idat, nivp, blks); - - exf->decrypt(sw->sw_kschedule, idat); - - /* XOR with previous block/IV */ - - for (j = 0; j < blks; j++) - { - idat[j] ^= ivp[j]; - } - - ivp = nivp; - } - - idat += blks; - count += blks; - k += blks; - i -= blks; - } + i -= blks; - /* Advance to the next iov if the end of the current iov - * is aligned with the end of a cipher block. - * Note that the code is equivalent to calling: - * ind = cuio_getptr(uio, count, &k); - */ + /* Could be done... */ - if (i > 0 && k == uio->uio_iov[ind].iov_len) - { - k = 0; - ind++; - if (ind >= uio->uio_iovcnt) - { - return EINVAL; - } - } + if (i == 0) + { + break; } } @@ -574,7 +252,7 @@ int swcr_encdec(FAR struct cryptodesc *crd, FAR struct swcr_data *sw, int swcr_authcompute(FAR struct cryptop *crp, FAR struct cryptodesc *crd, FAR struct swcr_data *sw, - caddr_t buf, int outtype) + caddr_t buf) { unsigned char aalg[AALG_MAX_RESULT_LEN]; FAR const struct auth_hash *axf; @@ -583,27 +261,13 @@ int swcr_authcompute(FAR struct cryptop *crp, if (sw->sw_ictx == 0) { - return EINVAL; + return -EINVAL; } axf = sw->sw_axf; bcopy(sw->sw_ictx, &ctx, axf->ctxsize); - - if (outtype == CRYPTO_BUF_MBUF) - { - err = m_apply((FAR struct mbuf *) buf, crd->crd_skip, crd->crd_len, - (int (*)(caddr_t, caddr_t, unsigned int)) axf->update, - (caddr_t) &ctx); - } - else - { - err = cuio_apply((FAR struct uio *) buf, crd->crd_skip, - crd->crd_len, - (int (*)(caddr_t, caddr_t, unsigned int)) axf->update, - (caddr_t) &ctx); - } - + err = axf->update(&ctx, (FAR uint8_t *)buf, crd->crd_len); if (err) { return err; @@ -624,7 +288,7 @@ int swcr_authcompute(FAR struct cryptop *crp, case CRYPTO_SHA2_512_HMAC: if (sw->sw_octx == NULL) { - return EINVAL; + return -EINVAL; } axf->final(aalg, &ctx); @@ -632,17 +296,13 @@ int swcr_authcompute(FAR struct cryptop *crp, axf->update(&ctx, aalg, axf->hashsize); axf->final(aalg, &ctx); break; + default: + return -EINVAL; } - if (outtype == CRYPTO_BUF_MBUF) - { - COPYBACK(outtype, buf, crd->crd_inject, axf->hashsize, aalg); - } - else - { - bcopy(aalg, crp->crp_mac, axf->hashsize); - } + /* Inject the authentication data */ + bcopy(aalg, crp->crp_mac, axf->hashsize); return 0; } @@ -663,15 +323,12 @@ int swcr_authenc(FAR struct cryptop *crp) FAR struct swcr_data *swe = NULL; FAR const struct auth_hash *axf = NULL; FAR const struct enc_xform *exf = NULL; - FAR struct mbuf *m = NULL; - FAR struct uio *uio = NULL; caddr_t buf = (caddr_t)crp->crp_buf; FAR uint32_t *blkp; int blksz = 0; int ivlen = 0; int iskip = 0; int oskip = 0; - int outtype; int aadlen; int len; int i; @@ -684,7 +341,7 @@ int swcr_authenc(FAR struct cryptop *crp) if (sw == NULL) { - return EINVAL; + return -EINVAL; } switch (sw->sw_alg) @@ -706,31 +363,20 @@ int swcr_authenc(FAR struct cryptop *crp) axf = swa->sw_axf; if (swa->sw_ictx == 0) { - return EINVAL; + return -EINVAL; } bcopy(swa->sw_ictx, &ctx, axf->ctxsize); blksz = axf->blocksize; break; default: - return EINVAL; + return -EINVAL; } } if (crde == NULL || crda == NULL) { - return EINVAL; - } - - if (crp->crp_flags & CRYPTO_F_IMBUF) - { - outtype = CRYPTO_BUF_MBUF; - m = (struct mbuf *)buf; - } - else - { - outtype = CRYPTO_BUF_IOV; - uio = (struct uio *)buf; + return -EINVAL; } /* Initialize the IV */ @@ -748,11 +394,9 @@ int swcr_authenc(FAR struct cryptop *crp) arc4random_buf(iv, ivlen); } - /* Do we need to write the IV */ - - if (!(crde->crd_flags & CRD_F_IV_PRESENT)) + if (!((crde->crd_flags) & CRD_F_IV_PRESENT)) { - COPYBACK(outtype, buf, crde->crd_inject, ivlen, iv); + bcopy(iv, buf + crde->crd_inject, ivlen); } } else @@ -769,7 +413,7 @@ int swcr_authenc(FAR struct cryptop *crp) { /* Get IV off buf */ - COPYDATA(outtype, buf, crde->crd_inject, ivlen, iv); + bcopy(iv, buf + crde->crd_inject, ivlen); } } @@ -798,7 +442,7 @@ int swcr_authenc(FAR struct cryptop *crp) /* SPI */ - COPYDATA(outtype, buf, crda->crd_skip, 4, blk); + bcopy(buf + crda->crd_skip, blk, 4); iskip = 4; /* loop below will start with an offset of 4 */ /* ESN */ @@ -810,7 +454,7 @@ int swcr_authenc(FAR struct cryptop *crp) for (i = iskip; i < crda->crd_len; i += axf->hashsize) { len = MIN(crda->crd_len - i, axf->hashsize - oskip); - COPYDATA(outtype, buf, crda->crd_skip + i, len, blk + oskip); + bcopy(buf + crda->crd_skip + i, blk + oskip, len); bzero(blk + len + oskip, axf->hashsize - len - oskip); axf->update(&ctx, blk, axf->hashsize); oskip = 0; /* reset initial output offset */ @@ -831,7 +475,7 @@ int swcr_authenc(FAR struct cryptop *crp) bzero(blk, blksz); } - COPYDATA(outtype, buf, crde->crd_skip + i, len, blk); + bcopy(buf + i, blk, len); if (crde->crd_flags & CRD_F_ENCRYPT) { exf->encrypt((caddr_t)swe->sw_kschedule, blk); @@ -843,7 +487,7 @@ int swcr_authenc(FAR struct cryptop *crp) exf->decrypt((caddr_t)swe->sw_kschedule, blk); } - COPYBACK(outtype, buf, crde->crd_skip + i, len, blk); + bcopy(blk, crp->crp_dst + i, len); } /* Do any required special finalization */ @@ -883,14 +527,7 @@ int swcr_authenc(FAR struct cryptop *crp) /* Inject the authentication data */ - if (outtype == CRYPTO_BUF_MBUF) - { - COPYBACK(outtype, buf, crda->crd_inject, axf->authsize, aalg); - } - else - { - bcopy(aalg, crp->crp_mac, axf->authsize); - } + bcopy(aalg, crp->crp_mac, axf->authsize); return 0; } @@ -903,7 +540,6 @@ int swcr_compdec(FAR struct cryptodesc *crd, FAR struct swcr_data *sw, FAR uint8_t *data; FAR uint8_t *out; FAR const struct comp_algo *cxf; - int adj; uint32_t result; cxf = sw->sw_cxf; @@ -913,13 +549,14 @@ int swcr_compdec(FAR struct cryptodesc *crd, FAR struct swcr_data *sw, * copy in a buffer. */ - data = malloc(crd->crd_len, M_CRYPTO_DATA, M_NOWAIT); + data = kmm_malloc(crd->crd_len); if (data == NULL) { - return EINVAL; + return -EINVAL; } - COPYDATA(outtype, buf, crd->crd_skip, crd->crd_len, data); + bcopy(buf + crd->crd_skip, data, crd->crd_len); + if (crd->crd_flags & CRD_F_COMP) { result = cxf->compress(data, crd->crd_len, &out); @@ -929,16 +566,12 @@ int swcr_compdec(FAR struct cryptodesc *crd, FAR struct swcr_data *sw, result = cxf->decompress(data, crd->crd_len, &out); } - free(data, M_CRYPTO_DATA, crd->crd_len); + kmm_free(data); if (result == 0) { - return EINVAL; + return -EINVAL; } - /* Copy back the (de)compressed data. m_copyback is - * extending the mbuf as necessary. - */ - sw->sw_size = result; /* Check the compressed size when doing compression */ @@ -949,45 +582,13 @@ int swcr_compdec(FAR struct cryptodesc *crd, FAR struct swcr_data *sw, { /* Compression was useless, we lost time */ - free(out, M_CRYPTO_DATA, result); + kmm_free(out); return 0; } } - COPYBACK(outtype, buf, crd->crd_skip, result, out); - if (result < crd->crd_len) - { - adj = result - crd->crd_len; - if (outtype == CRYPTO_BUF_MBUF) - { - adj = result - crd->crd_len; - m_adj((FAR struct mbuf *)buf, adj); - } - else - { - FAR struct uio *uio = (FAR struct uio *)buf; - int ind; - - adj = crd->crd_len - result; - ind = uio->uio_iovcnt - 1; - - while (adj > 0 && ind >= 0) - { - if (adj < uio->uio_iov[ind].iov_len) - { - uio->uio_iov[ind].iov_len -= adj; - break; - } - - adj -= uio->uio_iov[ind].iov_len; - uio->uio_iov[ind].iov_len = 0; - ind--; - uio->uio_iovcnt--; - } - } - } - - free(out, M_CRYPTO_DATA, result); + bcopy(out, buf + crd->crd_skip, result); + kmm_free(out); return 0; } @@ -998,13 +599,12 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) FAR struct swcr_data **swd; FAR const struct auth_hash *axf; FAR const struct enc_xform *txf; - FAR const struct comp_algo *cxf; uint32_t i; int k; if (sid == NULL || cri == NULL) { - return EINVAL; + return -EINVAL; } if (swcr_sessions) @@ -1030,8 +630,7 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) swcr_sesnum *= 2; } - swd = mallocarray(swcr_sesnum, sizeof(struct swcr_data *), - M_CRYPTO_DATA, M_NOWAIT | M_ZERO); + swd = kmm_calloc(swcr_sesnum, sizeof(struct swcr_data *)); if (swd == NULL) { /* Reset session number */ @@ -1045,7 +644,7 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) swcr_sesnum /= 2; } - return ENOBUFS; + return -ENOBUFS; } /* Copy existing sessions */ @@ -1054,7 +653,7 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) { bcopy(swcr_sessions, swd, (swcr_sesnum / 2) * sizeof(struct swcr_data *)); - free(swcr_sessions, M_CRYPTO_DATA, 0); + kmm_free(swcr_sessions); } swcr_sessions = swd; @@ -1065,12 +664,11 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) while (cri) { - *swd = malloc(sizeof(struct swcr_data), M_CRYPTO_DATA, - M_NOWAIT | M_ZERO); + *swd = kmm_zalloc(sizeof(struct swcr_data)); if (*swd == NULL) { swcr_freesession(i); - return ENOBUFS; + return -ENOBUFS; } switch (cri->cri_alg) @@ -1109,12 +707,11 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) enccommon: if (txf->ctxsize > 0) { - (*swd)->sw_kschedule = malloc(txf->ctxsize, - M_CRYPTO_DATA, M_NOWAIT | M_ZERO); + (*swd)->sw_kschedule = kmm_zalloc(txf->ctxsize); if ((*swd)->sw_kschedule == NULL) { swcr_freesession(i); - return EINVAL; + return -EINVAL; } } @@ -1123,7 +720,7 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) cri->cri_klen / 8) < 0) { swcr_freesession(i); - return EINVAL; + return -EINVAL; } (*swd)->sw_exf = txf; @@ -1147,20 +744,18 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) case CRYPTO_SHA2_512_HMAC: axf = &auth_hash_hmac_sha2_512_256; authcommon: - (*swd)->sw_ictx = malloc(axf->ctxsize, M_CRYPTO_DATA, - M_NOWAIT); + (*swd)->sw_ictx = kmm_malloc(axf->ctxsize); if ((*swd)->sw_ictx == NULL) { swcr_freesession(i); - return ENOBUFS; + return -ENOBUFS; } - (*swd)->sw_octx = malloc(axf->ctxsize, M_CRYPTO_DATA, - M_NOWAIT); + (*swd)->sw_octx = kmm_malloc(axf->ctxsize); if ((*swd)->sw_octx == NULL) { swcr_freesession(i); - return ENOBUFS; + return -ENOBUFS; } for (k = 0; k < cri->cri_klen / 8; k++) @@ -1209,12 +804,11 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) axf = &auth_hash_chacha20_poly1305; auth4common: - (*swd)->sw_ictx = malloc(axf->ctxsize, M_CRYPTO_DATA, - M_NOWAIT); + (*swd)->sw_ictx = kmm_malloc(axf->ctxsize); if ((*swd)->sw_ictx == NULL) { swcr_freesession(i); - return ENOBUFS; + return -ENOBUFS; } axf->init((*swd)->sw_ictx); @@ -1223,10 +817,6 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) (*swd)->sw_axf = axf; break; - case CRYPTO_DEFLATE_COMP: - cxf = &comp_algo_deflate; - (*swd)->sw_cxf = cxf; - break; case CRYPTO_ESN: /* nothing to do */ @@ -1234,7 +824,7 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) break; default: swcr_freesession(i); - return EINVAL; + return -EINVAL; } (*swd)->sw_alg = cri->cri_alg; @@ -1257,7 +847,7 @@ int swcr_freesession(uint64_t tid) if (sid > swcr_sesnum || swcr_sessions == NULL || swcr_sessions[sid] == NULL) { - return EINVAL; + return -EINVAL; } /* Silently accept and return */ @@ -1288,7 +878,7 @@ int swcr_freesession(uint64_t tid) if (swd->sw_kschedule) { explicit_bzero(swd->sw_kschedule, txf->ctxsize); - free(swd->sw_kschedule, M_CRYPTO_DATA, 0); + kmm_free(swd->sw_kschedule); } break; @@ -1304,13 +894,13 @@ int swcr_freesession(uint64_t tid) if (swd->sw_ictx) { explicit_bzero(swd->sw_ictx, axf->ctxsize); - free(swd->sw_ictx, M_CRYPTO_DATA, 0); + kmm_free(swd->sw_ictx); } if (swd->sw_octx) { explicit_bzero(swd->sw_octx, axf->ctxsize); - free(swd->sw_octx, M_CRYPTO_DATA, 0); + kmm_free(swd->sw_octx); } break; @@ -1324,13 +914,13 @@ int swcr_freesession(uint64_t tid) if (swd->sw_ictx) { explicit_bzero(swd->sw_ictx, axf->ctxsize); - free(swd->sw_ictx, M_CRYPTO_DATA, 0); + kmm_free(swd->sw_ictx); } break; } - free(swd, M_CRYPTO_DATA, 0); + kmm_free(swd); } return 0; @@ -1343,37 +933,27 @@ int swcr_process(struct cryptop *crp) FAR struct cryptodesc *crd; FAR struct swcr_data *sw; uint32_t lid; - int type; /* Sanity check */ if (crp == NULL) { - return EINVAL; + return -EINVAL; } if (crp->crp_desc == NULL || crp->crp_buf == NULL) { - crp->crp_etype = EINVAL; + crp->crp_etype = -EINVAL; goto done; } lid = crp->crp_sid & 0xffffffff; if (lid >= swcr_sesnum || lid == 0 || swcr_sessions[lid] == NULL) { - crp->crp_etype = ENOENT; + crp->crp_etype = -ENOENT; goto done; } - if (crp->crp_flags & CRYPTO_F_IMBUF) - { - type = CRYPTO_BUF_MBUF; - } - else - { - type = CRYPTO_BUF_IOV; - } - /* Go through crypto descriptors, processing as we go */ for (crd = crp->crp_desc; crd; crd = crd->crd_next) @@ -1395,7 +975,7 @@ int swcr_process(struct cryptop *crp) if (sw == NULL) { - crp->crp_etype = EINVAL; + crp->crp_etype = -EINVAL; goto done; } @@ -1412,8 +992,8 @@ int swcr_process(struct cryptop *crp) case CRYPTO_RIJNDAEL128_CBC: case CRYPTO_AES_CTR: case CRYPTO_AES_XTS: - if ((crp->crp_etype = swcr_encdec(crd, sw, - crp->crp_buf, type)) != 0) + if ((crp->crp_etype = swcr_encdec(crp, crd, sw, + crp->crp_buf)) != 0) { goto done; } @@ -1426,7 +1006,7 @@ int swcr_process(struct cryptop *crp) case CRYPTO_SHA2_384_HMAC: case CRYPTO_SHA2_512_HMAC: if ((crp->crp_etype = swcr_authcompute(crp, crd, sw, - crp->crp_buf, type)) != 0) + crp->crp_buf)) != 0) { goto done; } @@ -1442,31 +1022,18 @@ int swcr_process(struct cryptop *crp) case CRYPTO_CHACHA20_POLY1305_MAC: crp->crp_etype = swcr_authenc(crp); goto done; - - case CRYPTO_DEFLATE_COMP: - if ((crp->crp_etype = swcr_compdec(crd, sw, - crp->crp_buf, type)) != 0) - { - goto done; - } - else - { - crp->crp_olen = (int)sw->sw_size; - } - break; default: /* Unknown/unsupported algorithm */ - crp->crp_etype = EINVAL; + crp->crp_etype = -EINVAL; goto done; } } done: - crypto_done(crp); return 0; } @@ -1483,7 +1050,7 @@ void swcr_init(void) { /* This should never happen */ - panic("Software crypto device cannot initialize!"); + PANIC(); } algs[CRYPTO_3DES_CBC] = CRYPTO_ALG_FLAG_SUPPORTED; @@ -1497,7 +1064,6 @@ void swcr_init(void) algs[CRYPTO_AES_XTS] = CRYPTO_ALG_FLAG_SUPPORTED; algs[CRYPTO_AES_GCM_16] = CRYPTO_ALG_FLAG_SUPPORTED; algs[CRYPTO_AES_GMAC] = CRYPTO_ALG_FLAG_SUPPORTED; - algs[CRYPTO_DEFLATE_COMP] = CRYPTO_ALG_FLAG_SUPPORTED; algs[CRYPTO_NULL] = CRYPTO_ALG_FLAG_SUPPORTED; algs[CRYPTO_SHA2_256_HMAC] = CRYPTO_ALG_FLAG_SUPPORTED; algs[CRYPTO_SHA2_384_HMAC] = CRYPTO_ALG_FLAG_SUPPORTED; diff --git a/crypto/des_locl.h b/crypto/des_locl.h index 46564bf2f9..2da7500e9e 100644 --- a/crypto/des_locl.h +++ b/crypto/des_locl.h @@ -59,7 +59,6 @@ ****************************************************************************/ #include <sys/types.h> -#include <sys/systm.h> typedef unsigned char des_cblock[8]; typedef struct des_ks_struct diff --git a/crypto/gmac.c b/crypto/gmac.c index 83ca183452..d05b601aa6 100644 --- a/crypto/gmac.c +++ b/crypto/gmac.c @@ -28,9 +28,9 @@ * Included Files ****************************************************************************/ +#include <endian.h> +#include <strings.h> #include <sys/param.h> -#include <sys/systm.h> - #include <crypto/aes.h> #include <crypto/gmac.h> diff --git a/crypto/hmac.c b/crypto/hmac.c index 80494a4259..a21752ff3d 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c @@ -26,8 +26,9 @@ * Included Files ****************************************************************************/ +#include <string.h> +#include <strings.h> #include <sys/param.h> -#include <sys/systm.h> #include <crypto/md5.h> #include <crypto/sha1.h> diff --git a/crypto/idgen.c b/crypto/idgen.c index 1af2e4c99c..841eabba57 100644 --- a/crypto/idgen.c +++ b/crypto/idgen.c @@ -26,8 +26,11 @@ * Included Files ****************************************************************************/ +#include <string.h> +#include <strings.h> +#include <stdlib.h> +#include <nuttx/clock.h> #include <sys/types.h> -#include <sys/systm.h> #include <sys/time.h> #include <crypto/idgen.h> @@ -119,7 +122,8 @@ static void idgen32_rekey(FAR struct idgen32_ctx *ctx) ctx->id32_hibit ^= 0x80000000; ctx->id32_offset = arc4random(); arc4random_buf(ctx->id32_key, sizeof(ctx->id32_key)); - ctx->id32_rekey_time = getuptime() + IDGEN32_REKEY_TIME; + ctx->id32_rekey_time = TICK2SEC(clock_systime_ticks()) + + IDGEN32_REKEY_TIME; } /**************************************************************************** @@ -142,7 +146,7 @@ uint32_t idgen32(FAR struct idgen32_ctx *ctx) /* Rekey a little early to avoid "card counting" attack */ if (ctx->id32_counter > IDGEN32_REKEY_LIMIT || - ctx->id32_rekey_time < getuptime()) + ctx->id32_rekey_time < TICK2SEC(clock_systime_ticks())) { idgen32_rekey(ctx); } diff --git a/crypto/key_wrap.c b/crypto/key_wrap.c index 2bb996acfa..8c88386eb2 100644 --- a/crypto/key_wrap.c +++ b/crypto/key_wrap.c @@ -23,9 +23,9 @@ * Included Files ****************************************************************************/ +#include <endian.h> +#include <string.h> #include <sys/param.h> -#include <sys/systm.h> - #include <crypto/aes.h> #include <crypto/key_wrap.h> diff --git a/crypto/md5.c b/crypto/md5.c index c278b2e29c..ffc05ba02c 100644 --- a/crypto/md5.c +++ b/crypto/md5.c @@ -22,8 +22,9 @@ * Included Files ****************************************************************************/ +#include <endian.h> +#include <string.h> #include <sys/param.h> -#include <sys/systm.h> #include <crypto/md5.h> #define PUT_64BIT_LE(cp, value) \ diff --git a/crypto/poly1305.c b/crypto/poly1305.c index a85d0490ba..20d81ce6fd 100644 --- a/crypto/poly1305.c +++ b/crypto/poly1305.c @@ -12,7 +12,6 @@ ****************************************************************************/ #include <sys/types.h> -#include <sys/systm.h> #include <crypto/poly1305.h> diff --git a/crypto/rijndael.c b/crypto/rijndael.c index b51537a1bb..a7491bd568 100644 --- a/crypto/rijndael.c +++ b/crypto/rijndael.c @@ -32,7 +32,6 @@ ****************************************************************************/ #include <sys/param.h> -#include <sys/systm.h> #include <crypto/rijndael.h> diff --git a/crypto/rmd160.c b/crypto/rmd160.c index 35ab189696..668bc50f95 100644 --- a/crypto/rmd160.c +++ b/crypto/rmd160.c @@ -35,8 +35,8 @@ ****************************************************************************/ #include <sys/param.h> -#include <sys/systm.h> -#include <sys/endian.h> +#include <endian.h> +#include <string.h> #include <crypto/rmd160.h> #define PUT_64BIT_LE(cp, value) \ diff --git a/crypto/set_key.c b/crypto/set_key.c index e895d70598..1c1af75b84 100644 --- a/crypto/set_key.c +++ b/crypto/set_key.c @@ -61,6 +61,8 @@ * Included Files ****************************************************************************/ +#include <strings.h> + #include "des_locl.h" #include "podd.h" #include "sk.h" diff --git a/crypto/sha1.c b/crypto/sha1.c index 433a275a19..f1ea87b610 100644 --- a/crypto/sha1.c +++ b/crypto/sha1.c @@ -20,8 +20,9 @@ * Included Files ****************************************************************************/ +#include <endian.h> +#include <string.h> #include <sys/param.h> -#include <sys/systm.h> #include <crypto/sha1.h> diff --git a/crypto/sha2.c b/crypto/sha2.c index 40c486e7ed..76af7d18ee 100644 --- a/crypto/sha2.c +++ b/crypto/sha2.c @@ -38,8 +38,9 @@ * Included Files ****************************************************************************/ +#include <endian.h> +#include <string.h> #include <sys/time.h> -#include <sys/systm.h> #include <crypto/sha2.h> /* UNROLLED TRANSFORM LOOP NOTE: diff --git a/crypto/siphash.c b/crypto/siphash.c index f8c36918cb..73bf48e7c4 100644 --- a/crypto/siphash.c +++ b/crypto/siphash.c @@ -48,8 +48,9 @@ * Included Files ****************************************************************************/ +#include <endian.h> +#include <string.h> #include <sys/param.h> -#include <sys/systm.h> #include <crypto/siphash.h> diff --git a/crypto/sk.h b/crypto/sk.h index 7a851a4287..54c022e854 100644 --- a/crypto/sk.h +++ b/crypto/sk.h @@ -51,6 +51,12 @@ * [including the GNU Public Licence.] ****************************************************************************/ +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + static const uint32_t des_skb[8][64] = { { diff --git a/crypto/spr.h b/crypto/spr.h index c26fd4ab05..5ff6c5350a 100644 --- a/crypto/spr.h +++ b/crypto/spr.h @@ -50,6 +50,12 @@ * [including the GNU Public Licence.] ****************************************************************************/ +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + static const uint32_t des_sptrans[8][64] = { { diff --git a/crypto/xform.c b/crypto/xform.c index 11276f4541..830d6156e0 100644 --- a/crypto/xform.c +++ b/crypto/xform.c @@ -53,12 +53,11 @@ * Included Files ****************************************************************************/ +#include <errno.h> +#include <string.h> +#include <strings.h> #include <sys/param.h> -#include <sys/systm.h> -#include <sys/errno.h> #include <sys/time.h> -#include <sys/kernel.h> -#include <machine/cpu.h> #include <crypto/md5.h> #include <crypto/sha1.h> @@ -118,9 +117,6 @@ int sha256update_int(FAR void *, FAR const uint8_t *, uint16_t); int sha384update_int(FAR void *, FAR const uint8_t *, uint16_t); int sha512update_int(FAR void *, FAR const uint8_t *, uint16_t); -uint32_t deflate_compress(FAR uint8_t *, uint32_t, FAR uint8_t **); -uint32_t deflate_decompress(FAR uint8_t *, uint32_t, FAR uint8_t **); - struct aes_ctr_ctx { AES_CTX ac_key; @@ -337,15 +333,6 @@ const struct auth_hash auth_hash_chacha20_poly1305 = chacha20_poly1305_final }; -/* Compression instance */ - -const struct comp_algo comp_algo_deflate = -{ - CRYPTO_DEFLATE_COMP, "Deflate", - 90, deflate_compress, - deflate_decompress -}; - /* Encryption wrapper routines. */ void des3_encrypt(caddr_t key, FAR uint8_t *blk) @@ -633,28 +620,3 @@ int sha512update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len) sha512update(ctx, buf, len); return 0; } - -uint32_t deflate_global(FAR uint8_t *, uint32_t, int, FAR uint8_t **); - -struct deflate_buf -{ - FAR uint8_t *out; - uint32_t size; - int flag; -}; - -/* And compression */ - -uint32_t deflate_compress(FAR uint8_t *data, - uint32_t size, - FAR uint8_t **out) -{ - return deflate_global(data, size, 0, out); -} - -uint32_t deflate_decompress(FAR uint8_t *data, - uint32_t size, - FAR uint8_t **out) -{ - return deflate_global(data, size, 1, out); -} diff --git a/include/crypto/aes.h b/include/crypto/aes.h index 1b7f281486..aa0f4fceb7 100644 --- a/include/crypto/aes.h +++ b/include/crypto/aes.h @@ -29,6 +29,12 @@ #ifndef __INCLUDE_CRYPTO_AES_H #define __INCLUDE_CRYPTO_AES_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + #ifndef AES_MAXROUNDS # define AES_MAXROUNDS (14) #endif diff --git a/include/crypto/blf.h b/include/crypto/blf.h index 403174098f..daf7941b86 100644 --- a/include/crypto/blf.h +++ b/include/crypto/blf.h @@ -33,6 +33,12 @@ #ifndef __INCLUDE_CRYPTO_BLF_H #define __INCLUDE_CRYPTO_BLF_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + /* Schneier states the maximum key length to be 56 bytes. * The way how the subkeys are initialized by the key up * to (N+2)*4 i.e. 72 bytes are utilized. diff --git a/include/crypto/cmac.h b/include/crypto/cmac.h index e7cc14ff6a..7a8c948c7d 100644 --- a/include/crypto/cmac.h +++ b/include/crypto/cmac.h @@ -21,6 +21,12 @@ #ifndef __INCLUDE_CRYPTO_CMAC_H_ #define __INCLUDE_CRYPTO_CMAC_H_ +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + #define AES_CMAC_KEY_LENGTH 16 #define AES_CMAC_DIGEST_LENGTH 16 diff --git a/include/crypto/cryptodev.h b/include/crypto/cryptodev.h index 303894474d..e0c1815009 100644 --- a/include/crypto/cryptodev.h +++ b/include/crypto/cryptodev.h @@ -55,8 +55,7 @@ * Included Files ****************************************************************************/ -#include <sys/ioccom.h> -#include <sys/task.h> +#include <sys/types.h> /* Some initial values */ @@ -173,7 +172,6 @@ struct cryptodesc struct cryptop { - struct task crp_task; uint64_t crp_sid; /* Session ID */ int crp_ilen; /* Input data total length */ int crp_olen; /* Result total length */ @@ -202,6 +200,7 @@ struct cryptop CODE int (*crp_callback)(FAR struct cryptop *); /* Callback function */ caddr_t crp_mac; + caddr_t crp_dst; }; #define CRYPTO_BUF_IOV 0x1 @@ -245,8 +244,6 @@ struct crypt_kop struct cryptkop { - struct task krp_task; - u_int krp_op; /* ie. CRK_MOD_EXP or other */ u_int krp_status; /* return status */ u_short krp_iparams; /* # of input parameters */ @@ -322,21 +319,18 @@ struct crypt_op * Please use F_SETFD against the cloned descriptor. */ -#define CRIOGET _IOWR('c', 100, uint32_t) +#define CRIOGET 100 /* the following are done against the cloned descriptor */ -#define CIOCGSESSION _IOWR('c', 101, struct session_op) -#define CIOCFSESSION _IOW('c', 102, uint32_t) -#define CIOCCRYPT _IOWR('c', 103, struct crypt_op) -#define CIOCKEY _IOWR('c', 104, struct crypt_kop) -#define CIOCASYMFEAT _IOR('c', 105, uint32_t) +#define CIOCGSESSION 101 +#define CIOCFSESSION 102 +#define CIOCCRYPT 103 +#define CIOCKEY 104 +#define CIOCASYMFEAT 105 -#ifdef _KERNEL int crypto_newsession(FAR uint64_t *, FAR struct cryptoini *, int); int crypto_freesession(uint64_t); -int crypto_dispatch(FAR struct cryptop *); -int crypto_kdispatch(FAR struct cryptkop *); int crypto_register(uint32_t, FAR int *, CODE int (*)(uint32_t *, struct cryptoini *), CODE int (*)(uint64_t), @@ -346,17 +340,8 @@ int crypto_unregister(uint32_t, int); int crypto_get_driverid(uint8_t); int crypto_invoke(FAR struct cryptop *); int crypto_kinvoke(FAR struct cryptkop *); -void crypto_done(FAR struct cryptop *); -void crypto_kdone(FAR struct cryptkop *); int crypto_getfeat(FAR int *); -void cuio_copydata(FAR struct uio *, int, int, caddr_t); -void cuio_copyback(FAR struct uio *, int, int, const void *); -int cuio_getptr(FAR struct uio *, int, FAR int *); -int cuio_apply(FAR struct uio *, int, int, - CODE int (*f)(caddr_t, caddr_t, unsigned int), caddr_t); - FAR struct cryptop *crypto_getreq(int); void crypto_freereq(FAR struct cryptop *); -#endif /* _KERNEL */ #endif /* __INCLUDE_CRYPTO_CRYPTODEV_H */ diff --git a/include/crypto/cryptosoft.h b/include/crypto/cryptosoft.h index 52fb1bdfeb..ea8af3aa7b 100644 --- a/include/crypto/cryptosoft.h +++ b/include/crypto/cryptosoft.h @@ -30,6 +30,9 @@ * Included Files ****************************************************************************/ +#include <sys/queue.h> +#include <crypto/cryptodev.h> + /* Software session entry */ struct swcr_data @@ -70,14 +73,13 @@ struct swcr_data struct swcr_data *sw_next; }; -#ifdef _KERNEL extern const uint8_t hmac_ipad_buffer[HMAC_MAX_BLOCK_LEN]; extern const uint8_t hmac_opad_buffer[HMAC_MAX_BLOCK_LEN]; -int swcr_encdec(FAR struct cryptodesc *, - FAR struct swcr_data *, caddr_t, int); +int swcr_encdec(FAR struct cryptop *, FAR struct cryptodesc *, + FAR struct swcr_data *, caddr_t); int swcr_authcompute(FAR struct cryptop *, FAR struct cryptodesc *, - FAR struct swcr_data *, caddr_t, int); + FAR struct swcr_data *, caddr_t); int swcr_authenc(FAR struct cryptop *); int swcr_compdec(FAR struct cryptodesc *, FAR struct swcr_data *, caddr_t, int); @@ -85,6 +87,5 @@ int swcr_process(FAR struct cryptop *); int swcr_newsession(FAR uint32_t *, FAR struct cryptoini *); int swcr_freesession(uint64_t); void swcr_init(void); -#endif /* _KERNEL */ #endif /* __INCLUDE_CRYPTO_CRYPTOSOFT_H */ diff --git a/include/crypto/gmac.h b/include/crypto/gmac.h index 83d1dc435c..9dee9fa251 100644 --- a/include/crypto/gmac.h +++ b/include/crypto/gmac.h @@ -24,6 +24,7 @@ * Included Files ****************************************************************************/ +#include <sys/types.h> #include <crypto/aes.h> #define GMAC_BLOCK_LEN 16 diff --git a/include/crypto/hmac.h b/include/crypto/hmac.h index ca6cd7038a..ed69bfae32 100644 --- a/include/crypto/hmac.h +++ b/include/crypto/hmac.h @@ -21,6 +21,12 @@ #ifndef __INCLUDE_CRYPTO_HMAC_H_ #define __INCLUDE_CRYPTO_HMAC_H_ +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + typedef struct _HMAC_MD5_CTX { MD5_CTX ctx; diff --git a/include/crypto/key_wrap.h b/include/crypto/key_wrap.h index e0e2314528..e6b23c28f3 100644 --- a/include/crypto/key_wrap.h +++ b/include/crypto/key_wrap.h @@ -20,6 +20,12 @@ #ifndef __INCLUDE_CRYPTO_KEY_WRAP_H_ #define __INCLUDE_CRYPTO_KEY_WRAP_H_ +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + typedef struct _aes_key_wrap_ctx { AES_CTX ctx; diff --git a/include/crypto/md5.h b/include/crypto/md5.h index e0c4239c66..1b6d04e6ee 100644 --- a/include/crypto/md5.h +++ b/include/crypto/md5.h @@ -18,6 +18,12 @@ #ifndef __INCLUDE_CRYPTO_MD5_H #define __INCLUDE_CRYPTO_MD5_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + #define MD5_BLOCK_LENGTH 64 #define MD5_DIGEST_LENGTH 16 diff --git a/include/crypto/poly1305.h b/include/crypto/poly1305.h index 29064067c0..74ed68978c 100644 --- a/include/crypto/poly1305.h +++ b/include/crypto/poly1305.h @@ -11,6 +11,12 @@ #ifndef __INCLUDE_CRYPTO_POLY1305_H #define __INCLUDE_CRYPTO_POLY1305_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + #define poly1305_block_size 16 typedef struct poly1305_state diff --git a/include/crypto/rijndael.h b/include/crypto/rijndael.h index 2f0108e708..c90bffab78 100644 --- a/include/crypto/rijndael.h +++ b/include/crypto/rijndael.h @@ -30,6 +30,12 @@ #ifndef __INCLUDE_CRYPTO_RIJNDAEL_H #define __INCLUDE_CRYPTO_RIJNDAEL_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + #define AES_MAXKEYBITS (256) #define AES_MAXKEYBYTES (AES_MAXKEYBITS / 8) diff --git a/include/crypto/rmd160.h b/include/crypto/rmd160.h index d7716812e0..aa67a9a8a5 100644 --- a/include/crypto/rmd160.h +++ b/include/crypto/rmd160.h @@ -28,6 +28,12 @@ #ifndef __INCLUDE_CRYPTO_RMD160_H #define __INCLUDE_CRYPTO_RMD160_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + #define RMD160_BLOCK_LENGTH 64 #define RMD160_DIGEST_LENGTH 20 diff --git a/include/crypto/sha1.h b/include/crypto/sha1.h index 34d7cdf00e..024dc9b14e 100644 --- a/include/crypto/sha1.h +++ b/include/crypto/sha1.h @@ -9,6 +9,12 @@ #ifndef __INCLUDE_CRYPTO_SHA1_H #define __INCLUDE_CRYPTO_SHA1_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + #define SHA1_BLOCK_LENGTH 64 #define SHA1_DIGEST_LENGTH 20 diff --git a/include/crypto/sha2.h b/include/crypto/sha2.h index 152a2ff9f1..b5e3a5a59b 100644 --- a/include/crypto/sha2.h +++ b/include/crypto/sha2.h @@ -38,6 +38,12 @@ #ifndef __INCLUDE_CRYPTO_SHA2_H #define __INCLUDE_CRYPTO_SHA2_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + /* SHA-256/384/512 Various Length Definitions */ #define SHA256_BLOCK_LENGTH 64 diff --git a/include/crypto/siphash.h b/include/crypto/siphash.h index 2111c1c60f..42d51fd340 100644 --- a/include/crypto/siphash.h +++ b/include/crypto/siphash.h @@ -51,6 +51,12 @@ #ifndef __INCLUDE_CRYPTO_SIPHASH_H_ #define __INCLUDE_CRYPTO_SIPHASH_H_ +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> + #define SIPHASH_BLOCK_LENGTH 8 #define SIPHASH_KEY_LENGTH 16 #define SIPHASH_DIGEST_LENGTH 8 diff --git a/include/crypto/xform.h b/include/crypto/xform.h index 35a7499ec2..1b9d248fad 100644 --- a/include/crypto/xform.h +++ b/include/crypto/xform.h @@ -29,6 +29,7 @@ * Included Files ****************************************************************************/ +#include <sys/types.h> #include <crypto/md5.h> #include <crypto/sha1.h> #include <crypto/rmd160.h> @@ -116,6 +117,4 @@ extern const struct auth_hash auth_hash_gmac_aes_192; extern const struct auth_hash auth_hash_gmac_aes_256; extern const struct auth_hash auth_hash_chacha20_poly1305; -extern const struct comp_algo comp_algo_deflate; - #endif /* __INCLUDE_CRYPTO_XFORM_H */