summaryrefslogtreecommitdiff
path: root/crypt_common.c (follow)
Commit message (Collapse)AuthorAge
* Switch to SPDX identifiers.Andre Noll2026-03-17
| | | | | | | | Generated with sed -i 's|Copyright.*Andre Noll.*|SPDX-License-Identifier: GPL-2.0 */|g' *.c *.h followed by manually tweaking the result a bit. No license change intended.
* Remove support for PEM private keys.Andre Noll2026-01-28
| | | | | This gets us rid of a couple of hand-written parsers, which can only be a good thing. The shortstat says it all...
* crypt_common.c: Remove pointless check in decode_public_key().Andre Noll2025-12-18
| | | | This goto is a no-op.
* crypt_common.c: Simplify base64_decode().Andre Noll2025-10-11
| | | | | Neither of the two callers makes use of the "-1 means check for length" feature of this function. Drop the feature.
* Move base64.c into crypt_common.c.Andre Noll2025-10-11
| | | | | Both public functions of base64.c, uudecode() and base64_decode(), are only called from crypt_common.c. Now they can be made static.
* Rename hash2 -> hash.Andre Noll2025-05-22
| | | | | Now that sha1 is no longer supported, the hash2 naming has become meaningless. Rename it back to "hash".
* Remove sha1.Andre Noll2025-05-22
| | | | | | | | | | | | | | | | Server and client prefer sha256 in the authentication protocol since paraslash-0.7.0, while 0.6.x clients and servers only know about sha1. This patch drops the compatibility code which enabled old clients to connect to new servers and vice versa. Now the client code no longer checks whether the sha256 feature is supported, but requests and uses the feature unconditionally. The server still announces the sha256 feature and accepts the corresponding feature request, but uses sha256 unconditionally. With this approach older 0.7.x clients are still compatible to current server versions and current clients can still talk to servers running older 0.7.x versions.
* Include regex.h from para.h.Andre Noll2025-05-19
| | | | Every .c file includes it anyway.
* crypt: Deprecate PEM keys.Andre Noll2023-05-14
| | | | | | | | Users have been advised since 2018 to create RFC4716 keys (see commit 9e2b093bed5d), and this has been the default key format for ssh-keygen(1) for a long time as well. Upgrade the severity of the existing log message from info to warning to encourage users at runtime to replace their old keys.
* string: Rename para_malloc() -> alloc().Andre Noll2022-07-29
| | | | | | | Just because it's shorter and matches the naming of the new allocators we are about to introduce. The bulk of this patch was created with sed -i 's/para_malloc/alloc/g' *.c *.h yy/mp.y
* Introduce hash2 (sha256).Andre Noll2021-10-21
| | | | | | This adds a second hash function which will replace sha1. Both openssl and libgcrypt support sha256, so it is easy to do. There are no users of the new functions so far, so this patch has no effect yet.
* crypt_common: Constify hash pointers.Andre Noll2020-07-11
| | | | | hash_to_asc() and hash_compare() only read from the memory locations given by these pointers.
* openssl: Add support for RFC4716 keysAndre Noll2018-12-25
| | | | | | | | | | | | | | | | | | | | | | The decode_private_key() helper of gcrypt.c base64-decodes the key but does not read the RSA bignums. It is thus independent of gcrypt and openssl. To add support for RFC4716 keys to the openssl backend, we need to move it to crypt_common.c, making it a crypo backend function. That is, non-static and declared in crypt_backend.h. The patch also documents the function using doxgen comments. With decode_private_key() and find_openssh_bignum_offset() to our disposal, supporting RFC4716 keys is simple. We only need to initialize the openssl-specific rsa structure with the six bignums stored in a private RFC4716 key. This is implemented in the new read_private_rsa_params() which calls the existing read_bignum() six times. The fields of the rsa structure are exposed to applications in openssl-1.0, but the structure was made opaque in openssl-1.1. We use the existing HAVE_RSA_SET0_KEY macro to decide whether or not we must use the accessor functions of openssl-1.1 to initialize the rsa structure.
* gcrypt: Add support for RFC4716 private keys.Andre Noll2018-12-25
| | | | | | | | | This teaches the gcrypt backend to parse private keys generated with ssh-keygen -m RFC4716. Support for the openssl backend will be implemented in a subsequent patch. The new find_openssh_bignum_offset() is independent of the gcrypt API. We put this function into crypt_common.c rather then into gcrypt.c so that openssh.c can also use it.
* crypt: Rename decoding functions.Andre Noll2018-12-25
| | | | | | | | decode_ssh_key() and decode_key() operate on public and private keys respectively. This should be obvious from the naming. Also, the two functions will soon be grouped together in the same file. The inconsistent naming would even increase the possible confusion, so it's better to rename the functions now.
* crypt: Deduplicate get_public_key().Andre Noll2018-02-26
| | | | | | | | | | | | The openssl and grypt implementations of this function share quite some code. This patch factors out the common code into the new decode_ssh_key() helper of crypt_common.c. Both implementations are changed to call the new helper. As a side effect of this change, all callers of is_ssh_rsa_key() and check_ssh_key_header() now reside in crypt_common.c, so we can make these two functions static and remove their declarations from crypt_backend.h.
* Shorten copyright notice.Andre Noll2017-09-22
| | | | | | | | | | | | | | | | | | | | | The GPLv2 line does not add any additional information, so drop it. This leaves a single line of legalese text for most files, which is about the amount of screen real estate it deserves. This patch was created with the following script (plus some manual fixups): awk '{ if (NR <= 5) { gs = gensub(/.*Copyright.* ([0-9]+).*Andre Noll.*/, "\\1", "g") if (gs != $0) year = gs next } if (NR == 6 && year != "") printf("/* Copyright (C) %s Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */\n", year) print }'
* crypt: Remove read_ssh_u32().Andre Noll2017-07-23
| | | | | It was just another implementation of read_u32_be(). This commit makes the crypto code use the helper of portable_io.h instead.
* crypto: Rename check_key_file() -> check_private_key_file().Andre Noll2017-01-06
| | | | | | | | | | | | | For public keys the function only called stat(2), which is unnecessary because only an error from the subsequent open(2) call requires to fail the operation. The stat() call is needed for loading private keys though, to make sure permissions are restrictive enough. This commit renames the function as indicated in the subject and drops the second parameter. In crypt.c we now call this function for private keys only.
* Merge branch 'refs/heads/t/format-signedness'Andre Noll2016-12-28
|\ | | | | | | | | | | | | | | | | | | | | This series fixes all warnings produced by compiling with -Wformat-signedness and adds the flag to CFLAGS if the compiler supports it. * refs/heads/t/format-signedness (cooking for ~2 weeks): gcrypt: Fix a few format-signedness issues. Compile with -Wformat-signedness if possible. Fix signedness issues in format strings.
| * Fix signedness issues in format strings.Andre Noll2016-12-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Compiling with -Wformat-signedness (not enabled so far) causes many warnings because of format strings which specify an unsigned type but correspond to an argument of signed type, or vice versa. This commit fixes all these mismatches. For "%u", "%d", "%lu", "%ld" we let the format string match the type of the argument, but for "%x" we need to cast the argument to a suitable unsigned type. After this patch the tree compiles cleanly with -Wformat-signedness given. The warning will be enabled in a subsequent commit.
* | Move base64 implementation to own file.Andre Noll2016-08-23
|/ | | | | | | The base64 decoder is independent of anything else, so it should not be part of the crypto API. This patch moves the two public functions uudecode() and base64_decode() to a new file, base64.c, and introduces base64.h to declare them.
* Update year in copyright headers.Andre Noll2015-01-12
| | | | | | | | | | | | | | | | Done with files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2014\)* Andre Noll') sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2014 Andre Noll/Copyright (C) \1 Andre Noll/1' $files In previous years we ran a similar script to set the second year in the range to the current year. This is kind of silly, so let's get rid of this useless information. This commit replaces "Copyright (C) A-B" by "Copyright (C) A" in all file headers, i.e. only the first year (A) is left in. Accurate information including time stamps for each change can be obtained from the git history.
* doc: Change email address to maan@tuebingen.mpg.deAndre Noll2014-08-18
| | | | | | | | | | | | | | The mail server on systemlinux.org was down for more than a week lately, so let's use an alternative official address. This commit changes all maan@systemlinux.org addresses to maan@tuebingen.mpg.de. Most .c and .h files contain the email address in the copyright header, so they must all be patched. Three other files contain the address for a different reason: * README lists email and git, gitweb and home page URLs * configure.ac needs it for configure -h * version.c contains it for the -V option of all commands
* crypt: Simplify base64_decode().Andre Noll2014-06-10
| | | | We never call this function with target == NULL.
* Change copyright year to 2014.Andre Noll2014-02-22
| | | | | | | | | This year, we're really on time. The changes in this patch were created by the following silly script: files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2013\)* Andre Noll') sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2013 Andre Noll/Copyright (C) \1-2014 Andre Noll/1' $files sed --in-place= -e 's/Copyright (C) 2013 Andre Noll/Copyright (C) 2013-2014 Andre Noll/1' $files
* Remove old stream cipher API.Andre Noll2013-04-03
| | | | | No users remained after the sideband compatibility code has been removed.
* Change copyright year to 2013.Andre Noll2013-03-25
| | | | Better late than never.
* Add sideband implementation.Andre Noll2012-05-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds the new source files sideband.[ch] to the repository and links the corresponding object file into para_server, para_audiod and para_client. The sideband API enables the command handlers of para_server to send a multiplexed output stream. The client side (para_client or para_audiod) demultiplex the received stream afterwards. The design is as simple as it can be: Each data buffer is preceded by a 5-byte header containing the length and the band designator, a one-byte number which specifies the type of the data which follows. The server-side and the client-side implement their own variant of the send_sb() and recv_sb() functions for sending and receiving sideband packets. Two implementations are necessary because the underlying file descriptor is blocking on the server side (command handlers of para_server) while it is non-blocking on the client side (para_client and para_audiod). The sideband API allows to optionally filter all data (including the sideband header) through an arbitrary transformation. This patch adds a suitable transformation as a new public function performs RC4 to the crypto API. To keep the patch within reasonable size, this commit does not contain any users of the new sideband API yet. Subsequent commits will teach the authentication handshake code and the command handlers to send and receive data as sideband packets.
* Replace PARA_VSNPRINTF by xvasprintf().Andre Noll2012-01-20
| | | | | | | | | | | | | | | | | | | | | | The PARA_VSNPRINTF macro is rather clumsy, and too large to be inlined. Moreover, it does not return the length of the formated string, so users have to call strlen() after the call to PARA_VSNPRINTF(). This is extra work which can easily be avoided since the number of bytes written is returned by the underlying call to vsnprintf(). This patch replaces the macro by the public function xvasprintf(), which is similar to the non-standard vasprintf() on GNU systems. It also adds xasprintf(), a similar variant which takes a variable number of arguments. Unlike PARA_VSNPRINTF, xasprintf() and xvasprintf() return the number of bytes written. This relies on vsnprintf() conforming to the C99 standard and breaks in particular on glibc 2.0 systems. Since glibc 2.0 is about 15 years old, this is unlikely to cause problems on real systems. All users which called strlen() right after xvasprintf() are changed to use the return value of xvasprintf() instead.
* sc_send_buffer(): Return an error on short writes.Andre Noll2012-01-20
| | | | This allows all callers to just check for negative return values.
* Change year in copyright message to 2012.Andre Noll2012-01-07
|
* Always include stdbool.h.Andre Noll2011-12-18
| | | | | | | | | This adds the #include statement for stdbool.h to para.h. This allows to get rid of the individual includes in *.c. More importantly, since all *.c files include para.h, booleans will now be available everywhere so that we won't need to touch dozens of files anymore whenever a boolean is added to a public structure.
* crypt: Don't use plain integer as NULL pointer.Andre Noll2011-08-09
| | | | Found by sparse.
* crypt_common.c: Add missing doxygen documentation.Andre Noll2011-07-06
|
* crypt: Move documentation to crypt.h.Andre Noll2011-07-06
| | | | | | | | Since we will have two implementations soon, the documentation of the public API should go to the common header. Also fix the documentation of pub_encrypt(): The size of the input buffer is never enough. 512 always suffices.
* stream cipher: Allow in-place encryption.Andre Noll2011-07-06
| | | | | | unlike openssl's RC4(), the RC4 implemenation of libgcrypt can encrypt a buffer in-place. For this the "buf" argument of the various send and receive functions must not be const.
* crypt: Make base64_decode public.Andre Noll2011-07-06
| | | | | | gcrypt.c needs this to decode public rsa keys. Public functions should always return proper error codes, so change the return value for errors from -1 to -E_BASE64.
* crypt: Move implementation-independent code to separate file.Andre Noll2011-07-06
This introduces crypt_common.c which contains helper functions from crypt.c which are independent of openssl. crypt.common.c contains two types of public functions: Frontend functions are called by users of the crypto API, and these functions are exported as usual through the crypt.h header file. Backend functions, on the other hand, are expected to be called only from the crypto implementation (i.e. from crypt.c or gcrypt.c). These functions are exported through the new crypt_backend.h header file.