private static bool Secp256K1EcdsaSigSign(EcmultGenContext ctx, Scalar sigr, Scalar sigs, Scalar seckey, Scalar message, Scalar nonce, out byte recid)
        {
            byte[] numArray = new byte[32];
            Ge     r1       = new Ge();
            Scalar scalar   = new Scalar();
            bool   overflow = false;
            GeJ    r2;

            EcMultGen.secp256k1_ecmult_gen(ctx, out r2, nonce);
            Group.SetGeJ(r1, r2);
            Field.Normalize(r1.X);
            Field.Normalize(r1.Y);
            Field.GetB32(numArray, r1.X);
            Scalar.SetB32(sigr, numArray, ref overflow);
            recid = (byte)((overflow ? 2 : 0) | (Field.IsOdd(r1.Y) ? 1 : 0));
            Scalar.Mul(scalar, sigr, seckey);
            Scalar.Add(scalar, scalar, message);
            Scalar.Inverse(sigs, nonce);
            Scalar.Mul(sigs, sigs, scalar);
            Scalar.Clear(scalar);
            Group.secp256k1_gej_clear(r2);
            Group.secp256k1_ge_clear(r1);
            if (Scalar.IsZero(sigs))
            {
                return(false);
            }
            if (Scalar.IsHigh(sigs))
            {
                Scalar.Negate(sigs, sigs);
                recid ^= (byte)1;
            }
            return(true);
        }
Example #2
0
        public LogItem[] GetItems(
            NpgsqlConnection connection, CriteriaType criteriaType, DateTime criteria, int maxCount, bool includeBytes)
        {
            IWhereOp whereOp;
            bool     asc;

            switch (criteriaType)
            {
            case CriteriaType.DownFromInfinity:
                whereOp = null;
                asc     = false;
                break;

            case CriteriaType.DownFrom:
                whereOp = new Lt(DbStr.Time, criteria.Ticks);
                asc     = false;
                break;

            case CriteriaType.DownFromOrEqual:
                whereOp = new Le(DbStr.Time, criteria.Ticks);
                asc     = false;
                break;

            case CriteriaType.UpFromInfinity:
                whereOp = null;
                asc     = true;
                break;

            case CriteriaType.UpFrom:
                whereOp = new Gt(DbStr.Time, criteria.Ticks);
                asc     = true;
                break;

            case CriteriaType.UpFromOrEqual:
                whereOp = new Ge(DbStr.Time, criteria.Ticks);
                asc     = true;
                break;

            default:
                throw new NotSupportedException("CriteriaType " + criteriaType);
            }
            var columns = includeBytes ? _columns : _columnsWithoutBytes;
            var query   = _npgQueryHelper.Select(
                _tableName, columns, whereOp, new[] { DbStr.Time }, asc, Math.Min(maxCount, MaxItemsToRetrieve));
            var alarms = _npgHelper.ExecuteReader(connection, query, reader =>
            {
                var i = new LogItem
                {
                    Time = reader.GetDateTimeFormTicks(0),
                    Text = reader.GetNullableString(1)
                };
                if (includeBytes)
                {
                    i.Bytes = reader.GetByteArray(2);
                }
                return(i);
            });

            return(asc ? alarms.Reverse().ToArray() : alarms);
        }
Example #3
0
 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     modelBuilder.Entity <Grupos>()
     .HasMany <Estudiantes>(g => g.Estudiante)
     .WithMany(e => e.Grupo)
     .Map(Ge =>
     {
         Ge.MapLeftKey("EstudianteId");
         Ge.MapRightKey("GrupodId");
         Ge.ToTable("GruposEstudiantes");
     });
 }
Example #4
0
        static IValidator Ge(object pValue, object pMin, string pFieldName, string pErrorMsg)
        {
            IValidator validator = new Ge()
            {
                Value     = pValue,
                Min       = pMin,
                ErrorMsg  = pErrorMsg,
                FieldName = pFieldName
            };

            return(validator);
        }
Example #5
0
        public GroupElement(GE groupElement)
        {
            if (groupElement.IsInfinity)
            {
                LazyGe = new Lazy <GE>(() => GE.Infinity);
            }
            else
            {
                Guard.True($"{nameof(groupElement)}.{nameof(groupElement.IsValidVariable)}", groupElement.IsValidVariable);
                LazyGe = new Lazy <GE>(() => new GE(groupElement.x.Normalize(), groupElement.y.Normalize()));
            }

            Gej = Ge.ToGroupElementJacobian();             // eagerly initialize Ge property
        }
