Пример #1
0
bool ECP::ValidateParameters(RandomNumberGenerator &rng) const
{
	Integer p = FieldSize();
	return p.IsOdd() && VerifyPrime(rng, p)
		&& !m_a.IsNegative() && m_a<p && !m_b.IsNegative() && m_b<p
		&& ((4*m_a*m_a*m_a+27*m_b*m_b)%p).IsPositive();
}
Пример #2
0
bool ECP::VerifyPoint(const Point &P) const
{
	const FieldElement &x = P.x, &y = P.y;
	Integer p = FieldSize();
	return P.identity ||
		(!x.IsNegative() && x<p && !y.IsNegative() && y<p
		&& !(((x*x+m_a)*x+m_b-y*y)%p));
}
Пример #3
0
hashcode_t HashCode::hashcodeByRepeatedField(const Message* msg, const FieldDescriptor* field) {
  hashcode_t result = 0;
  auto reflect = msg->GetReflection();
  int size = reflect->FieldSize(*msg, field);

  switch (field->cpp_type()) {
  case FieldDescriptor::CPPTYPE_UINT64:
    HASH_ARRAY_FIELD(msg, field, UInt64)
    ;
    break;
  case FieldDescriptor::CPPTYPE_INT64:
    HASH_ARRAY_FIELD(msg, field, Int64)
    ;
    break;
  case FieldDescriptor::CPPTYPE_UINT32:
    HASH_ARRAY_FIELD(msg, field, UInt32)
    ;
    break;
  case FieldDescriptor::CPPTYPE_INT32:
    HASH_ARRAY_FIELD(msg, field, Int32)
    ;
    break;
  case FieldDescriptor::CPPTYPE_STRING:
    HASH_ARRAY_FIELD(msg, field, String)
    ;
    break;
  case FieldDescriptor::CPPTYPE_DOUBLE:
    HASH_ARRAY_FIELD(msg, field, Double)
    ;
    break;
  case FieldDescriptor::CPPTYPE_FLOAT:
    HASH_ARRAY_FIELD(msg, field, Float)
    ;
    break;
  case FieldDescriptor::CPPTYPE_BOOL:
    HASH_ARRAY_FIELD(msg, field, Bool)
    ;
    break;
  case FieldDescriptor::CPPTYPE_ENUM:
    HASH_ARRAY_FIELD(msg, field, Enum)
    ;
    break;
  case FieldDescriptor::CPPTYPE_MESSAGE:
    HASH_ARRAY_FIELD(msg, field, Message)
    ;
    break;
  default:
    LOG(ERROR)<< "The type of protobuf is not supported";
    break;
  }

  return result;
}
Пример #4
0
bool ECP::ValidateParameters(RandomNumberGenerator &rng, unsigned int level) const
{
	Integer p = FieldSize();

	bool pass = p.IsOdd();
	pass = pass && !m_a.IsNegative() && m_a<p && !m_b.IsNegative() && m_b<p;

	if (level >= 1)
		pass = pass && ((4*m_a*m_a*m_a+27*m_b*m_b)%p).IsPositive();

	if (level >= 2)
		pass = pass && VerifyPrime(rng, p);

	return pass;
}
Пример #5
0
bool ECP::DecodePoint(ECP::Point &P, BufferedTransformation &bt, unsigned int encodedPointLen) const
{
	byte type;
	if (encodedPointLen < 1 || !bt.Get(type))
		return false;

	switch (type)
	{
	case 0:
		P.identity = true;
		return true;
	case 2:
	case 3:
	{
		if (encodedPointLen != EncodedPointSize(true))
			return false;

		Integer p = FieldSize();

		P.identity = false;
		P.x.Decode(bt, GetField().MaxElementByteLength()); 
		P.y = ((P.x*P.x+m_a)*P.x+m_b) % p;

		if (Jacobi(P.y, p) !=1)
			return false;

		P.y = ModularSquareRoot(P.y, p);

		if ((type & 1) != P.y.GetBit(0))
			P.y = p-P.y;

		return true;
	}
	case 4:
	{
		if (encodedPointLen != EncodedPointSize(false))
			return false;

		unsigned int len = GetField().MaxElementByteLength();
		P.identity = false;
		P.x.Decode(bt, len);
		P.y.Decode(bt, len);
		return true;
	}
	default:
		return false;
	}
}
Пример #6
0
void Pb2Json::Message2Json(const ProtobufMsg& message, Json& json, bool enum2str) {
    auto descriptor = message.GetDescriptor();
    auto reflection = message.GetReflection();
    if (nullptr == descriptor || nullptr == descriptor) return;

    auto count = descriptor->field_count();

    for (auto i = 0; i < count; ++i) {
        const auto field = descriptor->field(i);

        if (field->is_repeated()) {
            if (reflection->FieldSize(message, field) > 0)
                RepeatedMessage2Json(message, field, reflection, json[field->name()], enum2str);

            continue;
        }

        if (!reflection->HasField(message, field)) {
            continue;
        }

        switch (field->type()) {
            case ProtobufFieldDescriptor::TYPE_MESSAGE: {
                const ProtobufMsg& tmp_message = reflection->GetMessage(message, field);
                if (0 != tmp_message.ByteSize()) Message2Json(tmp_message, json[field->name()]);
            } break;

            case ProtobufFieldDescriptor::TYPE_BOOL:
                json[field->name()] = reflection->GetBool(message, field) ? true : false;
                break;

            case ProtobufFieldDescriptor::TYPE_ENUM: {
                auto* enum_value_desc = reflection->GetEnum(message, field);
                if (enum2str) {
                    json[field->name()] = enum_value_desc->name();
                } else {
                    json[field->name()] = enum_value_desc->number();
                }
            } break;

            case ProtobufFieldDescriptor::TYPE_INT32:
            case ProtobufFieldDescriptor::TYPE_SINT32:
            case ProtobufFieldDescriptor::TYPE_SFIXED32:
                json[field->name()] = reflection->GetInt32(message, field);
                break;

            case ProtobufFieldDescriptor::TYPE_UINT32:
            case ProtobufFieldDescriptor::TYPE_FIXED32:
                json[field->name()] = reflection->GetUInt32(message, field);
                break;

            case ProtobufFieldDescriptor::TYPE_INT64:
            case ProtobufFieldDescriptor::TYPE_SINT64:
            case ProtobufFieldDescriptor::TYPE_SFIXED64:
                json[field->name()] = reflection->GetInt64(message, field);
                break;

            case ProtobufFieldDescriptor::TYPE_UINT64:
            case ProtobufFieldDescriptor::TYPE_FIXED64:
                json[field->name()] = reflection->GetUInt64(message, field);
                break;

            case ProtobufFieldDescriptor::TYPE_FLOAT:
                json[field->name()] = reflection->GetFloat(message, field);
                break;

            case ProtobufFieldDescriptor::TYPE_STRING:
            case ProtobufFieldDescriptor::TYPE_BYTES:
                json[field->name()] = reflection->GetString(message, field);
                break;

            default:
                break;
        }
    }
}
Пример #7
0
/* Initialise dirfile */
void InitialiseDirFile(int reset, unsigned long offset)
{
  dtrace("%i, %lu", reset, offset);
  FILE* fp;
  int fd;
  int j, i, is_bolo = 0;
#if DAS_CARDS > 0
  char field[FIELD_LEN];
  int bolo_node;
  char first_bolo_buf[16];
#endif
  char gpb[GPB_LEN];
  char ext[4] = "";

  fc = 0;

#ifdef HAVE_LIBZ
  if (rc.gzip_output) {
    defileclose = &gzclose;
    strcpy(ext, ".gz");
  } else
#endif
    defileclose = &close;

  rc.resume_at = -1;

  if (mkdir(rc.dirfile, 00755) < 0)
    if (!CheckWriteAllow(errno))
      berror(fatal, "cannot create dirfile `%s'", rc.dirfile);

  bprintf(info, "\nWriting to dirfile `%s'\n", rc.dirfile);

  rc.dirname = strdup(rc.dirfile);
  snprintf(rc.dirname, strlen(rc.dirfile), "%s", basename(rc.dirfile));

  for (i = 0; i < FAST_PER_SLOW + 10; ++i) {
    pre_buffer[i] = balloc(fatal, DiskFrameSize);
    pre_buffer[i][3] = i;
  }

  /* Reset the PreBuffer */
  PreBuffer(NULL);

  for (i = 0; i < FAST_PER_SLOW; ++i)
    fast_frame[i] = balloc(fatal, DiskFrameSize);

  /***********************************
   * create and fill the format file *
   ***********************************/
  sprintf(gpb, "%s/format", rc.dirfile);

  if ((fd = creat(gpb, 0666)) < 0)
    berror(fatal, "cannot create format file `%s/format'", rc.dirfile);

  PathSplit_r(rc.dirfile, NULL, gpb);

  WriteFormatFile(fd, atoi(gpb), offset / FAST_PER_SLOW);

#ifdef __SPIDER__
  if (rc.extra_format) {
    sprintf(gpb, "/INCLUDE /data/etc/spider/format.mce_mplex\n"
        "/INCLUDE /data/etc/spider/format.bolo_stats\n");
    if (write(fd, gpb, strlen(gpb)) < 0)
      berror(err, "Error writing to format file\n");
  }
#else
  /* no extra format for BLAST */
#endif

  if (close(fd) < 0)
    berror(fatal, "Error while closing format file");

  /* DEFILE_FLAGS */
  sprintf(gpb, "%s/DEFILE_FLAGS%s", rc.dirfile, ext);
  defile_field.size = 1;
  defile_field.fp = OpenField(1, 1, gpb);
  defile_field.i0 = 1;
  if (reset) {
    if (rc.resume_at > 0)
      defile_field.nw = rc.resume_at;
    else
      defile_field.nw = 0;
  }
  defile_field.i_in = defile_field.i_out = 0;
  defile_field.b = balloc(fatal, MAXBUF * sizeof(unsigned short));

  /* FASTSAMP */
  sprintf(gpb, "%s/FASTSAMP%s", rc.dirfile, ext);
  normal_fast[0].size = 2;

  normal_fast[0].fp = OpenField(1, 2, gpb);
  normal_fast[0].i0 = 1;
  if (reset) {
    if (rc.resume_at > 0)
      normal_fast[0].nw = rc.resume_at;
    else
      normal_fast[0].nw = 0;
  }

  normal_fast[0].i_in = normal_fast[0].i_out = 0;
  normal_fast[0].b = balloc(fatal, MAXBUF * sizeof(unsigned int));

  n_fast = 1;  //original form

  /* slow chs */
  for (i = 0; i < slowsPerBi0Frame; i++) {
    for (j = 0; j < FAST_PER_SLOW; j++) {
      if (strlen(SlowChList[i][j].field) > 0) {
        slow_fields[j][i].size = FieldSize(SlowChList[i][j].type,
            SlowChList[i][j].field);

        sprintf(gpb, "%s/%s%s", rc.dirfile, SlowChList[i][j].field, ext);
        slow_fields[j][i].fp = OpenField(0, slow_fields[j][i].size, gpb);
      } else
        slow_fields[j][i].fp = -1;

      slow_fields[j][i].i_in = slow_fields[j][i].i_out = 0;
      if (reset) {
        if (rc.resume_at > 0)
          slow_fields[j][i].nw = rc.resume_at / FAST_PER_SLOW;
        else
          slow_fields[j][i].nw = 0;
      }

      slow_fields[j][i].b = balloc(fatal, 2 * MAXBUF);

      slow_fields[j][i].i0 = SLOW_OFFSET + i;
    }
  }

  /* normal fast chs */

#if DAS_CARDS > 0
  sprintf(first_bolo_buf, "n%02dc00lo", DAS_START+1);
#endif
  for (i = 0; i < ccFast + ccWideFast; i++) {
#if DAS_CARDS > 0
    if (strcmp(FastChList[i].field, first_bolo_buf) == 0) {
      bolo_i0 = i + SLOW_OFFSET + slowsPerBi0Frame;
      is_bolo = 1;
    } else if (ccDecom > 0 && strcmp(FastChList[i].field,
          DecomChannels[0].field) == 0) {
      is_bolo = 0;
    }
#endif

    if (!is_bolo && strlen(FastChList[i].field) > 0) {
      normal_fast[n_fast].size = FieldSize(FastChList[i].type,
          FastChList[i].field);
      sprintf(gpb, "%s/%s%s", rc.dirfile, FastChList[i].field, ext);

      normal_fast[n_fast].fp = OpenField(1, normal_fast[n_fast].size, gpb);
      normal_fast[n_fast].i0 = i + SLOW_OFFSET + slowsPerBi0Frame;
      normal_fast[n_fast].i_in = normal_fast[n_fast].i_out = 0;
      if (reset) {
        if (rc.resume_at > 0)
          normal_fast[n_fast].nw = rc.resume_at;
        else
          normal_fast[n_fast].nw = 0;
      }

      normal_fast[n_fast].b = balloc(fatal, MAXBUF * 2 *
          normal_fast[n_fast].size);

      n_fast++;
    }
  }

#if DAS_CARDS > 0
  /* special (bolo) fast chs */
  bolo_node = DAS_START;
  for (i = 0; i < DAS_CARDS; i++) {
    bolo_node++;
    if (bolo_node%4 == 0) bolo_node++;
    for (j = 0; j < DAS_CHS; j++) {
      bolo_fields[i][j].size = 2;
      sprintf(field, "n%02dc%02d", bolo_node, j);
      sprintf(gpb, "%s/%s%s", rc.dirfile, field, ext);

      bolo_fields[i][j].fp = OpenField(1, 2, gpb);
      bolo_fields[i][j].i_in = bolo_fields[i][j].i_out = 0;

      if (reset) {
        if (rc.resume_at > 0)
          bolo_fields[i][j].nw = rc.resume_at;
        else
          bolo_fields[i][j].nw = 0;
      }

      bolo_fields[i][j].b = balloc(fatal, MAXBUF * 4);

      bolo_fields[i][j].i0 = bolo_i0 + i * (DAS_CARDS * 3 / 2) + j;
    }
  }
#endif

  if (rc.write_curfile) {
    // create the link file
    char lnkfile[1024];
    char curfile[1024];

    strncpy(curfile, rc.output_curfile, 1018);
    strcat(curfile, ".cur");

    strncpy(lnkfile, rc.output_curfile, 1018);
    strcat(lnkfile, ".lnk");
    unlink(lnkfile);
    if (symlink(rc.dirfile, lnkfile)<0) {
      berror(fatal, "could not create link from `%s' to `%s'",
             rc.dirfile, lnkfile);
    }
    // create the cur file
    if ((fp = fopen(curfile, "w")) == NULL)
      berror(fatal, "cannot create curfile `%s'", curfile);

    fprintf(fp, "%s\n", rc.dirfile);

    if (fclose(fp) < 0)
      berror(fatal, "cannot close curfile `%s'", curfile);
  }

  ri.dirfile_init = 1;
}
Пример #8
0
static inline long int GetNumFrames(size_t size, char type, const char* field)
{
  return (long int)size / 2 / FieldSize(type, field);
}