/* Encrypt or decrypt data chunk by XOR-ing it with spritz keystream.
 * spritz_crypt() usable after spritz_setup() or spritz_setup_withIV().
 */
void
spritz_crypt(spritz_ctx *ctx,
             const uint8_t *data, uint16_t dataLen,
             uint8_t *dataOut)
{
  uint16_t i;

  for (i = 0; i < dataLen; i++) {
    dataOut[i] = data[i] ^ drip(ctx);
  }
}
Exemple #2
0
static void
squeeze(State *state, unsigned char *out, size_t outlen)
{
    size_t v;

    if (state->a > 0) {
        shuffle(state);
    }
    for (v = 0; v < outlen; v++) {
        out[v] = drip(state);
    }
}
/* Output hash digest */
void
spritz_hash_final(spritz_ctx *hash_ctx,
                  uint8_t *digest, uint8_t digestLen)
{
  uint8_t i;

  absorbStop(hash_ctx);
  absorb(hash_ctx, digestLen);
  /* squeeze() */
  if (hash_ctx->a) {
    shuffle(hash_ctx);
  }
  for (i = 0; i < digestLen; i++) {
    digest[i] = drip(hash_ctx);
  }
}
Exemple #4
0
int
spritz_decrypt(unsigned char *out, const unsigned char *c, size_t clen,
               const unsigned char *nonce, size_t noncelen,
               const unsigned char *key, size_t keylen)
{
    State  state;
    size_t v;

    key_setup(&state, key, keylen);
    absorb_stop(&state);
    absorb(&state, nonce, noncelen);
    for (v = 0; v < clen; v++) {
        out[v] = c[v] - drip(&state);
    }
    memzero(&state, sizeof state);

    return 0;
}
/* Generates a random byte of keystream from spritz state (spritz_ctx).
 * spritz_random_byte() usable after spritz_setup() or spritz_setup_withIV().
 */
uint8_t
spritz_random_byte(spritz_ctx *ctx)
{
  return drip(ctx);
}
Exemple #6
0
int DripLine::EPSWriteLine(std::ostream& outFile) const noexcept
{
  // Format: N Z S(x)
  std::ifstream drip(drip_file, std::ios::binary);

  if (!drip)
    {
      std::cerr << "***ERROR***: " << drip_file << " couldn't be opened to read the drip line data" << std::endl;
      return 1;
    }

  std::cout << "Reading " << drip_file << " and drawing the drip line";

  switch (the_line)
    {
      case LineType::singleneutron:
        outFile << "\n%Neutron Drip Line\n";
        break;
      case LineType::doubleneutron:
        outFile << "\n%Two Neutron Drip Line\n";
        break;
      case LineType::singleproton:
        outFile << "\n%Proton Drip Line\n";
        break;
      case LineType::doubleproton:
        outFile << "\n%Two Proton Drip Line\n";
        break;
    }
  outFile << "gs\n"
          << line_colour << " rgb\n"
          << "1 u div sl" << std::endl;

  bool initial = true;
  std::string line;

  while (std::getline(drip, line))
    {
      if (line.empty() || line.at(0) == '#')
        {
          continue;
        }

      int zDrip = 0;
      int nDrip = 0;

      double dummy = 0.0;

      std::istringstream dripData(line);
      dripData >> nDrip >> zDrip >> dummy;

      if (zDrip >= Zmin && zDrip <= Zmax && nDrip >= Nmin && nDrip <= Nmax)
        {
          outFile << std::setw(3) << nDrip - Nmin << " " << std::setw(3) << zDrip - Zmin << " " << (initial ? 'm' : 'l')
                  << '\n';

          if (initial)
            {
              initial = false;
            }
        }
    }
  drip.close();

  outFile << "st\n"
          << "gr" << std::endl;

  std::cout << std::endl;
  return 0;
}