Example #6
0
        public Tuple <DateTime, double?[]>[] GetSamples(int[] trendTagIds, DateTime startTime,
                                                        DateTime?endTime, int rarerer)
        {
            var columns = new List <string>(trendTagIds.Length + 1)
            {
                DbStr.Time
            };

            columns.AddRange(trendTagIds.Select(GetColumnName));
            var columnsArr = columns.ToArray();
            var parameters = new List <NpgsqlParameter>();
            var queryTexts = new List <string>();

            for (var i = 0; i < TrendTableSelector.TablesCount; i++)
            {
                if (rarerer != 0 && rarerer != i + 1)
                {
                    continue;
                }
                string   tableName = GetTableName(i);
                IWhereOp whereOp   = new Ge(DbStr.Time, startTime.Ticks);
                if (endTime.HasValue)
                {
                    whereOp = new And(whereOp, new Le(DbStr.Time, endTime.Value.Ticks));
                }
                string queryText = _npgQueryHelper.Select(
                    parameters,
                    tableName,
                    columnsArr,
                    whereOp,
                    limit: MaxSamplesToRetrieve);
                queryTexts.Add(queryText);
            }

            NpgQuery query = queryTexts.Count == 1
                ? new NpgQuery(queryTexts[0], parameters.ToArray())
                : _npgQueryHelper.Union(parameters, queryTexts, ColumnsOfTime, true, MaxSamplesToRetrieve);

            return(_npgHelper.ExecuteReader(_connection, query, reader => {
                DateTime time = reader.GetDateTimeFormTicks(0);
                var values = new double?[columns.Count - 1];
                for (var j = 1; j < columns.Count; j++)
                {
                    values[j - 1] = reader.GetNullableDouble(j);
                }
                return new Tuple <DateTime, double?[]>(time, values);
            }));
        }
Example #7
0
        public User[] Get(NpgsqlConnection connection, CriteriaType criteriaType, string name, int count)
        {
            IWhereOp whereOp;
            bool     asc;

            switch (criteriaType)
            {
            case CriteriaType.DownFromInfinity:
                whereOp = null;
                asc     = true;
                break;

            case CriteriaType.DownFrom:
                whereOp = new Gt(DbStr.Name, name);
                asc     = true;
                break;

            case CriteriaType.DownFromOrEqual:
                whereOp = new Ge(DbStr.Name, name);
                asc     = true;
                break;

            case CriteriaType.UpFromInfinity:
                whereOp = null;
                asc     = false;
                break;

            case CriteriaType.UpFrom:
                whereOp = new Lt(DbStr.Name, name);
                asc     = false;
                break;

            case CriteriaType.UpFromOrEqual:
                whereOp = new Le(DbStr.Name, name);
                asc     = false;
                break;

            default:
                throw new NotSupportedException("CriteriaType " + criteriaType);
            }

            int      limit = Math.Min(count, MaxUsersToRetrieve);
            NpgQuery query = _npgQueryHelper.Select(
                DbStr.Users, _userColumns, whereOp, new[] { DbStr.Name }, asc, limit);
            var users = _npgHelper.ExecuteReader(connection, query, GetUser);

            return(asc ? users : users.Reverse().ToArray());
        }
Example #8
0
        private static bool Secp256K1EcdsaSigSign(EcmultGenContext ctx, Scalar sigr, Scalar sigs, Scalar seckey, Scalar message, Scalar nonce, out byte recid)
        {
            var    b = new byte[32];
            GeJ    rp;
            Ge     r        = new Ge();
            Scalar n        = new Scalar();
            bool   overflow = false;

            EcMultGen.secp256k1_ecmult_gen(ctx, out rp, nonce);
            Group.SetGeJ(r, rp);
            Field.Normalize(r.X);
            Field.Normalize(r.Y);
            Field.GetB32(b, r.X);
            Scalar.SetB32(sigr, b, ref overflow);
            /* These two conditions should be checked before calling */
            Debug.Assert(!Scalar.IsZero(sigr));
            Debug.Assert(!overflow);


            // The overflow condition is cryptographically unreachable as hitting it requires finding the discrete log
            // of some P where P.x >= order, and only 1 in about 2^127 points meet this criteria.
            recid = (byte)((overflow ? 2 : 0) | (Field.IsOdd(r.Y) ? 1 : 0));

            Scalar.Mul(n, sigr, seckey);
            Scalar.Add(n, n, message);
            Scalar.Inverse(sigs, nonce);
            Scalar.Mul(sigs, sigs, n);
            Scalar.Clear(n);
            Group.secp256k1_gej_clear(rp);
            Group.secp256k1_ge_clear(r);
            if (Scalar.IsZero(sigs))
            {
                return(false);
            }

            if (Scalar.IsHigh(sigs))
            {
                Scalar.Negate(sigs, sigs);
                recid ^= 1;
            }

            return(true);
        }
