all repos — TinyCrypT @ main

Short and sweet classical cryptographic primitives

meson.build (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
project('TinyCrypT', 'c', version: '0.1.0')

incdir = include_directories('.')

sources = [
  'tinycrypt/portable/kangarootwelve128.c',
  'tinycrypt/portable/sha2.c',
  'tinycrypt/portable/chacha20.c',
]

if meson.get_compiler('c').has_define('__SIZEOF_INT128__')
  sources += 'tinycrypt/min64/ed25519.c'
else
  sources += 'tinycrypt/min32/ed25519.c'
endif

if meson.get_compiler('c').has_define('__SIZEOF_INT128__')
  sources += 'tinycrypt/min64/chacha20_poly1305.c'
else
  sources += 'tinycrypt/min32/chacha20_poly1305.c'
endif

if meson.get_compiler('c').has_define('__SIZEOF_INT128__')
  sources += 'tinycrypt/min64/x25519.c'
else
  sources += 'tinycrypt/min32/x25519.c'
endif

build_args = [
  '-O3',
  '-ffreestanding',
]

if target_machine.cpu_family() == 'x86_64'
  build_args += '-march=native'
  build_args += '-DTCT_SIMD128'
  build_args += '-DTCT_SIMD256'
endif

if target_machine.cpu_family() == 'aarch64'
  build_args += '-DTCT_SIMD128'
  build_args += '-DTCT_SIMD256'
endif

if target_machine.endian() == 'little'
  build_args += '-DTCT_LITTLE_ENDIAN'
endif

target = static_library('tinycrypt', sources, c_args: build_args, include_directories: incdir)

project_dep = declare_dependency(include_directories: incdir, link_with: target)
set_variable(meson.project_name() + '_dep', project_dep)

sha2_test_sources = [
  'tests/src/sha2/SHA512LongMsg.cpp',
  'tests/src/sha2/SHA512ShortMsg.cpp',
  'tests/src/sha2/SHA512Monte.cpp',
  'tests/src/sha2/SHA256LongMsg.cpp',
  'tests/src/sha2/SHA256ShortMsg.cpp',
  'tests/src/sha2/SHA256Monte.cpp',
]

ed25519_test_sources = [
  'tests/src/ed25519/verify_happy.cpp',
  'tests/src/ed25519/verify_sad.cpp',
  'tests/src/ed25519/sign.cpp',
  'tests/src/ed25519/keygen.cpp',
]

cc20_p1305_test_sources = [
  'tests/src/chacha20-poly1305/all.cpp',
]

x25519_test_sources = [
  'tests/src/x25519/all.cpp',
]

if not meson.is_subproject() and not meson.is_cross_build()
  add_languages('cpp')
  subdir('tests')
  test(
    'sha2_tests',
    executable(
      'sha2_tests',
      sha2_test_sources,
      include_directories: incdir,
      link_with: target,
      dependencies: test_dep,
      install: false,
    ),
  )
  test(
    'ed25519_tests',
    executable(
      'ed25519_tests',
      ed25519_test_sources,
      include_directories: incdir,
      link_with: target,
      dependencies: test_dep,
      install: false,
    ),
  )
  test(
    'cc20_p1305_tests',
    executable(
      'cc20_p1305_tests',
      cc20_p1305_test_sources,
      include_directories: incdir,
      link_with: target,
      dependencies: test_dep,
      install: false,
    ),
  )
  # Not included by default because it takes ~110 seconds to execute (includes a million-repetition test case)
  test(
    'x25519_tests',
    executable(
      'x25519_tests',
      x25519_test_sources,
      include_directories: incdir,
      link_with: target,
      dependencies: test_dep,
      install: false,
    ),
  )
endif