Skip to content
Snippets Groups Projects
Select Git revision
  • f8c206ed23e98a62c2b4d17237d6c0a2f6050843
  • master default
  • wip-slh-dsa-sha2-128s
  • master-updates
  • release-3.10-fixes
  • getopt-prototype
  • fix-bcrypt-warning
  • refactor-hmac
  • wip-use-alignas
  • trim-sha3-context
  • fix-gitlab-ci
  • check-fat-emulate
  • delete-digest_func-size
  • slh-dsa-shake-128f-nettle
  • slh-dsa-shake-128s-nettle
  • slh-dsa-shake-128s
  • delete-openpgp
  • ppc64-sha512
  • delete-md5-compat
  • cleanup-hmac-tests
  • ppc64-sha256
  • nettle_3.10.2_release_20250626
  • nettle_3.10.1_release_20241230
  • nettle_3.10_release_20240616
  • nettle_3.10rc2
  • nettle_3.10rc1
  • nettle_3.9.1_release_20230601
  • nettle_3.9_release_20230514
  • nettle_3.8.1_release_20220727
  • nettle_3.8_release_20220602
  • nettle_3.7.3_release_20210606
  • nettle_3.7.2_release_20210321
  • nettle_3.7.1_release_20210217
  • nettle_3.7_release_20210104
  • nettle_3.7rc1
  • nettle_3.6_release_20200429
  • nettle_3.6rc3
  • nettle_3.6rc2
  • nettle_3.6rc1
  • nettle_3.5.1_release_20190627
  • nettle_3.5_release_20190626
41 results

rsa-encrypt.c

Blame
  • testutils.h 3.31 KiB
    #ifndef NETTLE_TESTUTILS_H_INCLUDED
    #define NETTLE_TESTUTILS_H_INCLUDED
    
    #if HAVE_CONFIG_H
    # include "config.h"
    #endif
    
    #include "nettle-types.h"
    
    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    #if HAVE_LIBGMP
    # include "bignum.h"
    #endif
    
    #if WITH_HOGWEED
    # include "rsa.h"
    # include "dsa.h"
    #endif
    
    #include "nettle-meta.h"
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    void *
    xalloc(size_t size);
    
    /* Decodes a NUL-terminated hex string. */
    
    unsigned
    decode_hex_length(const char *hex);
    
    int
    decode_hex(uint8_t *dst, const char *hex);
    
    /* Allocates space */
    const uint8_t *
    decode_hex_dup(const char *hex);
    
    void
    print_hex(unsigned length, const uint8_t *data);
    
    /* The main program */
    int
    test_main(void);
    
    extern int verbose;
    
    void
    test_cipher(const struct nettle_cipher *cipher,
    	    unsigned key_length,
    	    const uint8_t *key,
    	    unsigned length,
    	    const uint8_t *cleartext,
    	    const uint8_t *ciphertext);
    
    void
    test_cipher_cbc(const struct nettle_cipher *cipher,
    		unsigned key_length,
    		const uint8_t *key,
    		unsigned length,
    		const uint8_t *cleartext,
    		const uint8_t *ciphertext,
    		const uint8_t *iv);
    
    void
    test_cipher_ctr(const struct nettle_cipher *cipher,
    		unsigned key_length,
    		const uint8_t *key,
    		unsigned length,
    		const uint8_t *cleartext,
    		const uint8_t *ciphertext,
    		const uint8_t *iv);
    
    void
    test_cipher_stream(const struct nettle_cipher *cipher,
    		   unsigned key_length,
    		   const uint8_t *key,
    		   unsigned length,
    		   const uint8_t *cleartext,
    		   const uint8_t *ciphertext);
    
    void
    test_hash(const struct nettle_hash *hash,
    	  unsigned length,
    	  const uint8_t *data,
    	  const uint8_t *digest);
    
    void
    test_hash_large(const struct nettle_hash *hash,
    		unsigned count, unsigned length,
    		uint8_t c,
    		const uint8_t *digest);
    
    void
    test_armor(const struct nettle_armor *armor,
               unsigned data_length,
               const uint8_t *data,
               const uint8_t *ascii);
    
    #if WITH_HOGWEED
    void
    test_rsa_set_key_1(struct rsa_public_key *pub,
    		   struct rsa_private_key *key);
    
    void
    test_rsa_md5(struct rsa_public_key *pub,
    	     struct rsa_private_key *key,
    	     mpz_t expected);
    
    void
    test_rsa_sha1(struct rsa_public_key *pub,
    	      struct rsa_private_key *key,
    	      mpz_t expected);
    
    void
    test_rsa_sha256(struct rsa_public_key *pub,
    		struct rsa_private_key *key,
    		mpz_t expected);
    
    void
    test_rsa_sha512(struct rsa_public_key *pub,
    		struct rsa_private_key *key,
    		mpz_t expected);
    
    void
    test_rsa_key(struct rsa_public_key *pub,
    	     struct rsa_private_key *key);
    
    void
    test_dsa(const struct dsa_public_key *pub,
    	 const struct dsa_private_key *key);
    
    void
    test_dsa_key(struct dsa_public_key *pub,
    	     struct dsa_private_key *key);
    
    #endif /* WITH_HOGWEED */
    
    #ifdef __cplusplus
    }
    #endif
    
    #define H2(d, s) decode_hex((d), (s))
    #define H(x) decode_hex_dup(x)
    #define HL(x) decode_hex_length(x), decode_hex_dup(x)
    
    /* LDATA needs to handle NUL characters. */
    #define LLENGTH(x) (sizeof(x) - 1)
    #define LDATA(x) (sizeof(x) - 1), x
    #define LDUP(x) strlen(x), strdup(x)
    
    #define MEMEQ(length, a, b) (!memcmp((a), (b), (length)))
    #define MEMEQH(length, a, b) \
    ((length) == decode_hex_length((b)) \
     && !memcmp((a), decode_hex_dup((b)), (length)))
    
    #define FAIL() abort()
    #define SKIP() exit(77)
    #define SUCCESS() return EXIT_SUCCESS
    
    #define ASSERT(x) do { if (!(x)) FAIL(); } while(0)
    
    #endif /* NETTLE_TESTUTILS_H_INCLUDED */