/* * sha512_base.h - core logic for SHA-512 implementations * * Copyright (C) 2015 Linaro Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include #include #include #include #include typedef void (sha512_block_fn)(struct sha512_state *sst, u8 const *src, int blocks); static inline int sha384_base_init(struct shash_desc *desc) { struct sha512_state *sctx = shash_desc_ctx(desc); sctx->state[0] = SHA384_H0; sctx->state[1] = SHA384_H1; sctx->state[2] = SHA384_H2; sctx->state[3] = SHA384_H3; sctx->state[4] = SHA384_H4; sctx->state[5] = SHA384_H5; sctx->state[6] = SHA384_H6; sctx->state[7] = SHA384_H7; sctx->count[0] = sctx->count[1] = 0; return 0; } static inline int sha512_base_init(struct shash_desc *desc) { struct sha512_state *sctx = shash_desc_ctx(desc); sctx->state[0] = SHA512_H0; sctx->state[1] = SHA512_H1; sctx->state[2] = SHA512_H2; sctx->state[3] = SHA512_H3; sctx->state[4] = SHA512_H4; sctx->state[5] = SHA512_H5; sctx->state[6] = SHA512_H6; sctx->state[7] = SHA512_H7; sctx->count[0] = sctx->count[1] = 0; return 0; } static inline int sha512_base_do_update(struct shash_desc *desc, const u8 *data, unsigned int len, sha512_block_fn *block_fn) { struct sha512_state *sctx = shash_desc_ctx(desc); unsigned int partial = sctx->count[0] % SHA512_BLOCK_SIZE; sctx->count[0] += len; if (sctx->count[0] < len) sctx->count[1]++; if (unlikely((partial + len) >= SHA512_BLOCK_SIZE)) { int blocks; if (partial) { int p = SHA512_BLOCK_SIZE - partial; memcpy(sctx->buf + partial, data, p); data += p; len -= p; block_fn(sctx, sctx->buf, 1); } blocks = len / SHA512_BLOCK_SIZE; len %= SHA512_BLOCK_SIZE; if (blocks) { block_fn(sctx, data, blocks); data += blocks * SHA512_BLOCK_SIZE; } partial = 0; } if (len) memcpy(sctx->buf + partial, data, len); return 0; } static inline int sha512_base_do_finalize(struct shash_desc *desc, sha512_block_fn *block_fn) { const int bit_offset = SHA512_BLOCK_SIZE - sizeof(__be64[2]); struct sha512_state *sctx = shash_desc_ctx(desc); __be64 *bits = (__be64 *)(sctx->buf + bit_offset); unsigned int partial = sctx->count[0] % SHA512_BLOCK_SIZE; sctx->buf[partial++] = 0x80; if (partial > bit_offset) { memset(sctx->buf + partial, 0x0, SHA512_BLOCK_SIZE - partial); partial = 0; block_fn(sctx, sctx->buf, 1); } memset(sctx->buf + partial, 0x0, bit_offset - partial); bits[0] = cpu_to_be64(sctx->count[1] << 3 | sctx->count[0] >> 61); bits[1] = cpu_to_be64(sctx->count[0] << 3); block_fn(sctx, sctx->buf, 1); return 0; } static inline int sha512_base_finish(struct shash_desc *desc, u8 *out) { unsigned int digest_size = crypto_shash_digestsize(desc->tfm); struct sha512_state *sctx = shash_desc_ctx(desc); __be64 *digest = (__be64 *)out; int i; for (i = 0; digest_size > 0; i++, digest_size -= sizeof(__be64)) put_unaligned_be64(sctx->state[i], digest++); *sctx = (struct sha512_state){}; return 0; } xt:space:mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-08-23 17:39:31 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-08-23 17:39:31 -0400
commiteafe5cfe718926c1ed8b3dacd2191c189b3cdcd2 (patch)
tree0297efe4a906d650fad0e162a1b450418de3979a /Documentation/acpi
parentc0678b2d6648ab65b68703044709e367799ba9f9 (diff)
parent3d4267a5a3a4b7619b80ad1839d8b3bedd8b7a8d (diff)
Merge tag 'iio-fixes-for-4.8a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into work-linus
Jonathan writes: First round of IIO fixes for the 4.8 cycle. This is somewhat of a bumper set due to my unavailabilty earlier in the month. The only slightly unusual ones are the dts updates for the rockchip adc reset. The fix in the driver only makes sense with these and the rockchip maintainer is happy with them going through IIO to reach mainline. Core stuff * Fix an issue with a blocking op when !TASK_RUNNING. This been there a while and snuck in with seemingly minor additions to some core code paths. * Tools - generic_buffer failed to initialize the channel array pointer thus in the case of no channels blows up trying to free a random memory address. * sw-trigger: - Fix config group initialization when configfs is built as a module. Drivers * ad5933 - Fix an incorrect overwrite of an error value. * ad799x - A missed assignment of the update_scan_mode callback means buffered mode doesn't work on the ad7991, ad7995 or ad7999. * ads1015 - wrong pointer returned from i2c_get_clientdata (missmatch of assumptions) * am2315 - Timestamps are reported, but never actually acquired from anywhere (so always 0) - missing buffer selects in Kconfig * am335x adc - Protect fifo1 from concurrent access. - Increase timeout waiting for ADC to be long enough in all cases. * as3935 - Timestamps are reported, but never actually acquired from anywhere (so always 0) * at91 - Fix reading of channel 3. * atlas-ph-sensor - Typo means that the scale of electrical conductivity readings is way off. * bma220 - Timestamps are reported, but never actually acquired from anywhere (so always 0) - Missing buffer selects in Kconfig * bmp280 - pass the write pointer to PTR_ERR (i.e. the one that was just checked with IS_ERR). - suspend /resume crash due to wrong assumption about what dev_get_drvdata would return. * hdc100x - It superficially appeared that smbus_read_byte commands would allow reading of the outputs in two goes. In reality it doesn't work, but instead returns the same for the upper and lower bytes (nice catch from Alison!) * kxsd9 - Fix raw read return value to ensure it actually reports the value rather than a blank string. * max44000 - Missing buffer selects in Kconfig * rockchip_saradc - Add use of reset controller to enforce a clean state of the ADC. Some bootloaders can leave it in an 'intersting' state and effectively frozen without this. A couple of associated dts updates. * stk8ba50 - Missing buffer selects in Kconfig * stx104 - Fix a possible race due to use of devm_iio_device_register when there was other stuff in the remove function.
Diffstat (limited to 'Documentation/acpi')