Example #9
0
        // Since GEJ.IsValidVariable, this constructor is private
        private GroupElement(GEJ groupElementJacobian)
        {
            if (groupElementJacobian.IsInfinity)
            {
                LazyGe = new Lazy <GE>(() => GE.Infinity);
                Gej    = Ge.ToGroupElementJacobian();              // eagerly initialize Ge property
            }
            else
            {
                GE ComputeAffineCoordinates()
                {
                    var groupElement = groupElementJacobian.ToGroupElement();

                    return(new GE(groupElement.x.Normalize(), groupElement.y.Normalize()));
                }

                LazyGe = new Lazy <GE>(ComputeAffineCoordinates);                // avoid computing affine coordinates until needed
                Gej    = groupElementJacobian;
            }
        }
Example #10
0
 public static bool PubkeySerialize(Ge elem, byte[] pub, ref int size, bool compressed)
 {
     if (Group.secp256k1_ge_is_infinity(elem))
     {
         return(false);
     }
     Field.NormalizeVar(elem.X);
     Field.NormalizeVar(elem.Y);
     Field.GetB32(pub, 1, elem.X);
     if (compressed)
     {
         size   = 33;
         pub[0] = (byte)(2 | (Field.IsOdd(elem.Y) ? 1 : 0));
     }
     else
     {
         size   = 65;
         pub[0] = (byte)4;
         Field.GetB32(pub, 33, elem.Y);
     }
     return(true);
 }
