Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

blowfish.c

Blame
  • Forked from Nettle / nettle
    Source project has a limited visibility.
    blowfish.c 19.29 KiB
    /* blowfish.c
     *
     * The blowfish block cipher.
     *
     * For a description of the algorithm, see:
     *   Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996.
     *   ISBN 0-471-11709-9. Pages 336 ff.
     */
    
    /* nettle, low-level cryptographics library
     *
     * Copyright (C) 2014 Niels Möller
     * Copyright (C) 2010  Simon Josefsson
     * Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
     *  
     * The nettle library is free software; you can redistribute it and/or modify
     * it under the terms of the GNU Lesser General Public License as published by
     * the Free Software Foundation; either version 2.1 of the License, or (at your
     * option) any later version.
     * 
     * The nettle library 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 Lesser General Public
     * License for more details.
     * 
     * You should have received a copy of the GNU Lesser General Public License
     * along with the nettle library; see the file COPYING.LIB.  If not, write to
     * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
     * MA 02111-1301, USA.
     */
    
    /* This file is derived from cipher/blowfish.c in Libgcrypt v1.4.6.
       The adaption to Nettle was made by Simon Josefsson on 2010-11-23.
       Changes include removing the selftest, renaming u32/byte types to
       uint32_t/uint8_t, renaming BLOWFISH_ROUNDS to _BLOWFISH_ROUNDS
       (from Nettle's blowfish.h), dropping the libgcrypt wrapper
       functions, fixing #include's, remove support for non-16 rounds
       (there are no test vectors), adding FOR_BLOCK iterations, and
       running indent on the code. */
    
    #if HAVE_CONFIG_H
    #include "config.h"
    #endif
    
    #include <assert.h>
    
    #include "blowfish.h"
    
    #include "macros.h"
    
    /* precomputed S boxes */
    static const struct blowfish_ctx
    initial_ctx = {
      {
        { /* ks0 */
          0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96,
          0xBA7C9045, 0xF12C7F99, 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
          0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E, 0x0D95748F, 0x728EB658,
          0x718BCD58, 0x82154AEE, 0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013,
          0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF, 0x8E79DCB0, 0x603A180E,
          0x6C9E0E8B, 0xB01E8A3E, 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60,
          0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440, 0x55CA396A, 0x2AAB10B6,
          0xB4CC5C34, 0x1141E8CE, 0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
          0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E, 0xAFD6BA33, 0x6C24CF5C,
          0x7A325381, 0x28958677, 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193,
          0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032, 0xEF845D5D, 0xE98575B1,
          0xDC262302, 0xEB651B88, 0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239,
          0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E, 0x21C66842, 0xF6E96C9A,
          0x670C9C61, 0xABD388F0, 0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3,
          0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98, 0xA1F1651D, 0x39AF0176,