--- /dev/null
+/* blowfish-internal.h
+
+ Blowfish block cipher.
+
+ Copyright (C) 2014 Niels Möller
+ Copyright (C) 1998, 2001 FSF, Ray Dassen, Niels Möller
+
+ This file is part of GNU Nettle.
+
+ GNU Nettle is free software: you can redistribute it and/or
+ modify it under the terms of either:
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ or both in parallel, as here.
+
+ GNU Nettle is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see http://www.gnu.org/licenses/.
+*/
+
+#ifndef NETTLE_BLOWFISH_INTERNAL_H_INCLUDED
+#define NETTLE_BLOWFISH_INTERNAL_H_INCLUDED
+
+#include "nettle-types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern const struct blowfish_ctx _nettle_blowfish_initial_ctx;
+extern void _nettle_blowfish_encround (const struct blowfish_ctx *ctx,
+ uint32_t * ret_xl, uint32_t * ret_xr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NETTLE_BLOWFISH_INTERNAL_H_INCLUDED */
#include <assert.h>
#include "blowfish.h"
+#include "blowfish-internal.h"
#include "macros.h"
/* precomputed S boxes */
-static const struct blowfish_ctx
-initial_ctx = {
+const struct blowfish_ctx
+_nettle_blowfish_initial_ctx = {
{
{ /* ks0 */
0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96,
#define R(c, l,r,i) do { l ^= c->p[i]; r ^= F(c,l); } while(0)
-static void
-encrypt (const struct blowfish_ctx *ctx, uint32_t * ret_xl,
+void
+_nettle_blowfish_encround (const struct blowfish_ctx *ctx, uint32_t * ret_xl,
uint32_t * ret_xr)
{
uint32_t xl, xr;
}
static void
-decrypt (const struct blowfish_ctx *ctx, uint32_t * ret_xl, uint32_t * ret_xr)
+decround (const struct blowfish_ctx *ctx, uint32_t * ret_xl, uint32_t * ret_xr)
{
uint32_t xl, xr;
d1 = READ_UINT32(src);
d2 = READ_UINT32(src+4);
- encrypt (ctx, &d1, &d2);
+ _nettle_blowfish_encround (ctx, &d1, &d2);
dst[0] = (d1 >> 24) & 0xff;
dst[1] = (d1 >> 16) & 0xff;
dst[2] = (d1 >> 8) & 0xff;
d1 = READ_UINT32(src);
d2 = READ_UINT32(src+4);
- decrypt (ctx, &d1, &d2);
+ decround (ctx, &d1, &d2);
dst[0] = (d1 >> 24) & 0xff;
dst[1] = (d1 >> 16) & 0xff;
dst[2] = (d1 >> 8) & 0xff;
int i, j;
uint32_t data, datal, datar;
- *ctx = initial_ctx;
+ *ctx = _nettle_blowfish_initial_ctx;
for (i = j = 0; i < _BLOWFISH_ROUNDS + 2; i++)
{
datal = datar = 0;
for (i = 0; i < _BLOWFISH_ROUNDS + 2; i += 2)
{
- encrypt (ctx, &datal, &datar);
+ _nettle_blowfish_encround (ctx, &datal, &datar);
ctx->p[i] = datal;
ctx->p[i + 1] = datar;
}
-
+
for (j = 0; j < 4; j++)
for (i = 0; i < 256; i += 2)
{
- encrypt (ctx, &datal, &datar);
+ _nettle_blowfish_encround (ctx, &datal, &datar);
ctx->s[j][i] = datal;
ctx->s[j][i + 1] = datar;
}