Example #11
0
        public Tuple <DateTime, double?[]>[] GetPage(int[] trendTagIds, CriteriaType criteriaType,
                                                     DateTime criteria, int maxCount)
        {
            IWhereOp whereOp;
            bool     asc;

            switch (criteriaType)
            {
            case CriteriaType.DownFromInfinity:
                whereOp = null;
                asc     = false;
                break;

            case CriteriaType.DownFrom:
                whereOp = new Lt(DbStr.Time, criteria.Ticks);
                asc     = false;
                break;

            case CriteriaType.DownFromOrEqual:
                whereOp = new Le(DbStr.Time, criteria.Ticks);
                asc     = false;
                break;

            case CriteriaType.UpFromInfinity:
                whereOp = null;
                asc     = true;
                break;

            case CriteriaType.UpFrom:
                whereOp = new Gt(DbStr.Time, criteria.Ticks);
                asc     = true;
                break;

            case CriteriaType.UpFromOrEqual:
                whereOp = new Ge(DbStr.Time, criteria.Ticks);
                asc     = true;
                break;

            default:
                throw new NotSupportedException("CriteriaType " + criteriaType);
            }

            var columns = new List <string>(trendTagIds.Length + 1)
            {
                DbStr.Time
            };

            columns.AddRange(trendTagIds.Select(GetColumnName));
            var columnsArr = columns.ToArray();
            int limit      = Math.Min(maxCount, MaxSamplesToRetrieve);
            var parameters = new List <NpgsqlParameter>();
            var queryTexts = new List <string>();

            for (var i = 0; i < TrendTableSelector.TablesCount; i++)
            {
                string queryText = _npgQueryHelper.Select(
                    parameters,
                    _tableName + "_" + i,
                    columnsArr,
                    whereOp,
                    ColumnsOfTime,
                    asc,
                    limit);
                queryTexts.Add(queryText);
            }

            NpgQuery query  = _npgQueryHelper.Union(parameters, queryTexts, ColumnsOfTime, asc, limit);
            var      result = _npgHelper.ExecuteReader(_connection, query, reader => {
                DateTime time = reader.GetDateTimeFormTicks(0);
                var values    = new double?[columns.Count - 1];
                for (var j = 1; j < columns.Count; j++)
                {
                    values[j - 1] = reader.GetNullableDouble(j);
                }
                return(new Tuple <DateTime, double?[]>(time, values));
            });

            return(asc ? result.Reverse().ToArray() : result);
        }
        public string BuildEdi(List <Patient> patientList, InsuranceCompany insurance,
                               BillingProvider billingProvider)
        {
            var buildEdi = new StringBuilder();
            //Begin ISA
            var buildisa = new Isa();

            buildEdi.Append(buildisa.BuildIsa());

            //Begin GS
            var buildGs = new Gs();

            buildEdi.Append(buildGs.BuildGs());

            //Begin ST
            var buildSt = new St();

            buildEdi.Append(buildSt.BuildSt());

            //Begin BPR
            var buildBpr = new Bpr();

            buildEdi.Append(buildBpr.BuildBpr(insurance));

            //Build TRN
            var buildTrn = new Trn();

            buildEdi.Append(buildTrn.BuildTrn(insurance));

            //Ref Segment conditional, not included at this time
            //REF Receiver Identification
            //REF01 Receiver Reference Number
            //REF02 Receiver Reference Identification

            //Build DTM Loop Production Date
            var buildDtm = new Dtm();

            buildEdi.Append(buildDtm.BuildDtm(patientList));

            //Build N1 Insurance Company Identification Segment 1000A
            var buildNOne = new N1();

            buildEdi.Append(buildNOne.BuildNOne(insurance));

            //BuildN3 Insurance Company Identification Segment 1000A
            var buildNThree = new N3();

            buildEdi.Append(buildNThree.BuildNThree(insurance));

            // Build N4 Insurance Company Identification 1000A
            var buildNFour = new N4();

            buildEdi.Append(buildNFour.BuildN4(insurance));

            //Build Ref Insurance Company Identification 1000A
            var buildRef = new Ref();

            buildEdi.Append(buildRef.BuildRef());

            //Build Per Insurance Company Identification 1000A
            var buildPer = new Per();

            buildEdi.Append(buildPer.BuildPerPhone());

            //Build Per Insurance Company Website Information 1000A
            buildEdi.Append(buildPer.BuildPerWebSite());

            //Build N1 Provider Identifier Segment 1000B
            buildEdi.Append(buildNOne.BuildNOne(billingProvider));

            //Build N3 Provider Identifier Segment 1000B
            buildEdi.Append(buildNThree.BuildNThree(billingProvider));

            //Build N4 Provider Identifier Segment 1000B
            buildEdi.Append(buildNFour.BuildN4(billingProvider));

            //Build Ref Provider Identifier 1000B
            buildEdi.Append(buildRef.BuildRefAdditionalPayee());
            buildEdi.Append(buildRef.BuildRefAdditionalPayeeTwo());

            //LX Segment 2000B
            var buildLx = new Lx();

            buildEdi.Append(buildLx.BuildLx());

            //TS3 2000B NOT USED
            //TS2 2000B NOT USED
            //CLP Segment 2100

            foreach (Patient patient in patientList)
            {
                var buildClp = new Clp();
                buildEdi.Append(buildClp.BuildClp(patient));

                var buildNmOne = new Nm1();
                buildEdi.Append(buildNmOne.BuildNm1(patient));


                //MIA Inpatient Adjudication Information
                //MOA Outpatient Adjudication Information
                //REF Other CLaim Related Identification


                //Ref Rendering Provider Identifier 2100
                buildEdi.Append(buildRef.BuildRef(patient.Provider));

                //DTM Statement From or To Date 2100
                buildEdi.Append(buildDtm.BuildDtm(patient));

                //PER Claim Contact Information 2100

                //SVC Level 2110
                var buildSvc = new Svc();

                buildEdi.Append(buildSvc.BuildSvc(patient.Charge));
                buildEdi.Append(buildDtm.BuildDtm(patient.Charge));

                var buildCas = new Cas();
                if (patient.Charge.AdjustmentList != null)
                {
                    buildEdi.Append(buildCas.BuildCas(patient.Charge.AdjustmentList));
                    buildEdi.Append(buildCas.BuildCas(patient.Charge));
                }
                else
                {
                    buildEdi.Append(buildCas.BuildCas(patient.Charge));
                }
                buildEdi.Append(buildRef.BuildRefControlNumber());

                var buildAmt = new Amt();
                buildEdi.Append(buildAmt.BuildAmt(patient.Charge));
                //QTY 2110
                //LQ 2110
                //LQ01 Service Line Remittance Remark Code 1
                //LQ02 Service Line Remittance Remark Code 2

                foreach (AddonCharge addon in patient.Charge.AddonChargeList)
                {
                    buildEdi.Append(buildSvc.BuildSvc(addon));
                    buildEdi.Append(buildCas.BuildCas(addon.AdjustmentList));
                    buildEdi.Append(buildRef.BuildRefControlNumber());
                    buildEdi.Append(buildAmt.BuildAmt(addon));
                }
            }

            var buildSe = new Se();

            buildEdi.Append(buildSe.BuildSe());

            var buildGe = new Ge();

            buildEdi.Append(buildGe.BuildGe());

            var buildIea = new Iea();

            buildEdi.Append(buildIea.BuildIea());

            return(buildEdi.ToString());
        }