Skip to content
Snippets Groups Projects
Select Git revision
  • 84560929c2516e387d43ddc56e771d6ba3e2050b
  • master default protected
  • 9.0
  • 8.0
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • nt-tools
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
  • v8.0.1982
  • v8.0.1980
  • v8.0.1978
  • v8.0.1976
  • v8.0.1974
  • v8.0.1972
  • v8.0.1970
  • v8.0.1968
  • v8.0.1966
41 results

push_array_items

Blame
    • Fredrik Hübinette (Hubbe)'s avatar
      84560929
      more documentation added · 84560929
      Fredrik Hübinette (Hubbe) authored
      Rev: doc/internal/array/aggregate_array:1.1
      Rev: doc/internal/array/array_index:1.2
      Rev: doc/internal/array/array_remove:1.1
      Rev: doc/internal/array/array_search:1.1
      Rev: doc/internal/array/array_set_index:1.1
      Rev: doc/internal/array/copy_array:1.1
      Rev: doc/internal/array/push_array_items:1.1
      Rev: doc/internal/array/resize_array:1.1
      Rev: doc/internal/array/slice_array:1.1
      Rev: doc/internal/pike/types:1.1
      Rev: doc/internal/program/add_function:1.1
      Rev: doc/internal/program/add_storage:1.1
      Rev: doc/internal/program/end_c_program:1.1
      Rev: doc/internal/program/set_exit_callback:1.1
      Rev: doc/internal/program/set_init_callback:1.1
      Rev: doc/internal/program/start_new_program:1.1
      84560929
      History
      more documentation added
      Fredrik Hübinette (Hubbe) authored
      Rev: doc/internal/array/aggregate_array:1.1
      Rev: doc/internal/array/array_index:1.2
      Rev: doc/internal/array/array_remove:1.1
      Rev: doc/internal/array/array_search:1.1
      Rev: doc/internal/array/array_set_index:1.1
      Rev: doc/internal/array/copy_array:1.1
      Rev: doc/internal/array/push_array_items:1.1
      Rev: doc/internal/array/resize_array:1.1
      Rev: doc/internal/array/slice_array:1.1
      Rev: doc/internal/pike/types:1.1
      Rev: doc/internal/program/add_function:1.1
      Rev: doc/internal/program/add_storage:1.1
      Rev: doc/internal/program/end_c_program:1.1
      Rev: doc/internal/program/set_exit_callback:1.1
      Rev: doc/internal/program/set_init_callback:1.1
      Rev: doc/internal/program/start_new_program:1.1
    rsa-encrypt.c 2.03 KiB
    /* rsa_encrypt.c
     *
     * The RSA publickey algorithm. PKCS#1 encryption.
     */
    
    /* nettle, low-level cryptographics library
     *
     * Copyright (C) 2001 Niels Mller
     *  
     * 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., 59 Temple Place - Suite 330, Boston,
     * MA 02111-1307, USA.
     */
    
    #include "rsa.h"
    
    #include "bignum.h"
    
    #include <assert.h>
    #include <stdlib.h>
    #include <string.h>
    
    int
    rsa_encrypt(struct rsa_public_key *key,
    	    /* For padding */
    	    void *random_ctx, nettle_random_func random,
    	    unsigned length, const uint8_t *message,
    	    mpz_t gibbberish)
    {
      uint8_t *em;
      unsigned padding;
      unsigned i;
      
      /* The message is encoded as a string of the same length as the
       * modulo n, of the form
       *
       *   00 02 pad 00 message
       *
       * where padding should be at least 8 pseudorandomly generated
       * *non-zero* octets. */
         
      if (length + 11 < key->size)
        /* Message too long for this key. */
        return 0;
    
      /* At least 8 bits of random padding */
      padding = key->size - length - 3;
      assert(padding >= 8);
      
      em = alloca(key->size - 1);
      em[0] = 2;
    
      random(random_ctx, padding, em + 1);
    
      /* Replace 0-octets with 1 */
      for (i = 0; i<padding; i++)
        if (!em[i+1])
          em[i+1] = 1;
      
      memcpy(em + 1 + padding, message, length);
    
      nettle_mpz_set_str_256(gibbberish, key->size - 1, em);
      mpz_powm(gibbberish, gibbberish, key->e, key->n);
    
      return 1;  
    }