Implementing the IP Module Using Diamond
Instantiating
the Core
|
The
generated CSC Generator IP core package includes black-box
(<user_name>_bb.v) and instance (<username>_inst.v) templates
that can be used to instantiate the core in a top-level design. An
example RTL top-level reference source file that can be used as an
instantiation template for the IP core is provided in <project_dir>\csc_eval\<username>\src\rtl\top\<family>.
Users may also use this top-level reference as the starting template for the
top-level for their complete design. For
VHDL entry, only a top-level file is generated which contains the core
instantiation within. For
Linux/Unix environment: |
Hardware
Evaluation
|
Lattice's IP hardware evaluation
capability makes it possible to create IP cores that operate in hardware for
a limited period of time (approximately four hours) without requiring the
purchase on an IP license. The hardware evaluation capability is enabled by
default. It can be disabled by right clicking on "Build Database"
in the "Process for current sources" window of the Project
Navigator. The setting is called "Hardware Evaluation" and the
options are "Enable" or "Disable". If Diamond tool is
used, hardware evaluation capability can be enabled or disabled by clicking
on “Translate design” in Strategies window and set the option “Hardware
Evaluation”. |
Implementing
the Core in a Top-Level Design
|
Push-button
top-level implementation of this top-level is supported via
Diamond project file <username>_top.ldf located in <project_dir>\csc_eval\<username>\impl\<synthesis>.
This
design is intended only to provide an accurate indication of the device
utilization associated with the core itself and should not be used as an
actual implementation example. |
|
|
Running
Functional Simulation
The
functional simulation includes a configuration-specific behavioral model of the
CSC Generator, which is instantiated in an FPGA top level along with
some other logic (like PLLs and registers with Read/Write Interface). This FPGA
top is instantiated in an evaluation testbench that provides appropriate
stimulus for the CSC Generator IP core. The testbench files can be found
in <project_dir>\csc_eval\testbench.
The
generated IP core package includes the configuration-specific behavior model (<username>_beh.v,provided
in <project_dir>\csc_eval\<username>\src\beh_rtl\<family>)
for functional simulation.Models for simulation are provided in the
corresponding \models folder if required.
Users may run the eval simulation on ModelSim SE* by doing the
following:
Users
may run the eval simulation on Active-HDL(Windows only) by doing the
following:
Running
Timing Simulation
In
order to run the Post route timing simulation, an IP license is required. You
need to generate the timing simulation files by double-clicking on Generate
Timing Simulation Files in the process for current source window of the Project
Navigator.
Users may run the eval simulation on ModelSim SE(1) by
doing the following:
Users
may run the eval simulation on Active-HDL(Windows only) by doing the
following:
(1)
For
running VHDL RTL/Timing simulation on ModelSim SE, pre-compiled Library should
be prepared first.
Timing
Report file
·
Open Diamond Project navigator.
·
Under File tab, select Open -> Project.
·
Select file <project_dir>\csc_eval\<username>\impl\synplify(lse)\<username>_top.ldf
·
Double click on Place & Route Trace
menu in process window
·
View timing report in Reports window
Special
Information
When you want to regenerate the previous generated core whose core type as "Custom", make sure the coeffs.dat file is in the same location as the lpc file's.
Please ignore
these warnings. They will not impact the
functionality
WARNING - map:
Using local reset signal 'rst_n_c' to infer global GSR
net.
# Warning: VCP2738 ../../../../../../../../../../../../../../lscc/diamond/3.7_x64/cae_library/simulation/verilog/ecp5u/IBPD.v : (37, 1): Module input port I connected to gate output
# SLP: Warning:
Reference
Information
The following documents provide more information on implementing this core:
General Information
Copyright
Notice
|
Copyright
2000-2016© Lattice Semiconductor Corporation. ALL RIGHTS RESERVED. This
confidential and proprietary software may be used only as authorized by a licensing
agreement from Lattice Semiconductor Corporation. The entire notice above
must be reproduced on all authorized copies and copies may only be made to
the extent permitted by a licensing agreement from Lattice Semiconductor
Corporation. |
Contacting
Lattice
|
Mail: |
Lattice
Semiconductor Corporation |
|
Telephone: |
1-800-LATTICE
( |
|
|
1-503-268-8001
(other locations) |
|
Website: |
http://www.latticesemi.com |
|
E-mail: |
<EMAIL_ADDRESS>|
IP Module Information
About this
Module
|
IP
Name: |
CSC Generator |
|
IP
Version: |
ver
3.1 |
|
IP
Release Date: |
Sep 2016 |
|
Target
Technology: |
LatticeECP3/LatticeXP2/MachXO2/ ECP5U/ECP5UM/ECP5UM5G |
Software Requirements
|
Synthesis
Tools Supported: |
Synplify
Pro for Lattice K-2015.09L-2 or later |
|
Simulation
Tools Supported: |
Modelsim
SE 6.6f |
|
Lattice
Tool Supported: |
Diamond 3.7 or later |


This is my Fender Eric Johnson Signature Stratocaster
Bringing to life the vision of one of the most respected guitarists in the world, the Eric Johnson Signature Stratocaster Thinline is the perfect marriage between a semi-hollow body and a traditional Stratocaster. Johnson's search for his ideal tone is famous in guitar circles. Liquid and articulate, the sound perfectly complements the playing style that earned his place in the modern guitar pantheon.


Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages
pqxx::result::tuple Class Reference
Reference to one row in a result.
More...
#include <result.h>
Inheritance diagram for pqxx::result::tuple:
List of all members.
Detailed Description
Reference to one row in a result.
A tuple represents one row (also called a tuple) in a query result set. It also acts as a container mapping column numbers or names to field values (see below):
cout << tuple["date"].c_str() << ": " << tuple["name"].c_str() << endl;
The fields in a tuple can not currently be iterated over.
Member Typedef Documentation
Constructor & Destructor Documentation
| pqxx::result::tuple::~tuple |
( |
|
) |
|
|
| pqxx::result::tuple::tuple |
( |
|
) |
[protected] |
|
Member Function Documentation
| field pqxx::result::tuple::at |
( |
const PGSTD::string & |
s |
) |
const |
|
| size_type pqxx::result::tuple::ColumnNumber |
( |
const char |
ColName[] |
) |
const |
|
| size_type pqxx::result::tuple::ColumnNumber |
( |
const PGSTD::string & |
ColName |
) |
const |
|
| field pqxx::result::tuple::operator[] |
( |
const PGSTD::string & |
s |
) |
const |
|
Member Data Documentation
const result* pqxx::result::tuple::m_Home [protected]
|
|
The documentation for this class was generated from the following files:
Generated on Sat Jun 7 02:58:06 2003 for libpqxx by
1.3-rc3


Coverage report for
Generated at 30.11.2022 22:06:19 by DelphiCodeCoverage - an open source tool for Delphi Code Coverage.
Statistics for ..\..\Source\DECHashAuthentication.pas
| Number of lines covered | 304 | |
| Number of lines with code gen | 333 | |
| Line coverage | 91.3 % |
| 1 | {***************************************************************************** |
| 2 | The DEC team (see file NOTICE.txt) licenses this file |
| 3 | to you under the Apache License, Version 2.0 (the |
| 4 | "License"); you may not use this file except in compliance |
| 5 | with the License. A copy of this licence is found in the root directory |
| 6 | of this project in the file LICENCE.txt or alternatively at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, |
| 11 | software distributed under the License is distributed on an |
| 12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 13 | KIND, either express or implied. See the License for the |
| 14 | specific language governing permissions and limitations |
| 15 | under the License. |
| 16 | *****************************************************************************} |
| 17 | |
| 18 | /// <summary> |
| 19 | /// Unit containing all the KDF, MGF, HMAC and PBKDF2 algorithms |
| 20 | /// </summary> |
| 21 | unit DECHashAuthentication; |
| 22 | |
| 23 | interface |
| 24 | |
| 25 | uses |
| 26 | {$IFDEF FPC} |
| 27 | SysUtils, Classes, |
| 28 | {$ELSE} |
| 29 | System.SysUtils, System.Classes, Generics.Collections, |
| 30 | {$ENDIF} |
| 31 | DECBaseClass, DECHashBase, DECHashInterface, DECTypes , DECFormatBase; |
| 32 | |
| 33 | {$INCLUDE DECOptions.inc} |
| 34 | |
| 35 | type |
| 36 | /// <summary> |
| 37 | /// Type of the KDF variant |
| 38 | /// </summary> |
| 39 | TKDFType = (ktKDF1, ktKDF2, ktKDF3); |
| 40 | |
| 41 | /// <summary> |
| 42 | /// Meta class for the class containing the password hash specific properties |
| 43 | /// </summary> |
| 44 | TDECPasswordHashClass = class of TDECPasswordHash; |
| 45 | |
| 46 | /// <summary> |
| 47 | /// Class containing all the KDF, MGF, HMAC and PBKDF2 algorithms |
| 48 | /// </summary> |
| 49 | TDECHashAuthentication = class(TDECHash) |
| 50 | strict private |
| 51 | /// <summary> |
| 52 | /// Key deviation algorithm to derrive keys from other keys. |
| 53 | /// IEEE P1363 Working Group, ISO 18033-2:2004 |
| 54 | /// This is either KDF1 or KDF2 depending on KDFType |
| 55 | /// </summary> |
| 56 | /// <param name="Data"> |
| 57 | /// Source data from which the new key shall be derrived. |
| 58 | /// </param> |
| 59 | /// <param name="DataSize"> |
| 60 | /// Size in bytes of the source data passed. |
| 61 | /// </param> |
| 62 | /// <param name="Seed"> |
| 63 | /// Start value for pseudo random number generator |
| 64 | /// </param> |
| 65 | /// <param name="SeedSize"> |
| 66 | /// Size of the seed in byte. |
| 67 | /// </param> |
| 68 | /// <param name="MaskSize"> |
| 69 | /// Size of the generated output in byte |
| 70 | /// </param> |
| 71 | /// <param name="KDFType"> |
| 72 | /// Type of the algorithm: 1 = KDF1, 2 = KDF2 and 3 = KDF 3 |
| 73 | /// </param> |
| 74 | /// <returns> |
| 75 | /// Returns the new derrived key. |
| 76 | /// </returns> |
| 77 | class function KDFInternal(const Data; DataSize: Integer; const Seed; |
| 78 | SeedSize, MaskSize: Integer; |
| 79 | KDFType: TKDFType): TBytes; inline; |
| 80 | public |
| 81 | /// <summary> |
| 82 | /// Detects whether the given hash class is one particularily suited |
| 83 | /// for storing hashes of passwords |
| 84 | /// </summary> |
| 85 | /// <returns> |
| 86 | /// true if it's a hash class specifically designed to store password |
| 87 | /// hashes, false for ordinary hash algorithms. |
| 88 | /// </returns> |
| 89 | class function IsPasswordHash: Boolean; override; |
| 90 | |
| 91 | // mask generation |
| 92 | |
| 93 | /// <summary> |
| 94 | /// Mask generation: generates an output based on the data given which is |
| 95 | /// similar to a hash function but in contrast does not have a fixed output |
| 96 | /// length. Use of a MGF is desirable in cases where a fixed-size hash |
| 97 | /// would be inadequate. Examples include generating padding, producing |
| 98 | /// one time pads or keystreams in symmetric key encryption, and yielding |
| 99 | /// outputs for pseudorandom number generators. |
| 100 | /// Indexed Mask generation function, IEEE P1363 working group |
| 101 | /// equal to KDF1 except without seed. RFC 2437 PKCS #1 |
| 102 | /// </summary> |
| 103 | /// <param name="Data"> |
| 104 | /// Data from which to generate a mask from |
| 105 | /// </param> |
| 106 | /// <param name="DataSize"> |
| 107 | /// Size of the input data in bytes |
| 108 | /// </param> |
| 109 | /// <param name="MaskSize"> |
| 110 | /// Size of the returned mask in bytes |
| 111 | /// </param> |
| 112 | /// <returns> |
| 113 | /// Mask such that one cannot determine the data which had been given to |
| 114 | /// generate this mask from. |
| 115 | /// </returns> |
| 116 | class function MGF1(const Data; DataSize, MaskSize: Integer): TBytes; overload; |
| 117 | /// <summary> |
| 118 | /// Mask generation: generates an output based on the data given which is |
| 119 | /// similar to a hash function but incontrast does not have a fixed output |
| 120 | /// length. Use of a MGF is desirable in cases where a fixed-size hash |
| 121 | /// would be inadequate. Examples include generating padding, producing |
| 122 | /// one time pads or keystreams in symmetric key encryption, and yielding |
| 123 | /// outputs for pseudorandom number generators |
| 124 | /// </summary> |
| 125 | /// <param name="Data"> |
| 126 | /// Data from which to generate a mask from |
| 127 | /// </param> |
| 128 | /// <param name="MaskSize"> |
| 129 | /// Size of the returned mask in bytes |
| 130 | /// </param> |
| 131 | /// <returns> |
| 132 | /// Mask such that one cannot determine the data which had been given to |
| 133 | /// generate this mask from. |
| 134 | /// </returns> |
| 135 | class function MGF1(const Data: TBytes; MaskSize: Integer): TBytes; overload; |
| 136 | |
| 137 | /// <summary> |
| 138 | /// Key deviation algorithm to derrive keys from other keys. |
| 139 | /// IEEE P1363 Working Group, ISO 18033-2:2004 |
| 140 | /// </summary> |
| 141 | /// <param name="Data"> |
| 142 | /// Source data from which the new key shall be derrived. |
| 143 | /// </param> |
| 144 | /// <param name="DataSize"> |
| 145 | /// Size in bytes of the source data passed. |
| 146 | /// </param> |
| 147 | /// <param name="Seed"> |
| 148 | /// Salt value |
| 149 | /// </param> |
| 150 | /// <param name="SeedSize"> |
| 151 | /// Size of the seed/salt in byte. |
| 152 | /// </param> |
| 153 | /// <param name="MaskSize"> |
| 154 | /// Size of the generated output in byte |
| 155 | /// </param> |
| 156 | /// <returns> |
| 157 | /// Returns the new derrived key with the length specified in MaskSize. |
| 158 | /// </returns> |
| 159 | /// <remarks> |
| 160 | /// In earlier versions there was an optional format parameter. This has |
| 161 | /// been removed as this is a base class. The method might not have |
| 162 | /// returned a result with the MaskSize specified, as the formatting might |
| 163 | /// have had to alter this. This would have been illogical. |
| 164 | /// </remarks> |
| 165 | class function KDF1(const Data; DataSize: Integer; const Seed; |
| 166 | SeedSize, MaskSize: Integer): TBytes; overload; |
| 167 | |
| 168 | /// <summary> |
| 169 | /// Key deviation algorithm to derrive keys from other keys. |
| 170 | /// IEEE P1363 Working Group, ISO 18033-2:2004 |
| 171 | /// </summary> |
| 172 | /// <param name="Data"> |
| 173 | /// Source data from which the new key shall be derrived. |
| 174 | /// </param> |
| 175 | /// <param name="Seed"> |
| 176 | /// Salt value |
| 177 | /// </param> |
| 178 | /// <param name="MaskSize"> |
| 179 | /// Size of the generated output in byte |
| 180 | /// </param> |
| 181 | /// <returns> |
| 182 | /// Returns the new derrived key with the length specified in MaskSize. |
| 183 | /// </returns> |
| 184 | class function KDF1(const Data, Seed: TBytes; |
| 185 | MaskSize: Integer): TBytes; overload; |
| 186 | |
| 187 | /// <summary> |
| 188 | /// Key deviation algorithm to derrive keys from other keys. |
| 189 | /// IEEE P1363 Working Group, ISO 18033-2:2004 |
| 190 | /// </summary> |
| 191 | /// <param name="Data"> |
| 192 | /// Source data from which the new key shall be derrived. |
| 193 | /// </param> |
| 194 | /// <param name="DataSize"> |
| 195 | /// Size in bytes of the source data passed. |
| 196 | /// </param> |
| 197 | /// <param name="Seed"> |
| 198 | /// Salt value |
| 199 | /// </param> |
| 200 | /// <param name="SeedSize"> |
| 201 | /// Size of the seed/salt in byte. |
| 202 | /// </param> |
| 203 | /// <param name="MaskSize"> |
| 204 | /// Size of the generated output in byte |
| 205 | /// </param> |
| 206 | /// <returns> |
| 207 | /// Returns the new derrived key with the length specified in MaskSize. |
| 208 | /// </returns> |
| 209 | /// <remarks> |
| 210 | /// In earlier versions there was an optional format parameter. This has |
| 211 | /// been removed as this is a base class. The method might not have |
| 212 | /// returned a result with the MaskSize specified, as the formatting might |
| 213 | /// have had to alter this. This would have been illogical. |
| 214 | /// </remarks> |
| 215 | class function KDF2(const Data; DataSize: Integer; const Seed; |
| 216 | SeedSize, MaskSize: Integer): TBytes; overload; |
| 217 | |
| 218 | /// <summary> |
| 219 | /// Key deviation algorithm to derrive keys from other keys. |
| 220 | /// IEEE P1363 Working Group, ISO 18033-2:2004 |
| 221 | /// </summary> |
| 222 | /// <param name="Data"> |
| 223 | /// Source data from which the new key shall be derrived. |
| 224 | /// </param> |
| 225 | /// <param name="Seed"> |
| 226 | /// Start value for pseudo random number generator |
| 227 | /// </param> |
| 228 | /// <param name="MaskSize"> |
| 229 | /// Size of the generated output in byte |
| 230 | /// </param> |
| 231 | /// <returns> |
| 232 | /// Returns the new derrived key with the length specified in MaskSize. |
| 233 | /// </returns> |
| 234 | class function KDF2(const Data, Seed: TBytes; |
| 235 | MaskSize: Integer): TBytes; overload; |
| 236 | |
| 237 | /// <summary> |
| 238 | /// Key deviation algorithm to derrive keys from other keys. |
| 239 | /// </summary> |
| 240 | /// <param name="Data"> |
| 241 | /// Source data from which the new key shall be derrived. |
| 242 | /// </param> |
| 243 | /// <param name="DataSize"> |
| 244 | /// Size in bytes of the source data passed. |
| 245 | /// </param> |
| 246 | /// <param name="Seed"> |
| 247 | /// Salt value |
| 248 | /// </param> |
| 249 | /// <param name="SeedSize"> |
| 250 | /// Size of the seed/salt in byte. |
| 251 | /// </param> |
| 252 | /// <param name="MaskSize"> |
| 253 | /// Size of the generated output in byte |
| 254 | /// </param> |
| 255 | /// <returns> |
| 256 | /// Returns the new derrived key with the length specified in MaskSize. |
| 257 | /// </returns> |
| 258 | /// <remarks> |
| 259 | /// In earlier versions there was an optional format parameter. This has |
| 260 | /// been removed as this is a base class. The method might not have |
| 261 | /// returned a result with the MaskSize specified, as the formatting might |
| 262 | /// have had to alter this. This would have been illogical. |
| 263 | /// </remarks> |
| 264 | class function KDF3(const Data; DataSize: Integer; const Seed; |
| 265 | SeedSize, MaskSize: Integer): TBytes; overload; |
| 266 | |
| 267 | /// <summary> |
| 268 | /// Key deviation algorithm to derrive keys from other keys. |
| 269 | /// </summary> |
| 270 | /// <param name="Data"> |
| 271 | /// Source data from which the new key shall be derrived. |
| 272 | /// </param> |
| 273 | /// <param name="Seed"> |
| 274 | /// Salt value |
| 275 | /// </param> |
| 276 | /// <param name="MaskSize"> |
| 277 | /// Size of the generated output in byte |
| 278 | /// </param> |
| 279 | /// <returns> |
| 280 | /// Returns the new derrived key with the length specified in MaskSize. |
| 281 | /// </returns> |
| 282 | class function KDF3(const Data, Seed: TBytes; |
| 283 | MaskSize: Integer): TBytes; overload; |
| 284 | |
| 285 | // DEC's own KDF + MGF |
| 286 | |
| 287 | /// <summary> |
| 288 | /// Key deviation algorithm to derrive keys from other keys. The alrorithm |
| 289 | /// implemented by this method does not follow any official standard. |
| 290 | /// </summary> |
| 291 | /// <param name="Data"> |
| 292 | /// Source data from which the new key shall be derrived. |
| 293 | /// </param> |
| 294 | /// <param name="DataSize"> |
| 295 | /// Size in bytes of the source data passed. |
| 296 | /// </param> |
| 297 | /// <param name="Seed"> |
| 298 | /// Salt value |
| 299 | /// </param> |
| 300 | /// <param name="SeedSize"> |
| 301 | /// Size of the seed/salt in byte. |
| 302 | /// </param> |
| 303 | /// <param name="MaskSize"> |
| 304 | /// Size of the generated output in byte |
| 305 | /// </param> |
| 306 | /// <param name="Index"> |
| 307 | /// Optional parameter: can be used to specify a different default value |
| 308 | /// for the index variable used in the algorithm. |
| 309 | /// </param> |
| 310 | /// <returns> |
| 311 | /// Returns the new derrived key with the length specified in MaskSize. |
| 312 | /// </returns> |
| 313 | class function KDFx(const Data; DataSize: Integer; const Seed; |
| 314 | SeedSize, MaskSize: Integer; |
| 315 | Index: UInt32 = 1): TBytes; overload; |
| 316 | /// <summary> |
| 317 | /// Key deviation algorithm to derrive keys from other keys. |
| 318 | /// </summary> |
| 319 | /// <remarks> |
| 320 | /// This variant of the algorithm does not follow an official standard. |
| 321 | /// It has been created by the original author of DEC. |
| 322 | /// </remarks> |
| 323 | /// <param name="Data"> |
| 324 | /// Source data from which the new key shall be derrived. |
| 325 | /// </param> |
| 326 | /// <param name="Seed"> |
| 327 | /// Salt value |
| 328 | /// </param> |
| 329 | /// <param name="MaskSize"> |
| 330 | /// Size of the generated output in byte |
| 331 | /// </param> |
| 332 | /// <param name="Index"> |
| 333 | /// Optional parameter: can be used to specify a different default value |
| 334 | /// for the index variable used in the algorithm. |
| 335 | /// </param> |
| 336 | /// <returns> |
| 337 | /// Returns the new derrived key with the length specified in MaskSize. |
| 338 | /// </returns> |
| 339 | class function KDFx(const Data, Seed: TBytes; MaskSize: Integer; |
| 340 | Index: UInt32 = 1): TBytes; overload; |
| 341 | |
| 342 | /// <summary> |
| 343 | /// Mask generation: generates an output based on the data given which is |
| 344 | /// similar to a hash function but incontrast does not have a fixed output |
| 345 | /// length. Use of a MGF is desirable in cases where a fixed-size hash |
| 346 | /// would be inadequate. Examples include generating padding, producing |
| 347 | /// one time pads or keystreams in symmetric key encryption, and yielding |
| 348 | /// outputs for pseudorandom number generators. |
| 349 | /// </summary> |
| 350 | /// <remarks> |
| 351 | /// This variant of the algorithm does not follow an official standard. |
| 352 | /// It has been created by the original author of DEC. |
| 353 | /// </remarks> |
| 354 | /// <param name="Data"> |
| 355 | /// Data from which to generate a mask from |
| 356 | /// </param> |
| 357 | /// <param name="DataSize"> |
| 358 | /// Size of the passed data in bytes |
| 359 | /// </param> |
| 360 | /// <param name="MaskSize"> |
| 361 | /// Size of the returned mask in bytes |
| 362 | /// </param> |
| 363 | /// <param name="Index"> |
| 364 | /// Looks like this is a salt applied to each byte of output data? |
| 365 | { TODO : Clarify this parameter } |
| 366 | /// </param> |
| 367 | /// <returns> |
| 368 | /// Mask such that one cannot determine the data which had been given to |
| 369 | /// generate this mask from. |
| 370 | /// </returns> |
| 371 | class function MGFx(const Data; DataSize, MaskSize: Integer; |
| 372 | Index: UInt32 = 1): TBytes; overload; |
| 373 | /// <summary> |
| 374 | /// Mask generation: generates an output based on the data given which is |
| 375 | /// similar to a hash function but incontrast does not have a fixed output |
| 376 | /// length. Use of a MGF is desirable in cases where a fixed-size hash |
| 377 | /// would be inadequate. Examples include generating padding, producing |
| 378 | /// one time pads or keystreams in symmetric key encryption, and yielding |
| 379 | /// outputs for pseudorandom number generators. |
| 380 | /// </summary> |
| 381 | /// <remarks> |
| 382 | /// This variant of the algorithm does not follow an official standard. |
| 383 | /// It has been created by the original author of DEC. |
| 384 | /// </remarks> |
| 385 | /// <param name="Data"> |
| 386 | /// Data from which to generate a mask from |
| 387 | /// </param> |
| 388 | /// <param name="MaskSize"> |
| 389 | /// Size of the returned mask in bytes |
| 390 | /// </param> |
| 391 | /// <param name="Index"> |
| 392 | /// Looks like this is a salt applied to each byte of output data? |
| 393 | { TODO : Clarify this parameter } |
| 394 | /// </param> |
| 395 | /// <returns> |
| 396 | /// Mask such that one cannot determine the data which had been given to |
| 397 | /// generate this mask from. |
| 398 | /// </returns> |
| 399 | class function MGFx(const Data: TBytes; MaskSize: Integer; |
| 400 | Index: UInt32 = 1): TBytes; overload; |
| 401 | |
| 402 | /// <summary> |
| 403 | /// HMAC according to rfc2202: hash message authentication code allow to |
| 404 | /// verify both the data integrity and the authenticity of a message. |
| 405 | /// </summary> |
| 406 | /// <param name="Key"> |
| 407 | /// This is the secret key which shall not be transmitted over the line. |
| 408 | /// The sender uses this key to create the resulting HMAC, transmits the |
| 409 | /// text and the HMAC over the line and the receiver recalculates the HMAC |
| 410 | /// based on his copy of the secret key. If his calculated HMAC equals the |
| 411 | /// transfered HMAC value the message has not been tampered. |
| 412 | /// </param> |
| 413 | /// <param name="Text"> |
| 414 | /// Text over which to calculate the HMAC |
| 415 | /// </param> |
| 416 | /// <returns> |
| 417 | /// Calculated HMAC |
| 418 | /// </returns> |
| 419 | class function HMAC(const Key, Text: TBytes): TBytes; overload; |
| 420 | |
| 421 | /// <summary> |
| 422 | /// HMAC according to rfc2202: hash message authentication code allow to |
| 423 | /// verify both the data integrity and the authenticity of a message. |
| 424 | /// </summary> |
| 425 | /// <param name="Key"> |
| 426 | /// This is the secret key which shall not be transmitted over the line. |
| 427 | /// The sender uses this key to create the resulting HMAC, transmits the |
| 428 | /// text and the HMAC over the line and the receiver recalculates the HMAC |
| 429 | /// based on his copy of the secret key. If his calculated HMAC equals the |
| 430 | /// transfered HMAC value the message has not been tampered. |
| 431 | /// </param> |
| 432 | /// <param name="Text"> |
| 433 | /// Text over which to calculate the HMAC |
| 434 | /// </param> |
| 435 | /// <returns> |
| 436 | /// Calculated HMAC |
| 437 | /// </returns> |
| 438 | class function HMAC(const Key, Text: RawByteString): TBytes; overload; |
| 439 | |
| 440 | /// <summary> |
| 441 | /// Password based key deviation function 2 |
| 442 | /// RFC 2898, PKCS #5. |
| 443 | /// This can be used to create a login sheme by storing the output, |
| 444 | /// number of iterations and the salt. When the user enters a password |
| 445 | /// this calculation is done using the same parameters as stored for his |
| 446 | /// user account and comparing the output. |
| 447 | /// </summary> |
| 448 | /// <param name="Password"> |
| 449 | /// Password to create the deviation from |
| 450 | /// </param> |
| 451 | /// <param name="Salt"> |
| 452 | /// Salt used to modify the password |
| 453 | /// </param> |
| 454 | /// <param name="Iterations"> |
| 455 | /// Number of iterations to perform |
| 456 | /// </param> |
| 457 | /// <param name="KeyLength"> |
| 458 | /// Length of the resulting key in byte |
| 459 | /// </param> |
| 460 | class function PBKDF2(const Password, Salt: TBytes; Iterations: Integer; |
| 461 | KeyLength: Integer): TBytes; overload; |
| 462 | |
| 463 | /// <summary> |
| 464 | /// Password based key deviation function 2 |
| 465 | /// RFC 2898, PKCS #5. |
| 466 | /// This can be used to create a login sheme by storing the output, |
| 467 | /// number of iterations and the salt. When the user enters a password |
| 468 | /// this calculation is done using the same parameters as stored for his |
| 469 | /// user account and comparing the output. |
| 470 | /// </summary> |
| 471 | /// <param name="Password"> |
| 472 | /// Password to create the deviation from |
| 473 | /// </param> |
| 474 | /// <param name="Salt"> |
| 475 | /// Salt used to modify the password |
| 476 | /// </param> |
| 477 | /// <param name="Iterations"> |
| 478 | /// Number of iterations to perform |
| 479 | /// </param> |
| 480 | /// <param name="KeyLength"> |
| 481 | /// Length of the resulting key in byte |
| 482 | /// </param> |
| 483 | class function PBKDF2(const Password, Salt: RawByteString; |
| 484 | Iterations: Integer; |
| 485 | KeyLength: Integer): TBytes; overload; |
| 486 | end; |
| 487 | |
| 488 | /// <summary> |
| 489 | /// Adds methods which shall not be found in the specialized password hash |
| 490 | /// classes. Mainly the CalcStreamXXX and CalcFileXXX ones. They shall not |
| 491 | /// be contained there as those password hashes usually restrict the maximum |
| 492 | /// length of the data which can be hashed. |
| 493 | /// </summary> |
| 494 | TDECHashExtended = class(TDECHashAuthentication, IDECHashExtended) |
| 495 | /// <summary> |
| 496 | /// Calculates the hash value over a given stream of bytes |
| 497 | /// </summary> |
| 498 | /// <param name="Stream"> |
| 499 | /// Memory or file stream over which the hash value shall be calculated. |
| 500 | /// The stream must be assigned. The hash value will always be calculated |
| 501 | /// from the current position of the stream. |
| 502 | /// </param> |
| 503 | /// <param name="Size"> |
| 504 | /// Number of bytes within the stream over which to calculate the hash value |
| 505 | /// </param> |
| 506 | /// <param name="HashResult"> |
| 507 | /// In this byte array the calculated hash value will be returned |
| 508 | /// </param> |
| 509 | /// <param name="OnProgress"> |
| 510 | /// Optional callback routine. It can be used to display the progress of |
| 511 | /// the operation. |
| 512 | /// </param> |
| 513 | procedure CalcStream(const Stream: TStream; Size: Int64; var HashResult: TBytes; |
| 514 | const OnProgress:TDECProgressEvent = nil); overload; |
| 515 | /// <summary> |
| 516 | /// Calculates the hash value over a givens stream of bytes |
| 517 | /// </summary> |
| 518 | /// <param name="Stream"> |
| 519 | /// Memory or file stream over which the hash value shall be calculated. |
| 520 | /// The stream must be assigned. The hash value will always be calculated |
| 521 | /// from the current position of the stream. |
| 522 | /// </param> |
| 523 | /// <param name="Size"> |
| 524 | /// Number of bytes within the stream over which to calculate the hash value |
| 525 | /// </param> |
| 526 | /// <param name="Format"> |
| 527 | /// Optional formatting class. The formatting of that will be applied to |
| 528 | /// the returned hash value. |
| 529 | /// </param> |
| 530 | /// <param name="OnProgress"> |
| 531 | /// Optional callback routine. It can be used to display the progress of |
| 532 | /// the operation. |
| 533 | /// </param> |
| 534 | /// <returns> |
| 535 | /// Hash value over the bytes in the stream, formatted with the formatting |
| 536 | /// passed as format parameter, if used. |
| 537 | /// </returns> |
| 538 | function CalcStream(const Stream: TStream; Size: Int64; Format: TDECFormatClass = nil; |
| 539 | const OnProgress:TDECProgressEvent = nil): RawByteString; overload; |
| 540 | |
| 541 | /// <summary> |
| 542 | /// Calculates the hash value over a given stream of bytes. The calculated |
| 543 | /// hash value can be retrieved with one of the DigestAsXXX methods. |
| 544 | /// </summary> |
| 545 | /// <param name="Stream"> |
| 546 | /// Memory or file stream over which the hash value shall be calculated. |
| 547 | /// The stream must be assigned. The hash value will always be calculated |
| 548 | /// from the current position of the stream. |
| 549 | /// </param> |
| 550 | /// <param name="Size"> |
| 551 | /// Number of bytes within the stream over which to calculate the hash value |
| 552 | /// </param> |
| 553 | /// <param name="OnProgress"> |
| 554 | /// Optional callback routine. It can be used to display the progress of |
| 555 | /// the operation. |
| 556 | /// </param> |
| 557 | /// <param name="DoFinalize"> |
| 558 | /// Optinal parameter: if true this call is the last one and the |
| 559 | /// finalization of the hash calculation, including calling done, will be |
| 560 | /// carried out in this method call as well. |
| 561 | /// </param> |
| 562 | /// <remarks> |
| 563 | /// Before calling this method for the first time after creation of the |
| 564 | /// hash instance or after calling Done Init needs to be called. |
| 565 | /// After calling this method Done needs to be called and in case of |
| 566 | /// algorithms (like SHA3) with a message size in bits and not whole bytes |
| 567 | /// the contents of the last byte needs to be assigned to PaddingByte before |
| 568 | /// calling Done! |
| 569 | /// </remarks> |
| 570 | procedure CalcStream(const Stream: TStream; Size: Int64; |
| 571 | const OnProgress:TDECProgressEvent = nil; |
| 572 | DoFinalize: Boolean = false); overload; |
| 573 | |
| 574 | /// <summary> |
| 575 | /// Calculates the hash value over the contents of a given file |
| 576 | /// </summary> |
| 577 | /// <param name="FileName"> |
| 578 | /// Path and name of the file to be processed |
| 579 | /// </param> |
| 580 | /// <param name="HashResult"> |
| 581 | /// Here the resulting hash value is being returned as byte array |
| 582 | /// </param> |
| 583 | /// <param name="OnProgress"> |
| 584 | /// Optional callback. If being used the hash calculation will call it from |
| 585 | /// time to time to return the current progress of the operation |
| 586 | /// </param> |
| 587 | procedure CalcFile(const FileName: string; var HashResult: TBytes; |
| 588 | const OnProgress:TDECProgressEvent = nil); overload; |
| 589 | /// <summary> |
| 590 | /// Calculates the hash value over the contents of a given file |
| 591 | /// </summary> |
| 592 | /// <param name="FileName"> |
| 593 | /// Path and name of the file to be processed |
| 594 | /// </param> |
| 595 | /// <param name="Format"> |
| 596 | /// Optional parameter: Formatting class. If being used the formatting is |
| 597 | /// being applied to the returned string with the calculated hash value |
| 598 | /// </param> |
| 599 | /// <param name="OnProgress"> |
| 600 | /// Optional callback. If being used the hash calculation will call it from |
| 601 | /// time to time to return the current progress of the operation |
| 602 | /// </param> |
| 603 | /// <returns> |
| 604 | /// Calculated hash value as RawByteString. |
| 605 | /// </returns> |
| 606 | /// <remarks> |
| 607 | /// We recommend to use a formatting which results in 7 bit ASCII chars |
| 608 | /// being returned, otherwise the conversion into the RawByteString might |
| 609 | /// result in strange characters in the returned result. |
| 610 | /// </remarks> |
| 611 | function CalcFile(const FileName: string; Format: TDECFormatClass = nil; |
| 612 | const OnProgress:TDECProgressEvent = nil): RawByteString; overload; |
| 613 | end; |
| 614 | |
| 615 | /// <summary> |
| 616 | /// All hash classes with hash algorithms specially developed for password |
| 617 | /// hashing should inherit from this class in order to be able to distinguish |
| 618 | /// those from normal hash algorithms not really meant to be used for password |
| 619 | /// hashing. |
| 620 | /// </summary> |
| 621 | TDECPasswordHash = class(TDECHashAuthentication, IDECHashPassword) |
| 622 | strict private |
| 623 | /// <summary> |
| 624 | /// Sets the salt value given. Throws an EDECHashException if a salt is |
| 625 | /// passed which is longer than MaxSaltLength. |
| 626 | /// </summary> |
| 627 | /// <exception cref="EDECHashException"> |
| 628 | /// Exception raised if length of <c>Value</c> is not in the range of |
| 629 | /// <c>MinSaltLength</c> and <c>MaxSaltLength</c> |
| 630 | /// </exception> |
| 631 | procedure SetSalt(const Value: TBytes); |
| 632 | /// <summary> |
| 633 | /// Returns the defined salt value |
| 634 | /// </summary> |
| 635 | function GetSalt: TBytes; |
| 636 | strict protected |
| 637 | /// <summary> |
| 638 | /// Most, if not all password hashing algorithms (like bcrypt) have a salt |
| 639 | /// parameter to modify the entered password value. |
| 640 | /// </summary> |
| 641 | FSalt : TBytes; |
| 642 | |
| 643 | /// <summary> |
| 644 | /// Overwrite the salt value |
| 645 | /// </summary> |
| 646 | procedure DoDone; override; |
| 647 | |
| 648 | {$Region CryptFormatHandling} |
| 649 | /// <summary> |
| 650 | /// Returns the ID code for Crypt/BSD like storing of passwords. The ID |
| 651 | /// has to start with the $ at the beginning and does not contain a |
| 652 | /// trailing $. |
| 653 | /// </summary> |
| 654 | /// <returns> |
| 655 | /// If the algorithm on which this is being used is a Crypt/BSD compatible |
| 656 | /// password hash algorithm the ID is returned otherwise an empty string. |
| 657 | /// </returns> |
| 658 | class function GetCryptID:string; virtual; |
| 659 | |
| 660 | /// <summary> |
| 661 | /// Returns the parameters required for the crypt-like password storing |
| 662 | /// in that format. |
| 663 | /// </summary> |
| 664 | /// <param name="Params"> |
| 665 | /// Algorithm specific parameters used for initialization. For details see |
| 666 | /// documentation of the concrete implementation in the algorithm. |
| 667 | /// </param> |
| 668 | /// <param name="Format"> |
| 669 | /// Format class for formatting the output |
| 670 | /// </param> |
| 671 | /// <returns> |
| 672 | /// Returns an empty string if the the algorithm on which this is being |
| 673 | /// used is not a Crypt/BSD compatible password hash algorithm |
| 674 | /// </returns> |
| 675 | function GetCryptParams(const Params : string; |
| 676 | Format : TDECFormatClass):string; virtual; |
| 677 | /// <summary> |
| 678 | /// Returns the salt required for the crypt-like password storing |
| 679 | /// in that format. |
| 680 | /// </summary> |
| 681 | /// <param name="Salt"> |
| 682 | /// The raw salt value |
| 683 | /// </param> |
| 684 | /// <param name="Format"> |
| 685 | /// Format class for formatting the output |
| 686 | /// </param> |
| 687 | function GetCryptSalt(const Salt : TBytes; |
| 688 | Format : TDECFormatClass):string; virtual; |
| 689 | /// <summary> |
| 690 | /// Returns the hash required for the crypt-like password storing |
| 691 | /// in that format. If a salt etc. is needed that needs to be scepcified |
| 692 | /// before calling this method. |
| 693 | /// </summary> |
| 694 | /// <param name="Password"> |
| 695 | /// Password entered which shall be hashed. |
| 696 | /// </param> |
| 697 | /// <param name="Params"> |
| 698 | /// Algorithm specific parameters used for initialization. For details see |
| 699 | /// documentation of the concrete implementation in the algorithm. |
| 700 | /// </param> |
| 701 | /// <param name="Salt"> |
| 702 | /// Salt value used by the password hash calculation. Depending on the |
| 703 | /// value of SaltIsRaw, the salt needs to specified in raw encoding or |
| 704 | /// in the encoding used in the Crypt/BSD password storage string. |
| 705 | /// </param> |
| 706 | /// <param name="Salt"> |
| 707 | /// Salt value used by the password hash calculation in binary raw format, |
| 708 | /// means not Radix64 encoded or so. |
| 709 | /// </param> |
| 710 | /// <param name="Format"> |
| 711 | /// Format class for formatting the output |
| 712 | /// </param> |
| 713 | /// <returns> |
| 714 | /// Returns an empty string if the the algorithm on which this is being |
| 715 | /// used is not a Crypt/BSD compatible password hash algorithm. |
| 716 | /// </returns> |
| 717 | function GetCryptHash(Password : TBytes; |
| 718 | const Params : string; |
| 719 | const Salt : TBytes; |
| 720 | Format : TDECFormatClass):string; virtual; |
| 721 | {$EndRegion} |
| 722 | public |
| 723 | /// <summary> |
| 724 | /// Returns the maximum length of a salt value given for the algorithm |
| 725 | /// in byte |
| 726 | /// </summary> |
| 727 | function MaxSaltLength:UInt8; virtual; abstract; |
| 728 | /// <summary> |
| 729 | /// Returns the minimum length of a salt value given for the algorithm |
| 730 | /// in byte |
| 731 | /// </summary> |
| 732 | function MinSaltLength:UInt8; virtual; abstract; |
| 733 | /// <summary> |
| 734 | /// Returns the maximum length of a user supplied password given for the |
| 735 | /// algorithm in byte |
| 736 | /// </summary> |
| 737 | class function MaxPasswordLength:UInt8; virtual; abstract; |
| 738 | |
| 739 | {$Region CryptBSDFormatHandlingPublic} |
| 740 | /// <summary> |
| 741 | /// Tries to find a class type by its Crypt identification |
| 742 | /// (e.g. 2a is Bcrypt). |
| 743 | /// </summary> |
| 744 | /// <param name="Identity"> |
| 745 | /// Identity to look for, with or without the starting $ delimiter sign. |
| 746 | /// </param> |
| 747 | /// <returns> |
| 748 | /// Returns the class type of the class with the specified identity value |
| 749 | /// or throws an EDECClassNotRegisteredException exception if no class |
| 750 | /// with the given Crypt identity has been found |
| 751 | /// </returns> |
| 752 | /// <exception cref="EDECClassNotRegisteredException"> |
| 753 | /// Exception raised if the class specified by <c>Identity</c> is not found |
| 754 | /// </exception> |
| 755 | class function ClassByCryptIdentity(Identity: string): TDECPasswordHashClass; |
| 756 | |
| 757 | /// <summary> |
| 758 | /// Calculates a passwort hash for the given password and returns it in |
| 759 | /// a BSDCrypt compatible format. This method only works for those hash |
| 760 | /// algorithms implementing the necessary GetBSDCryptID method. |
| 761 | /// </summary> |
| 762 | /// <param name="Password"> |
| 763 | /// Entered password for which to calculate the hash. The caller is |
| 764 | /// responsible to ensure the maximum password length is adhered to. |
| 765 | /// Any exceptions raised due to too long passwords are not caught here! |
| 766 | /// </param> |
| 767 | /// <param name="Params"> |
| 768 | /// Algorithm specific parameters used for initialization. For details see |
| 769 | /// documentation of the concrete implementation in the algorithm. |
| 770 | /// </param> |
| 771 | /// <param name="Salt"> |
| 772 | /// Salt value used by the password hash calculation. Depending on the |
| 773 | /// value of SaltIsRaw, the salt needs to specified in raw encoding or |
| 774 | /// in the encoding used in the Crypt/BSD password storage string. |
| 775 | /// </param> |
| 776 | /// <param name="SaltIsRaw"> |
| 777 | /// If true the passed salt value is a raw value. If false it is encoded |
| 778 | /// like in the Crypt/BSD password storage string. |
| 779 | /// </param> |
| 780 | /// <param name="Format"> |
| 781 | /// Formatting class used to format the calculated password. Different |
| 782 | /// algorithms in BSDCrypt use different algorithms so one needs to know |
| 783 | /// which one to pass. See description of the hash class used. |
| 784 | /// </param> |
| 785 | /// <returns> |
| 786 | /// Calculated hash value in BSD crypt style format. Returns an empty |
| 787 | /// string if the algorithm is not a Crypt/BSD style password hash algorithm. |
| 788 | /// </returns> |
| 789 | /// <exception cref="EDECHashException"> |
| 790 | /// Exception raised if length of <c>Password</c> is higher than |
| 791 | /// <c>MaxPasswordLength</c> or if a salt with a different length than |
| 792 | /// 128 bit has been specified. |
| 793 | /// </exception> |
| 794 | function GetDigestInCryptFormat(const Password : string; |
| 795 | const Params : string; |
| 796 | const Salt : string; |
| 797 | SaltIsRaw : Boolean; |
| 798 | Format : TDECFormatClass):string; overload; |
| 799 | |
| 800 | /// <summary> |
| 801 | /// Calculates a passwort hash for the given password and returns it in |
| 802 | /// a BSDCrypt compatible format. This method only works for those hash |
| 803 | /// algorithms implementing the necessary GetBSDCryptID method. |
| 804 | /// </summary> |
| 805 | /// <param name="Password"> |
| 806 | /// Entered password for which to calculate the hash. The caller is |
| 807 | /// responsible to ensure the maximum password length is adhered to. |
| 808 | /// Any exceptions raised due to too long passwords are not caught here! |
| 809 | /// </param> |
| 810 | /// <param name="Params"> |
| 811 | /// Algorithm specific parameters used for initialization. For details see |
| 812 | /// documentation of the concrete implementation in the algorithm. |
| 813 | /// </param> |
| 814 | /// <param name="Salt"> |
| 815 | /// Salt value used by the password hash calculation. Depending on the |
| 816 | /// value of SaltIsRaw, the salt needs to specified in raw encoding or |
| 817 | /// in the encoding used in the Crypt/BSD password storage string. |
| 818 | /// </param> |
| 819 | /// <param name="SaltIsRaw"> |
| 820 | /// If true the passed salt value is a raw value. If false it is encoded |
| 821 | /// like in the Crypt/BSD password storage string. |
| 822 | /// </param> |
| 823 | /// <param name="Format"> |
| 824 | /// Formatting class used to format the calculated password. Different |
| 825 | /// algorithms in BSDCrypt use different algorithms so one needs to know |
| 826 | /// which one to pass. See description of the hash class used. |
| 827 | /// </param> |
| 828 | /// <returns> |
| 829 | /// Calculated hash value in BSD crypt style format. Returns an empty |
| 830 | /// string if the algorithm is not a Crypt/BSD style password hash algorithm. |
| 831 | /// </returns> |
| 832 | /// <exception cref="EDECHashException"> |
| 833 | /// Exception raised if length of <c>Password</c> is higher than |
| 834 | /// <c>MaxPasswordLength</c> or if a salt with a different length than |
| 835 | /// 128 bit has been specified. |
| 836 | /// </exception> |
| 837 | function GetDigestInCryptFormat(Password : TBytes; |
| 838 | const Params : string; |
| 839 | const Salt : string; |
| 840 | SaltIsRaw : Boolean; |
| 841 | Format : TDECFormatClass):string; overload; virtual; |
| 842 | |
| 843 | /// <summary> |
| 844 | /// Checks whether a given password is the correct one for a password |
| 845 | /// storage "record"/entry in Crypt/BSD format. |
| 846 | /// </summary> |
| 847 | /// <param name="Password"> |
| 848 | /// Password to check for validity |
| 849 | /// </param> |
| 850 | /// <param name="CryptData"> |
| 851 | /// The data needed to "compare" the password against in Crypt/BSD like |
| 852 | /// format: $<id>[$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]] |
| 853 | /// The exact format depends on the algorithm used. |
| 854 | /// </param> |
| 855 | /// <param name="Format"> |
| 856 | /// Must be the right type for the Crypt/BSD encoding used by the |
| 857 | /// algorithm used. This was implemented this way to avoid making the |
| 858 | /// DECHashAuthentication unit dependant on the DECFormat unit not needed |
| 859 | /// otherwise. |
| 860 | /// </param> |
| 861 | /// <returns> |
| 862 | /// True if the password given is correct. |
| 863 | /// </returns> |
| 864 | function IsValidPassword(const Password : string; |
| 865 | const CryptData : string; |
| 866 | Format : TDECFormatClass): Boolean; overload; |
| 867 | |
| 868 | /// <summary> |
| 869 | /// Checks whether a given password is the correct one for a password |
| 870 | /// storage "record"/entry in Crypt/BSD format. |
| 871 | /// </summary> |
| 872 | /// <param name="Password"> |
| 873 | /// Password to check for validity |
| 874 | /// </param> |
| 875 | /// <param name="CryptData"> |
| 876 | /// The data needed to "compare" the password against in Crypt/BSD like |
| 877 | /// format: $<id>[$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]] |
| 878 | /// The exact format depends on the algorithm used. |
| 879 | /// </param> |
| 880 | /// <param name="Format"> |
| 881 | /// Must be the right type for the Crypt/BSD encoding used by the |
| 882 | /// algorithm used. This was implemented this way to avoid making the |
| 883 | /// DECHashAuthentication unit dependant on the DECFormat unit not needed |
| 884 | /// otherwise. |
| 885 | /// </param> |
| 886 | /// <returns> |
| 887 | /// True if the password given is correct. |
| 888 | /// </returns> |
| 889 | function IsValidPassword(Password : TBytes; |
| 890 | const CryptData : string; |
| 891 | Format : TDECFormatClass): Boolean; overload; virtual; |
| 892 | {$EndRegion} |
| 893 | |
| 894 | /// <summary> |
| 895 | /// Defines the salt value used. Throws an EDECHashException if a salt is |
| 896 | /// passed which is longer than MaxSaltLength. The salt has to be passed |
| 897 | /// in binary form. Any Base64 encoded salt needs to be decoded before |
| 898 | /// passing. |
| 899 | /// </summary> |
| 900 | /// <exception cref="EDECHashException"> |
| 901 | /// Exception raised if the length of the value assigned is not in the |
| 902 | /// range of <c>MinSaltLength</c> and <c>MaxSaltLength</c> |
| 903 | /// </exception> |
| 904 | property Salt: TBytes |
| 905 | read GetSalt |
| 906 | write SetSalt; |
| 907 | end; |
| 908 | |
| 909 | {$IF CompilerVersion < 28.0} |
| 910 | /// <summary> |
| 911 | /// Class helper for implementing array concatenation which is not available |
| 912 | /// in Delphi XE6 or lower. |
| 913 | /// </summary> |
| 914 | /// <remarks> |
| 915 | /// Shall be removed as soon as the minimum supported version is XE7 or higher. |
| 916 | /// </remarks> |
| 917 | TArrHelper = class |
| 918 | class procedure AppendArrays<T>(var A: TArray<T>; const B: TArray<T>); |
| 919 | end; |
| 920 | {$IFEND} |
| 921 | |
| 922 | /// <summary> |
| 923 | /// Meta class for the class containing the authentication methods |
| 924 | /// </summary> |
| 925 | TDECHashAuthenticationClass = class of TDECHashAuthentication; |
| 926 | /// <summary> |
| 927 | /// Meta class for the class containing the additional calculation methods |
| 928 | /// </summary> |
| 929 | TDECHashExtendedClass = class of TDECHashExtended; |
| 930 | |
| 931 | implementation |
| 932 | |
| 933 | uses |
| 934 | DECUtil; |
| 935 | |
| 936 | resourcestring |
| 937 | /// <summary> |
| 938 | /// Exception message when specifying a salt value longer than allowed |
| 939 | /// </summary> |
| 940 | sSaltValueTooLong = 'Maximum allowed salt length (%0:d byte) exceeded'; |
| 941 | /// <summary> |
| 942 | /// Exception message when specifying a salt value shorter than allowed |
| 943 | /// </summary> |
| 944 | sSaltValueTooShort = 'Minumum allowed salt length (%0:d byte) exceeded'; |
| 945 | /// <summary> |
| 946 | /// No class for the given crypt ID has been registered, so that ID is |
| 947 | /// not supported. |
| 948 | /// </summary> |
| 949 | sCryptIDNotRegistered = 'No class for crypt ID %s registered'; |
| 950 | |
| 951 | class function TDECHashAuthentication.IsPasswordHash: Boolean; |
| 952 | begin |
| 953 | Result := self.InheritsFrom(TDECPasswordHash); |
| 954 | end; |
| 955 | |
| 956 | class function TDECHashAuthentication.KDFInternal(const Data; DataSize: Integer; const Seed; |
| 957 | SeedSize, MaskSize: Integer; KDFType: TKDFType): TBytes; |
| 958 | var |
| 959 | I, n, |
| 960 | Rounds, DigestBytes : Integer; |
| 961 | Dest : PByteArray; |
| 962 | Count : UInt32; |
| 963 | HashInstance : TDECHashAuthentication; |
| 964 | begin |
| 965 | SetLength(Result, 0); |
| 966 | DigestBytes := DigestSize; |
| 967 | Assert(MaskSize >= 0); |
| 968 | Assert(DataSize >= 0); |
| 969 | Assert(SeedSize >= 0); |
| 970 | Assert(DigestBytes >= 0); |
| 971 | |
| 972 | HashInstance := TDECHashAuthenticationClass(self).Create; |
| 973 | try |
| 974 | Rounds := (MaskSize + DigestBytes - 1) div DigestBytes; |
| 975 | SetLength(Result, Rounds * DigestBytes); |
| 976 | Dest := @Result[0]; |
| 977 | |
| 978 | |
| 979 | if (KDFType = ktKDF2) then |
| 980 | n := 1 |
| 981 | else |
| 982 | n := 0; |
| 983 | |
| 984 | for I := 0 to Rounds-1 do |
| 985 | begin |
| 986 | Count := SwapUInt32(n); |
| 987 | HashInstance.Init; |
| 988 | |
| 989 | if (KDFType = ktKDF3) then |
| 990 | begin |
| 991 | HashInstance.Calc(Count, SizeOf(Count)); |
| 992 | HashInstance.Calc(Data, DataSize); |
| 993 | end |
| 994 | else |
| 995 | begin |
| 996 | HashInstance.Calc(Data, DataSize); |
| 997 | HashInstance.Calc(Count, SizeOf(Count)); |
| 998 | end; |
| 999 | |
| 1000 | HashInstance.Calc(Seed, SeedSize); |
| 1001 | HashInstance.Done; |
| 1002 | Move(HashInstance.Digest[0], Dest[(I) * DigestBytes], DigestBytes); |
| 1003 | |
| 1004 | inc(n); |
| 1005 | end; |
| 1006 | |
| 1007 | SetLength(Result, MaskSize); |
| 1008 | finally |
| 1009 | HashInstance.Free; |
| 1010 | end; |
| 1011 | end; |
| 1012 | |
| 1013 | class function TDECHashAuthentication.MGF1(const Data; DataSize, MaskSize: Integer): TBytes; |
| 1014 | begin |
| 1015 | Result := KDF1(Data, DataSize, NullStr, 0, MaskSize); |
| 1016 | end; |
| 1017 | |
| 1018 | class function TDECHashAuthentication.MGF1(const Data: TBytes; MaskSize: Integer): TBytes; |
| 1019 | begin |
| 1020 | Result := KDFInternal(Data[0], Length(Data), NullStr, 0, MaskSize, ktKDF1); |
| 1021 | end; |
| 1022 | |
| 1023 | class function TDECHashAuthentication.KDF1(const Data; DataSize: Integer; const Seed; |
| 1024 | SeedSize, MaskSize: Integer): TBytes; |
| 1025 | begin |
| 1026 | Result := KDFInternal(Data, DataSize, Seed, SeedSize, MaskSize, ktKDF1); |
| 1027 | end; |
| 1028 | |
| 1029 | class function TDECHashAuthentication.KDF1(const Data, Seed: TBytes; |
| 1030 | MaskSize: Integer): TBytes; |
| 1031 | begin |
| 1032 | if (length(Seed) > 0) then |
| 1033 | Result := KDFInternal(Data[0], length(Data), Seed[0], length(Seed), MaskSize, ktKDF1) |
| 1034 | else |
| 1035 | Result := KDFInternal(Data[0], length(Data), NullStr, 0, MaskSize, ktKDF1); |
| 1036 | end; |
| 1037 | |
| 1038 | class function TDECHashAuthentication.KDF2(const Data; DataSize: Integer; const Seed; |
| 1039 | SeedSize, MaskSize: Integer): TBytes; |
| 1040 | begin |
| 1041 | Result := KDFInternal(Data, DataSize, Seed, SeedSize, MaskSize, ktKDF2); |
| 1042 | end; |
| 1043 | |
| 1044 | class function TDECHashAuthentication.KDF2(const Data, Seed: TBytes; |
| 1045 | MaskSize: Integer): TBytes; |
| 1046 | begin |
| 1047 | if (length(Seed) > 0) then |
| 1048 | Result := KDFInternal(Data[0], Length(Data), Seed[0], Length(Seed), MaskSize, ktKDF2) |
| 1049 | else |
| 1050 | Result := KDFInternal(Data[0], Length(Data), NullStr, 0, MaskSize, ktKDF2); |
| 1051 | end; |
| 1052 | |
| 1053 | class function TDECHashAuthentication.KDF3(const Data; DataSize: Integer; |
| 1054 | const Seed; SeedSize, MaskSize: Integer): TBytes; |
| 1055 | begin |
| 1056 | Result := KDFInternal(Data, DataSize, Seed, SeedSize, MaskSize, ktKDF3); |
| 1057 | end; |
| 1058 | |
| 1059 | class function TDECHashAuthentication.KDF3(const Data, Seed: TBytes; |
| 1060 | MaskSize: Integer): TBytes; |
| 1061 | begin |
| 1062 | if (length(Seed) > 0) then |
| 1063 | Result := KDFInternal(Data[0], Length(Data), Seed[0], Length(Seed), MaskSize, ktKDF3) |
| 1064 | else |
| 1065 | Result := KDFInternal(Data[0], Length(Data), NullStr, 0, MaskSize, ktKDF3); |
| 1066 | end; |
| 1067 | |
| 1068 | class function TDECHashAuthentication.KDFx(const Data; DataSize: Integer; |
| 1069 | const Seed; SeedSize, MaskSize: Integer; |
| 1070 | Index: UInt32 = 1): TBytes; |
| 1071 | // DEC's own KDF, even stronger |
| 1072 | var |
| 1073 | I, J : Integer; |
| 1074 | Count : UInt32; |
| 1075 | R : Byte; |
| 1076 | HashInstance : TDECHashAuthentication; |
| 1077 | begin |
| 1078 | Assert(MaskSize >= 0); |
| 1079 | Assert(DataSize >= 0); |
| 1080 | Assert(SeedSize >= 0); |
| 1081 | Assert(DigestSize > 0); |
| 1082 | |
| 1083 | SetLength(Result, MaskSize); |
| 1084 | Index := SwapUInt32(Index); |
| 1085 | |
| 1086 | HashInstance := TDECHashAuthenticationClass(self).Create; |
| 1087 | try |
| 1088 | for I := 0 to MaskSize - 1 do |
| 1089 | begin |
| 1090 | HashInstance.Init; |
| 1091 | |
| 1092 | Count := SwapUInt32(I); |
| 1093 | HashInstance.Calc(Count, SizeOf(Count)); |
| 1094 | HashInstance.Calc(Result[0], I); |
| 1095 | |
| 1096 | HashInstance.Calc(Index, SizeOf(Index)); |
| 1097 | |
| 1098 | Count := SwapUInt32(SeedSize); |
| 1099 | HashInstance.Calc(Count, SizeOf(Count)); |
| 1100 | HashInstance.Calc(Seed, SeedSize); |
| 1101 | |
| 1102 | Count := SwapUInt32(DataSize); |
| 1103 | HashInstance.Calc(Count, SizeOf(Count)); |
| 1104 | HashInstance.Calc(Data, DataSize); |
| 1105 | |
| 1106 | HashInstance.Done; |
| 1107 | |
| 1108 | R := 0; |
| 1109 | |
| 1110 | for J := 0 to DigestSize - 1 do |
| 1111 | R := R xor HashInstance.Digest[J]; |
| 1112 | |
| 1113 | Result[I] := R; |
| 1114 | end; |
| 1115 | finally |
| 1116 | HashInstance.Free; |
| 1117 | end; |
| 1118 | end; |
| 1119 | |
| 1120 | class function TDECHashAuthentication.KDFx(const Data, Seed: TBytes; |
| 1121 | MaskSize: Integer; |
| 1122 | Index: UInt32 = 1): TBytes; |
| 1123 | begin |
| 1124 | if (length(Seed) > 0) then |
| 1125 | Result := KDFx(Data[0], Length(Data), Seed[0], Length(Seed), MaskSize, Index) |
| 1126 | else |
| 1127 | Result := KDFx(Data[0], Length(Data), NullStr, Length(Seed), MaskSize, Index) |
| 1128 | end; |
| 1129 | |
| 1130 | class function TDECHashAuthentication.MGFx(const Data; DataSize, MaskSize: Integer; |
| 1131 | Index: UInt32 = 1): TBytes; |
| 1132 | begin |
| 1133 | Result := KDFx(Data, DataSize, NullStr, 0, MaskSize, Index); |
| 1134 | end; |
| 1135 | |
| 1136 | class function TDECHashAuthentication.MGFx(const Data: TBytes; |
| 1137 | MaskSize: Integer; |
| 1138 | Index: UInt32 = 1): TBytes; |
| 1139 | begin |
| 1140 | Result := KDFx(Data[0], Length(Data), NullStr, 0, MaskSize, Index); |
| 1141 | end; |
| 1142 | |
| 1143 | class function TDECHashAuthentication.HMAC(const Key, Text: RawByteString): TBytes; |
| 1144 | begin |
| 1145 | result := HMAC(BytesOf(Key), BytesOf(Text)); |
| 1146 | end; |
| 1147 | |
| 1148 | class function TDECHashAuthentication.HMAC(const Key, Text: TBytes): TBytes; |
| 1149 | const |
| 1150 | CONST_UINT_OF_0x36 = $3636363636363636; |
| 1151 | CONST_UINT_OF_0x5C = $5C5C5C5C5C5C5C5C; |
| 1152 | var |
| 1153 | HashInstance: TDECHashAuthentication; |
| 1154 | InnerKeyPad, OuterKeyPad: array of Byte; |
| 1155 | I, KeyLength, BlockSize, DigestLength: Integer; |
| 1156 | begin |
| 1157 | HashInstance := TDECHashAuthenticationClass(self).Create; |
| 1158 | try |
| 1159 | BlockSize := HashInstance.BlockSize; // 64 for sha1, ... |
| 1160 | DigestLength := HashInstance.DigestSize; |
| 1161 | KeyLength := Length(Key); |
| 1162 | |
| 1163 | SetLength(InnerKeyPad, BlockSize); |
| 1164 | SetLength(OuterKeyPad, BlockSize); |
| 1165 | |
| 1166 | I := 0; |
| 1167 | |
| 1168 | if KeyLength > BlockSize then |
| 1169 | begin |
| 1170 | Result := HashInstance.CalcBytes(Key); |
| 1171 | KeyLength := DigestLength; |
| 1172 | end |
| 1173 | else |
| 1174 | Result := Key; |
| 1175 | |
| 1176 | while I <= KeyLength - SizeOf(NativeUInt) do |
| 1177 | begin |
| 1178 | PNativeUInt(@InnerKeyPad[I])^ := PNativeUInt(@Result[I])^ xor NativeUInt(CONST_UINT_OF_0x36); |
| 1179 | PNativeUInt(@OuterKeyPad[I])^ := PNativeUInt(@Result[I])^ xor NativeUInt(CONST_UINT_OF_0x5C); |
| 1180 | Inc(I, SizeOf(NativeUInt)); |
| 1181 | end; |
| 1182 | |
| 1183 | while I < KeyLength do |
| 1184 | begin |
| 1185 | InnerKeyPad[I] := Result[I] xor $36; |
| 1186 | OuterKeyPad[I] := Result[I] xor $5C; |
| 1187 | Inc(I); |
| 1188 | end; |
| 1189 | |
| 1190 | while I <= BlockSize - SizeOf(NativeUInt) do |
| 1191 | begin |
| 1192 | PNativeUInt(@InnerKeyPad[I])^ := NativeUInt(CONST_UINT_OF_0x36); |
| 1193 | PNativeUInt(@OuterKeyPad[I])^ := NativeUInt(CONST_UINT_OF_0x5C); |
| 1194 | Inc(I, SizeOf(NativeUInt)); |
| 1195 | end; |
| 1196 | |
| 1197 | while I < BlockSize do |
| 1198 | begin |
| 1199 | InnerKeyPad[I] := $36; |
| 1200 | OuterKeyPad[I] := $5C; |
| 1201 | Inc(I); |
| 1202 | end; |
| 1203 | |
| 1204 | HashInstance.Init; |
| 1205 | HashInstance.Calc(InnerKeyPad[0], BlockSize); |
| 1206 | if Length(Text) > 0 then |
| 1207 | HashInstance.Calc(Text[0], Length(Text)); |
| 1208 | HashInstance.Done; |
| 1209 | Result := HashInstance.DigestAsBytes; |
| 1210 | |
| 1211 | HashInstance.Init; |
| 1212 | HashInstance.Calc(OuterKeyPad[0], BlockSize); |
| 1213 | HashInstance.Calc(Result[0], DigestLength); |
| 1214 | HashInstance.Done; |
| 1215 | |
| 1216 | Result := HashInstance.DigestAsBytes; |
| 1217 | finally |
| 1218 | HashInstance.Free; |
| 1219 | end; |
| 1220 | end; |
| 1221 | |
| 1222 | class function TDECHashAuthentication.PBKDF2(const Password, Salt: TBytes; Iterations: Integer; KeyLength: Integer): TBytes; |
| 1223 | const |
| 1224 | CONST_UINT_OF_0x36 = $3636363636363636; |
| 1225 | CONST_UINT_OF_0x5C = $5C5C5C5C5C5C5C5C; |
| 1226 | var |
| 1227 | Hash: TDECHashAuthentication; |
| 1228 | I, J, C: Integer; |
| 1229 | BlockCount, HashLengthRounded, SaltLength: Integer; |
| 1230 | PassLength, DigestLength, BlockSize: Integer; |
| 1231 | InnerKeyPad, OuterKeyPad: TBytes; |
| 1232 | SaltEx, T, U, TrimmedKey: TBytes; |
| 1233 | begin |
| 1234 | Hash := TDECHashAuthenticationClass(self).Create; |
| 1235 | try |
| 1236 | // Setup needed parameters |
| 1237 | DigestLength := Hash.DigestSize; |
| 1238 | HashLengthRounded := DigestLength - SizeOf(NativeUInt) + 1; |
| 1239 | BlockCount := Trunc((KeyLength + DigestLength - 1) / DigestLength); |
| 1240 | BlockSize := Hash.BlockSize; |
| 1241 | PassLength := Length(Password); |
| 1242 | SaltLength := Length(Salt); |
| 1243 | SaltEx := Salt; |
| 1244 | SetLength(SaltEx, SaltLength + 4); // reserve 4 bytes for INT_32_BE(i) |
| 1245 | SetLength(T, DigestLength); |
| 1246 | |
| 1247 | // Prepare Key for HMAC calculation |
| 1248 | // PrepareKeyForHMAC; |
| 1249 | I := 0; |
| 1250 | if PassLength > BlockSize then |
| 1251 | begin |
| 1252 | TrimmedKey := Hash.CalcBytes(Password); |
| 1253 | PassLength := DigestLength; |
| 1254 | end |
| 1255 | else |
| 1256 | TrimmedKey := Password; |
| 1257 | |
| 1258 | SetLength(InnerKeyPad, BlockSize); |
| 1259 | SetLength(OuterKeyPad, BlockSize); |
| 1260 | while I < PassLength do |
| 1261 | begin |
| 1262 | InnerKeyPad[I] := TrimmedKey[I] xor $36; |
| 1263 | OuterKeyPad[I] := TrimmedKey[I] xor $5C; |
| 1264 | Inc(I); |
| 1265 | end; |
| 1266 | while I < BlockSize do |
| 1267 | begin |
| 1268 | InnerKeyPad[I] := $36; |
| 1269 | OuterKeyPad[I] := $5C; |
| 1270 | Inc(I); |
| 1271 | end; |
| 1272 | |
| 1273 | // Calculate DK |
| 1274 | for I := 1 to BlockCount do |
| 1275 | begin |
| 1276 | SaltEx[SaltLength + 0] := Byte(I shr 24); // INT_32_BE(i) |
| 1277 | SaltEx[SaltLength + 1] := Byte(I shr 16); |
| 1278 | SaltEx[SaltLength + 2] := Byte(I shr 8); |
| 1279 | SaltEx[SaltLength + 3] := Byte(I shr 0); |
| 1280 | FillChar(T[0], DigestLength, 0); // reset Ti / F |
| 1281 | U := SaltEx; // initialize U to U1 = Salt + INT_32_BE(i) |
| 1282 | // Calculate F(Password, Salt, c, i) = U1 ^ U2 ^ ... ^ Uc |
| 1283 | for C := 1 to Iterations do |
| 1284 | begin |
| 1285 | Hash.Init; |
| 1286 | Hash.Calc(InnerKeyPad[0], BlockSize); |
| 1287 | Hash.Calc(U[0], Length(U)); |
| 1288 | Hash.Done; |
| 1289 | U := Hash.DigestAsBytes; |
| 1290 | |
| 1291 | Hash.Init; |
| 1292 | Hash.Calc(OuterKeyPad[0], BlockSize); |
| 1293 | Hash.Calc(U[0], DigestLength); |
| 1294 | Hash.Done; |
| 1295 | U := Hash.DigestAsBytes; // Ui |
| 1296 | // F = U1 ^ U2 ^ ... ^ Uc |
| 1297 | J := 0; |
| 1298 | while J < HashLengthRounded do |
| 1299 | begin |
| 1300 | PNativeUInt(@T[J])^ := PNativeUInt(@T[J])^ xor PNativeUInt(@U[J])^; |
| 1301 | Inc(J, SizeOf(NativeUInt)); |
| 1302 | end; |
| 1303 | while J < DigestLength do |
| 1304 | begin |
| 1305 | T[J] := T[J] xor U[J]; |
| 1306 | Inc(J); |
| 1307 | end; |
| 1308 | end; |
| 1309 | |
| 1310 | {$IF CompilerVersion >= 28.0} |
| 1311 | Result := Result + T; // DK += F , DK = DK || Ti |
| 1312 | {$ELSE} |
| 1313 | TArrHelper.AppendArrays<Byte>(Result, T); |
| 1314 | {$IFEND} |
| 1315 | end; |
| 1316 | finally |
| 1317 | Hash.Free; |
| 1318 | end; |
| 1319 | |
| 1320 | // Trim to the needed key length |
| 1321 | SetLength(Result, KeyLength); |
| 1322 | end; |
| 1323 | |
| 1324 | class function TDECHashAuthentication.PBKDF2(const Password, Salt: RawByteString; Iterations: Integer; KeyLength: Integer): TBytes; |
| 1325 | begin |
| 1326 | result := PBKDF2(BytesOf(Password), BytesOf(Salt), Iterations, KeyLength); |
| 1327 | end; |
| 1328 | |
| 1329 | { TDECHashExtended } |
| 1330 | |
| 1331 | procedure TDECHashExtended.CalcStream(const Stream: TStream; Size: Int64; |
| 1332 | var HashResult: TBytes; const OnProgress:TDECProgressEvent); |
| 1333 | var |
| 1334 | Buffer: TBytes; |
| 1335 | Bytes: Integer; |
| 1336 | Max, Pos: Int64; |
| 1337 | begin |
| 1338 | Assert(Assigned(Stream), 'Stream to calculate hash on is not assigned'); |
| 1339 | |
| 1340 | Max := 0; |
| 1341 | SetLength(HashResult, 0); |
| 1342 | try |
| 1343 | Init; |
| 1344 | |
| 1345 | if StreamBufferSize <= 0 then |
| 1346 | StreamBufferSize := 8192; |
| 1347 | |
| 1348 | Pos := Stream.Position; |
| 1349 | |
| 1350 | if Size < 0 then |
| 1351 | Size := Stream.Size - Pos; |
| 1352 | |
| 1353 | // Last byte is incomplete so it mustn't be processed |
| 1354 | if (FFinalByteLength > 0) then |
| 1355 | Dec(Size); |
| 1356 | |
| 1357 | Max := Pos + Size; |
| 1358 | |
| 1359 | if Assigned(OnProgress) then |
| 1360 | OnProgress(Max, 0, Started); |
| 1361 | |
| 1362 | Bytes := StreamBufferSize mod FBufferSize; |
| 1363 | |
| 1364 | if Bytes = 0 then |
| 1365 | Bytes := StreamBufferSize |
| 1366 | else |
| 1367 | Bytes := StreamBufferSize + FBufferSize - Bytes; |
| 1368 | |
| 1369 | if Bytes > Size then |
| 1370 | SetLength(Buffer, Size) |
| 1371 | else |
| 1372 | SetLength(Buffer, Bytes); |
| 1373 | |
| 1374 | while Size > 0 do |
| 1375 | begin |
| 1376 | Bytes := Length(Buffer); |
| 1377 | if Bytes > Size then |
| 1378 | Bytes := Size; |
| 1379 | Stream.ReadBuffer(Buffer[0], Bytes); |
| 1380 | Calc(Buffer[0], Bytes); |
| 1381 | Dec(Size, Bytes); |
| 1382 | Inc(Pos, Bytes); |
| 1383 | |
| 1384 | if Assigned(OnProgress) then |
| 1385 | OnProgress(Max, Pos, Processing); |
| 1386 | end; |
| 1387 | |
| 1388 | // Last byte is incomplete but algorithm may need its value for padding |
| 1389 | if (FFinalByteLength > 0) then |
| 1390 | Stream.ReadBuffer(FPaddingByte, 1); |
| 1391 | |
| 1392 | Done; |
| 1393 | HashResult := DigestAsBytes; |
| 1394 | finally |
| 1395 | ProtectBytes(Buffer); |
| 1396 | if Assigned(OnProgress) then |
| 1397 | OnProgress(Max, Max, Finished); |
| 1398 | end; |
| 1399 | end; |
| 1400 | |
| 1401 | function TDECHashExtended.CalcStream(const Stream: TStream; Size: Int64; |
| 1402 | Format: TDECFormatClass; const OnProgress:TDECProgressEvent): RawByteString; |
| 1403 | var |
| 1404 | Hash: TBytes; |
| 1405 | begin |
| 1406 | CalcStream(Stream, Size, Hash, OnProgress); |
| 1407 | Result := BytesToRawString(ValidFormat(Format).Encode(Hash)); |
| 1408 | end; |
| 1409 | |
| 1410 | procedure TDECHashExtended.CalcStream(const Stream: TStream; Size: Int64; |
| 1411 | const OnProgress:TDECProgressEvent; |
| 1412 | DoFinalize: Boolean); |
| 1413 | var |
| 1414 | Buffer: TBytes; |
| 1415 | Bytes: Integer; |
| 1416 | Max, Pos: Int64; |
| 1417 | begin |
| 1418 | Assert(Assigned(Stream), 'Stream to calculate hash on is not assigned'); |
| 1419 | |
| 1420 | Max := 0; |
| 1421 | try |
| 1422 | if StreamBufferSize <= 0 then |
| 1423 | StreamBufferSize := 8192; |
| 1424 | |
| 1425 | Pos := Stream.Position; |
| 1426 | |
| 1427 | if Size < 0 then |
| 1428 | Size := Stream.Size - Pos; |
| 1429 | |
| 1430 | // Last byte is incomplete so it mustn't be processed |
| 1431 | if DoFinalize and (FFinalByteLength > 0) then |
| 1432 | Dec(Size); |
| 1433 | |
| 1434 | Max := Pos + Size; |
| 1435 | |
| 1436 | if Assigned(OnProgress) then |
| 1437 | OnProgress(Max, 0, Started); |
| 1438 | |
| 1439 | Bytes := StreamBufferSize mod FBufferSize; |
| 1440 | |
| 1441 | if Bytes = 0 then |
| 1442 | Bytes := StreamBufferSize |
| 1443 | else |
| 1444 | Bytes := StreamBufferSize + FBufferSize - Bytes; |
| 1445 | |
| 1446 | if Bytes > Size then |
| 1447 | SetLength(Buffer, Size) |
| 1448 | else |
| 1449 | SetLength(Buffer, Bytes); |
| 1450 | |
| 1451 | while Size > 0 do |
| 1452 | begin |
| 1453 | Bytes := Length(Buffer); |
| 1454 | if Bytes > Size then |
| 1455 | Bytes := Size; |
| 1456 | Stream.ReadBuffer(Buffer[0], Bytes); |
| 1457 | Calc(Buffer[0], Bytes); |
| 1458 | Dec(Size, Bytes); |
| 1459 | Inc(Pos, Bytes); |
| 1460 | |
| 1461 | if Assigned(OnProgress) then |
| 1462 | OnProgress(Max, Pos, Processing); |
| 1463 | end; |
| 1464 | |
| 1465 | // Last byte is incomplete but algorithm may need its value for padding |
| 1466 | if DoFinalize then |
| 1467 | begin |
| 1468 | if (FFinalByteLength > 0) then |
| 1469 | Stream.ReadBuffer(FPaddingByte, 1); |
| 1470 | Done; |
| 1471 | end; |
| 1472 | finally |
| 1473 | ProtectBytes(Buffer); |
| 1474 | if Assigned(OnProgress) then |
| 1475 | OnProgress(Max, Max, Finished); |
| 1476 | end; |
| 1477 | end; |
| 1478 | |
| 1479 | procedure TDECHashExtended.CalcFile(const FileName: string; var HashResult: TBytes; |
| 1480 | const OnProgress:TDECProgressEvent); |
| 1481 | var |
| 1482 | S: TFileStream; |
| 1483 | begin |
| 1484 | SetLength(HashResult, 0); |
| 1485 | S := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone); |
| 1486 | try |
| 1487 | CalcStream(S, S.Size, HashResult, OnProgress); |
| 1488 | finally |
| 1489 | S.Free; |
| 1490 | end; |
| 1491 | end; |
| 1492 | |
| 1493 | function TDECHashExtended.CalcFile(const FileName: string; Format: TDECFormatClass; |
| 1494 | const OnProgress:TDECProgressEvent): RawByteString; |
| 1495 | var |
| 1496 | Hash: TBytes; |
| 1497 | begin |
| 1498 | CalcFile(FileName, Hash, OnProgress); |
| 1499 | Result := BytesToRawString(ValidFormat(Format).Encode(Hash)); |
| 1500 | end; |
| 1501 | |
| 1502 | { TArrHelper } |
| 1503 | |
| 1504 | {$IF CompilerVersion < 28.0} |
| 1505 | class procedure TArrHelper.AppendArrays<T>(var A: TArray<T>; const B: TArray<T>); |
| 1506 | var |
| 1507 | i, L: Integer; |
| 1508 | begin |
| 1509 | L := Length(A); |
| 1510 | SetLength(A, L + Length(B)); |
| 1511 | for i := 0 to High(B) do |
| 1512 | A[L + i] := B[i]; |
| 1513 | end; |
| 1514 | {$IFEND} |
| 1515 | |
| 1516 | { TDECPasswordHash } |
| 1517 | |
| 1518 | function TDECPasswordHash.GetSalt: TBytes; |
| 1519 | begin |
| 1520 | Result := FSalt; |
| 1521 | end; |
| 1522 | |
| 1523 | procedure TDECPasswordHash.SetSalt(const Value: TBytes); |
| 1524 | begin |
| 1525 | if (Length(Value) > MaxSaltLength) then |
| 1526 | raise EDECHashException.CreateFmt(sSaltValueTooLong, [MaxSaltLength]); |
| 1527 | |
| 1528 | if (Length(Value) < MinSaltLength) then |
| 1529 | raise EDECHashException.CreateFmt(sSaltValueTooShort, [MinSaltLength]); |
| 1530 | |
| 1531 | FSalt := Value; |
| 1532 | end; |
| 1533 | |
| 1534 | class function TDECPasswordHash.GetCryptID: string; |
| 1535 | begin |
| 1536 | Result := ''; |
| 1537 | end; |
| 1538 | |
| 1539 | function TDECPasswordHash.GetCryptParams(const Params : string; |
| 1540 | Format : TDECFormatClass): string; |
| 1541 | begin |
| 1542 | Result := ''; |
| 1543 | end; |
| 1544 | |
| 1545 | function TDECPasswordHash.GetCryptSalt(const Salt : TBytes; |
| 1546 | Format : TDECFormatCLass): string; |
| 1547 | var |
| 1548 | FormattedSalt : TBytes; |
| 1549 | begin |
| 1550 | FormattedSalt := Format.Encode(Salt); |
| 1551 | |
| 1552 | Result := '$' + TEncoding.ASCII.GetString(FormattedSalt); |
| 1553 | end; |
| 1554 | |
| 1555 | class function TDECPasswordHash.ClassByCryptIdentity( |
| 1556 | Identity: string): TDECPasswordHashClass; |
| 1557 | var |
| 1558 | ClassEntry : TClassListEntry; |
| 1559 | IDLower : string; |
| 1560 | begin |
| 1561 | IDLower := Identity.ToLower; |
| 1562 | if not IDLower.StartsWith('$') then |
| 1563 | IDLower := '$' + IDLower; |
| 1564 | |
| 1565 | for ClassEntry in ClassList do |
| 1566 | begin |
| 1567 | if TDECHashClass(ClassEntry.Value).IsPasswordHash and |
| 1568 | (string(TDECPasswordHashClass(ClassEntry.Value).GetCryptID).ToLower = IDLower) then |
| 1569 | begin |
| 1570 | Result := TDECPasswordHashClass(ClassEntry.Value); |
| 1571 | Exit; |
| 1572 | end; |
| 1573 | end; |
| 1574 | |
| 1575 | // If we got this far, we have not found any mathich class |
| 1576 | raise EDECClassNotRegisteredException.CreateResFmt(@sCryptIDNotRegistered, |
| 1577 | [Identity]); |
| 1578 | end; |
| 1579 | |
| 1580 | procedure TDECPasswordHash.DoDone; |
| 1581 | begin |
| 1582 | inherited; |
| 1583 | |
| 1584 | ProtectBuffer(FSalt[0], SizeOf(FSalt)); |
| 1585 | SetLength(FSalt, 0); |
| 1586 | end; |
| 1587 | |
| 1588 | function TDECPasswordHash.GetCryptHash(Password : TBytes; |
| 1589 | const Params : string; |
| 1590 | const Salt : TBytes; |
| 1591 | Format : TDECFormatClass): string; |
| 1592 | begin |
| 1593 | Result := ''; |
| 1594 | end; |
| 1595 | |
| 1596 | function TDECPasswordHash.GetDigestInCryptFormat( |
| 1597 | const Password : string; |
| 1598 | const Params : string; |
| 1599 | const Salt : string; |
| 1600 | SaltIsRaw : Boolean; |
| 1601 | Format : TDECFormatClass): string; |
| 1602 | begin |
| 1603 | Result := GetDigestInCryptFormat(TEncoding.UTF8.GetBytes(Password), |
| 1604 | Params, |
| 1605 | Salt, |
| 1606 | SaltIsRaw, |
| 1607 | Format); |
| 1608 | end; |
| 1609 | |
| 1610 | function TDECPasswordHash.GetDigestInCryptFormat( |
| 1611 | Password : TBytes; |
| 1612 | const Params : string; |
| 1613 | const Salt : string; |
| 1614 | SaltIsRaw : Boolean; |
| 1615 | Format : TDECFormatClass): string; |
| 1616 | var |
| 1617 | SaltBytes : TBytes; |
| 1618 | begin |
| 1619 | // generic format used by Crypt, but not every algorithm sticks 100% to it |
| 1620 | // $<id>[$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]] |
| 1621 | |
| 1622 | // if no ID is delivered the algorithm is none of the Crypt/BSD algorithms |
| 1623 | Result := GetCryptID; |
| 1624 | if (Result <> '') then |
| 1625 | begin |
| 1626 | if SaltIsRaw then |
| 1627 | SaltBytes := TEncoding.UTF8.GetBytes(Salt) |
| 1628 | else |
| 1629 | SaltBytes := Format.Decode(TEncoding.UTF8.GetBytes(Salt)); |
| 1630 | |
| 1631 | Result := Result + GetCryptParams(Params, Format) + |
| 1632 | GetCryptSalt(SaltBytes, Format) + |
| 1633 | GetCryptHash(Password, Params, SaltBytes, Format); |
| 1634 | end; |
| 1635 | end; |
| 1636 | |
| 1637 | function TDECPasswordHash.IsValidPassword(const Password : string; |
| 1638 | const CryptData : string; |
| 1639 | Format : TDECFormatClass): Boolean; |
| 1640 | begin |
| 1641 | Result := IsValidPassword(TEncoding.UTF8.GetBytes(Password), |
| 1642 | CryptData, |
| 1643 | Format); |
| 1644 | end; |
| 1645 | |
| 1646 | function TDECPasswordHash.IsValidPassword(Password : TBytes; |
| 1647 | const CryptData : string; |
| 1648 | Format : TDECFormatClass): Boolean; |
| 1649 | begin |
| 1650 | Result := false; |
| 1651 | end; |
| 1652 | |
| 1653 | end. |


Accompanying package to the book
Quantitative Risk Management: Concepts, Techniques and Tools by
Alexander J. McNeil, Rüdiger Frey, and Paul Embrechts.
| Version: |
0.4-13 |
| Depends: |
R (≥ 3.0.1), gsl, Matrix, mvtnorm, numDeriv, timeSeries |
| Imports: |
Rcpp (≥ 0.11.1), mgcv, methods, timeDate |
| LinkingTo: |
Rcpp |
| Published: |
2016-03-18 |
| Author: |
Bernhard Pfaff [aut, cre],
Marius Hofert [ctb],
Alexander McNeil [aut] (S-Plus original (QRMlib)),
Scott Ulmann [trl] (First R port as package QRMlib) |
| Maintainer: |
Bernhard Pfaff <bernhard at pfaffikus.de> |
| License: |
GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
| NeedsCompilation: |
yes |
| In views: |
Distributions, ExtremeValue |
| CRAN checks: |
QRM results |


Purchase Form
Home
Purchase
Account
Shipping
First Name
Last Name
Address
Address 2
City
State
Choose...
...
Zip
Billing
First Name
Last Name
Address
Address 2
City
State
Choose...
...
Zip
Payment
Diner's Club
Visa
Mastercard
Name
Card Number
Zip
CC
Purchase


{{ define "content" }} Donate your stockpiled masks, gloves, and other equipment to hospitals to fight covid19 I have equipment to donate I am hospital staff


I have worked with Python, C++ and MATLAB in my computational neuroscience research work for over 3 years in order to develop software and perform statistical analysis. I have taught myself SQL Server in the past to work on database development.
I am currently working on curriculum from FreeCodeCamp to become a full-stack developer. I am very excited and want to learn more about the coding. I am learning numerous scripting techniques and have worked on many front-end projects at FCC. These projects are displayed below in my project section. If you would like me to work on your project or just want to discuss anything else, you can reach me via one of the links in the contact section. Enjoy!


Installation¶
Clone the repository:
$ git clone https://github.com/LoreDema/ValidPy.git
then install it using pip (Linux):
$ pip install -e ./ValidPy
Dependencies¶
- simplejson 3.3.1
- NumPy 1.9.2
- PyBrain 0.3
- SciPy 0.13.3
- matplotlib 1.3.1
- scikit-learn 0.15.2
Quick Start¶
This tool implement K-cross validation for both ANN and SVM.
For all the experiments you need a csv file comma ”,” separated. This file have to be 3 columns, each row is:
id, input_x, output_y
ANN k-cross validation¶
To perform a k-cross validation over a file you need to create a configuration JSON like this:
{ "grid":"true", "k":8, "parallel_process":4, "data_file":"absolute_path_to_data_file.csv", "out_folder":"absolute_path_output_folder", "input_length": 10, "output_length": 2, "hidden_layers":[1,2,3], "units":[15,25], "function":["sigmoid","gaussian"], "momentum":[0.0,0.9], "learning_rate":[0.01,0.05], "lr_decay":[1.0, 0.9999] }
Then you have to run ann_kcross.sh in executable/ giving the path to the configuration JSON as parameter:
$ cd ./ValidPy/executable/ $ sh ann_kcross.sh path_to_config_JSON
The script will produce a csv file containing for each combination of the parameters the average training time and the average average euclidean distance (computed on the validation set outputs) over the k experiments. It also produce for each combination a folder with the single experiments details and models.
SVM k-cross validation¶
To perform a k-cross validation over a file you need to create a configuration JSON like this:
{ "grid":"true", "k":8, "parallel_process":4, "data_file":"absolute_path_to_data_file.csv", "out_folder":"absolute_path_output_folder", "input_length": 10, "output_length": 2, "kernel":["linear", "poly", "rbf", "sigmoid"], "C":[0.1, 1.0, 10, 100], "epsilon":[0.01,0.05, 0.1, 0.5, 1, 5], "degree":[3] }
Then you have to run svm_kcross.sh in executable/ giving the path to the configuration JSON as parameter:
$ cd ./ValidPy/executable/ $ sh svm_kcross.sh path_to_config_JSON
The script will produce a csv file containing for each combination of the parameters the average training time and the average average euclidean distance (computed on the validation set outputs) over the k experiments. It also produce for each combination a folder with the single experiments details and models.
ANN vs SVM k-cross validation¶
To perform a k-cross validation over a file you need to create a configuration JSON like this, you can choose how many time to repeat the experiment setting the experiments parameter:
{ "experiments":4, "k":8, "parallel_process":4, "data_file":"absolute_path_to_data_file.csv", "out_folder":"absolute_path_output_folder", "input_length": 10, "output_length": 2, "ANN": { "hidden_layers":2, "units":25, "function":"sigmoid", "momentum":0.0, "learning_rate":0.05, "lr_decay":0.9999 }, "SVM": { "kernel":"rbf", "C":30, "epsilon":0.1, "degree":3 } }
Then you have to run ann_vs_svm_kcross.sh in executable/ giving the path to the configuration JSON as parameter:
$ cd ./ValidPy/executable/ $ sh ann_vs_svm_kcross.sh path_to_config_JSON
The script will produce a csv file containing for each experiment the average training time, the average average euclidean distance over the k experiments, the total average average training time and the total average average euclidean distance(computed on the validation set outputs). It also produce for each experiment a folder with the single experiment details and models.
ANN test¶
To perform a test you need to create a configuration JSON like this:
{ "training_set":"absolute_path_to_training_set_file.csv", "test_set":"absolute_path_to_test_set_file.csv", "out_folder":"absolute_path_output_folder", "input_length": 10, "output_length": 2, "hidden_layers":2, "valid_prop":0.1, "units":25, "function":"sigmoid", "momentum":0.0, "learning_rate":0.05, "lr_decay":0.9999 }
Then you have to run ann_test.sh in executable/ giving the path to the configuration JSON as parameter:
$ cd ./ValidPy/executable/ $ sh ann_test.sh path_to_config_JSON
The script will produce a txt file containing the training time and the average euclidean distance over the test set outputs and the experiment models.
SVM test¶
To perform a test you need to create a configuration JSON like this:
{ "training_set":"absolute_path_to_training_set_file.csv", "test_set":"absolute_path_to_test_set_file.csv", "out_folder":"absolute_path_output_folder", "input_length": 10, "output_length": 2, "kernel":"rbf", "C":30, "epsilon":0.1, "degree":3 }
Then you have to run svm_test.sh in executable/ giving the path to the configuration JSON as parameter:
$ cd ./ValidPy/executable/ $ sh svm_test.sh path_to_config_JSON
The script will produce a txt file containing the training time and the average euclidean distance over the test set outputs and the experiment models.
SVM predict¶
To predict over a blind set you need a csv file comma ”,” separated. This file have to be 2 columns, each row is:
id, input_x
- You have to create a configuration JSON like this:
{ "training_set":"absolute_path_to_training_set_file.csv", "test_set":"absolute_path_to_test_set_file.csv", "out_folder":"absolute_path_output_folder", "out_file":"absolute_path_output_file.csv", "input_length": 10, "output_length": 2, "kernel":"rbf", "C":10, "epsilon":0.1, "degree":3 }
Then you have to run svm_train.sh in executable/ giving the path to the configuration JSON as parameter:
$ cd ./ValidPy/executable/ $ sh svm_train.sh path_to_config_JSON
The script will produce for each output a model.
Then you have to run svm_predict.sh in executable/ giving the path to the configuration JSON as parameter:code-block:
$ cd ./ValidPy/executable/ $ sh svm_predict.sh path_to_config_JSON
The script will produce a csv file containing 3 columns, each row is:
id, input_x, output_y
ANN predict¶
Not already implemented.


Answer the questions below and we will determine which language is best for you!
Based on your answers, our very scientific process has discovered that... is the best language for you.


Us Donuts
Menu
About
Contact
Order
Location
☰
Fields marked with * are mandatory
Name *
Email *
Contact number *
Contact person *
Order products
Product
Qty
Sub total
{{ product.title }}
{{ options.name }} - ${{ options.price }}
${{ sumRows(product.variation) }}
No products for your search "{{ searchName }}"
Order Summary
Product name
Qty
Price
{{ product.title }}
{{ variation.name + ' x ' + variation.quantity }},
${{ sumRows(product.variation) }}
Please select products on the left
Total: ${{ sumSelectedProducts() }}
Submit Order


The Internet Reacts to the Announcement of a New Half-Life Game
by Nathan GraysonIt is 2019. Valve just announced a new Half-Life game. All bets are off now. Quit your job. Buy a lottery ticket. Fail to win the lottery. Buy several more lottery tickets. Fail again. Give up. Sell your car so you can make rent. Go online. Find out that the new Half-Life is a VR game. Compose an irate tweet about how you can’t afford it. Live your dreams.
Half-Life: Alyx, announced yesterday by Valve in what still feels like an impossible fever dream but was actually just a post on Twitter, is set to be the company’s “flagship VR game.” This has left fans in an odd spot. On one hand, it’s more Half-Life. Finally! After more than a decade of waiting. On the other hand, it’s not Half-Life 3, and on top of that, it’s a VR game, meaning it’ll require an expensive headset and a powerful PC. While it makes sense that Valve would want to create a killer app for its Valve Index VR platform, it’s still been a bitter pill to swallow for some of the Half-Life series’ vocal fans. Here’s what they’re saying:
Image: Tumblr
Image: Tumblr
Image: Tumblr
Image: Tumblr


--- date: 2011-03-03T00:00:00Z published: true title: The Charlie Sheen Glossary - ‘Winning,’ Warlocks, and More -- Vulture' url: /2011/03/03/the-charlie-sheen-glossary-winning-warlocks-and-more-vulture/ ---
Charlie Sheen
proper noun, verb, Sheened, Sheening
1. the actor whose erratic behavior may have cost him his lucrative job as a sitcom lead
2. the perfectly legal, yet dangerous substance that said actor claims to use recreationally, e.g., "I'm on a drug. It's called Charlie Sheen. It's not available. If you try it once, you will die"
3. the act of behaving in a manner akin to this actor, as in Trey Parker and Matt Stone telling David Letterman that they were "Sheening pretty hard" when they cross-dressed at the Oscars


Close Close Close Close


TODO list
Todo
Buy a hat for the bat
Clear the fog for the frogs
Bring a box to the fox
Done
Put the mitterns on the kittens


NHRangeSliderView
open class NHRangeSliderView: UIView
Range slider with labels for upper and lower thumbs, title label and configurable step value (optional)
-
Undocumented
Declaration
Swift
open class NHRangeSliderView: UIView
-
Range slider
Declaration
Swift
open var rangeSlider : NHRangeSlider? = nil
-
Display title
Declaration
Swift
open var titleLabel : UILabel? = nil
-
Undocumented
Declaration
Swift
open class NHRangeSliderView: UIView
-
upper value label for displaying selected upper value
Declaration
Swift
open var upperLabel : UILabel? = nil
-
display format for lower value. Default to %.0f to display value as Int
Declaration
Swift
open var lowerDisplayStringFormat: String = "%.0f"
-
display format for upper value. Default to %.0f to display value as Int
Declaration
Swift
open var upperDisplayStringFormat: String = "%.0f"
-
vertical spacing
Declaration
Swift
open var spacing: CGFloat = 4.0
-
position of thumb labels. Set to STICKY to stick to left and right positions. Set to FOLLOW to follow left and right thumbs
Declaration
Swift
open var thumbLabelStyle: NHSliderLabelStyle = .STICKY
-
minimum value
Declaration
Swift
@IBInspectable open var minimumValue: Double = 0.0
-
max value
Declaration
Swift
@IBInspectable open var maximumValue: Double = 100.0
-
value for lower thumb
Declaration
Swift
@IBInspectable open var lowerValue: Double = 0.0
-
value for upper thumb
Declaration
Swift
@IBInspectable open var upperValue: Double = 100.0
-
stepValue. If set, will snap to discrete step points along the slider . Default to nil
Declaration
Swift
@IBInspectable open var stepValue: Double? = nil
-
minimum distance between the upper and lower thumbs.
Declaration
Swift
open var gapBetweenThumbs: Double = 2.0
-
tint color for track between 2 thumbs
Declaration
Swift
@IBInspectable open var trackTintColor: UIColor = UIColor(white: 0.9, alpha: 1.0)
-
track highlight tint color
Declaration
Swift
@IBInspectable open var trackHighlightTintColor: UIColor = UIColor(red: 0.0, green: 0.45, blue: 0.94, alpha: 1.0)
-
thumb tint color
Declaration
Swift
@IBInspectable open var thumbTintColor: UIColor = UIColor.white
-
thumb border color
Declaration
Swift
@IBInspectable open var thumbBorderColor: UIColor = UIColor.gray
-
thumb border width
Declaration
Swift
@IBInspectable open var thumbBorderWidth: CGFloat = 0.5
-
set 0.0 for square thumbs to 1.0 for circle thumbs
Declaration
Swift
@IBInspectable open var curvaceousness: CGFloat = 1.0
-
thumb width and height
Declaration
Swift
@IBInspectable open var thumbSize: CGFloat = 32.0
-
Undocumented
Declaration
Swift
open class NHRangeSliderView: UIView
-
Undocumented
Declaration
Swift
open class NHRangeSliderView: UIView
-
setup
Declaration
Swift
open func setup()
-
Range slider change events. Upper / lower labels will be updated accordingly. Selected value for filterItem will also be updated
Parameter
Parameter rangeSlider: the changed rangeSliderDeclaration
Swift
open func rangeSliderValueChanged(_ rangeSlider: NHRangeSlider)
Parameters
rangeSlider
the changed rangeSlider
-
Undocumented
Declaration
Swift
open class NHRangeSliderView: UIView
-
layout subviews
Declaration
Swift
override open func layoutSubviews()
-
Undocumented
Declaration
Swift
open class NHRangeSliderView: UIView


To only show ACT sites: https://wheretofly.info/wtf.html?sites=binalong+collector+gearys_gap+pig_hill_e+pig_hill_n+spring_hill
To sort by site: https://wheretofly.info/?sortbysite=true
2018-02-15 Added Show Distance option. 2017-12-28 Added Hide Early/Late values option. 2017-11-20 Added Paraglider option. 2017-06-30 Added Info page. 2017-06-30 Fixed Ocean Grove URLs. 2017-06-25 Added OBS URL for Blackheath. 2017-06-09 Updated ACT OBS URLs. 2017-05-29 Added OBS URL to Ben Nevis. 2017-05-27 Added Potters Road, Fisher Street, Grossard Point and Rhyll. 2017-04-24 Added Tongarra and Cambewarra. 2017-04-15 Updated to v8. 2017-04-15 Added access-log to package.json. 2017-04-15 Updated README.md for title option. 2017-04-14 We now log requests to run/access.log. This needs to be a rw mount now. 2017-04-14 The title can now be set in the sites.json file. 2017-04-14 Added Landscape. 2017-03-18 First cut.


[gecode-users] Gist in bab or restart search, abnormal exit in red nodes
Guido Tack
tack at gecode.org
Tue Jul 6 07:56:13 CEST 2010
Claudio Cesar de Sá wrote:
> Hi
>
> Thanks, really it was the problem ... I fix it with a try ... catch, once
> that I want a formatted output ... so the code is such like:
>
> ...................................................
> try
> {
>
> for (int i = 0; i < mat_size; i++) {
> os << "\n" << i << "|" ;
> for (int j = 0; j < mat_size; j++) {
> os.width(1);
> //os << matrix(i,j) << " ";
> if ( matrix(i,j).val() == 1 )
> os << j << " ";
> else
> os << "_" << " ";
> }
> }
> So, now in blue and red nodes .... the gist's message is:
>
> BoolVar::val: Attempt to access value of unassigned variable PRINT OUTPUT: NON DEFINITION for MATRIX YET
>
>
> Is there any alternative or better for this solution? Is there any function to check if all the values of a variable are already instancied/assigned? In this case, the variable is a matrix.
You have to iterate over the whole matrix to determine if it is assigned. Or you change your output, like this (assuming the matrix is over BoolVars):
if (matrix(i,j).one()) os << j << " "; else if (matrix(i,j).zero()) os << "_ "; else os << "? ";
Cheers,
Guido
--
Guido Tack, http://people.cs.kuleuven.be/~guido.tack/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20100706/a4e22d79/attachment.htm>
More information about the users
mailing list


--- layout: api title: "v3.2.1 JavaScript Library: Global Switches" categories: api version: v3.2.1 permalink: /api/v3.2.1/l-global/ ---
Global switches are created for rare cases and generally make Leaflet to not detect a particular browser feature even if it's there. You need to set the switch as a global variable to true
before including Leaflet on the page, like this:
<script>L_PREFER_CANVAS = true;</script>
<script src="leaflet.js"></script>
| Switch | Description |
|---|---|
L_PREFER_CANVAS |
Forces Leaflet to use the Canvas back-end (if available) for vector layers instead of SVG. This can increase performance considerably in some cases (e.g. many thousands of circle markers on the map). |
L_NO_TOUCH |
Forces Leaflet to not use touch events even if it detects them. |
L_DISABLE_3D |
Forces Leaflet to not use hardware-accelerated CSS 3D transforms for positioning (which may cause glitches in some rare environments) even if they're supported. |


{% img right http://www.gravatar.com/avatar/f8ee60f3cb8ecc91f41ee093542e12f4?s=60 %} Jeremy is a PHP developer, a public speaker, a sometime open source contributor, and an amateur photographer. He is currently working for Alegion as a Senior Software Engineer and resides in Austin, TX.


Hello , how are you today?
This is your account balance:
Would you like to make a transaction?
Recent Transactions:


Provides classes and interfaces to handle text.
double
)
equivalent to standard String/Double methods?
With Javolution 4.1, double
formatting/parsing is lossless
and functionally the same as with the standard library. Parsing a character
sequence will always result in the same number whether it is performed with
{@link javolution.text.TypeFormat TypeFormat} or using Double.parseDouble(String))
.
When formatting a double
number, the number of digits output
is adjustable. The default (if the number of digits is unspecified) is 17
or 16
when the the 16 digits representation can be parsed back to
the same double
(mimic the standard library formatting).
 Better, it does not force the user to create intermediate String
objects, any CharSequence/Appendable
can be used! Serial parsing is also supported
(cursor parameter).
It all depends of the size of the text to append (the actual size of the document being appended has almost no impact in both cases).
If the text being appended is large (or arbitrarily large) then using {@link javolution.text.Text Text} is preferable.[code] class FastCollection { public final Text toText() { // We don't know the length of the text representation for // the collection's elements, we use Text concatenation // to avoid copying what could be quite large. Text text = Text.valueOf("{"); for (Record r = head(), end = tail(); (r = r.getNext()) != end;) { text = text.plus(valueOf(r)); if (r.getNext() != end) { text = text.plus(", "); } } return text.plus("}"); } }[/code] When appending small text (e.g. < 20 characters) then {@link javolution.text.TextBuilder TextBuilder} works faster. class Complex { double real, imaginary; public Text toText() { TextBuilder tmp = TextBuilder.newInstance(); try { tmp.append(real).append(" + ").append(imaginary).append("i"); return tmp.toText(); } finally { TextBuilder.recycle(tmp); } } }[/code]
"/proj/lodecase/src/com/lodecase/util/foo.java"
, and
"/proj/lodecase/src/com/lodecase/util/bar.java"
.
Can the 'Text' class save us memory when strings
have common prefixes?
It depends how you build your text. For example in following code:[code]
Text directoryName = Text.valueOf("/proj/lodecase/src/com/lodecase/util/");
Text fooFileName = directoryName.plus("foo.java");
Text barFileName = directoryName.plus("bar.java");[/code]
The prefix (directoryName)is shared between fooFileName
and barFileName
.
Text is a binary tree of blocks of characters. In the example,
above, fooFileName
is a node with directoryName
for
head and "foo.java" for tail. The tree is maintained balanced automatically
through tree rotations.


High Priestess Levian:
To become a Cleric, one who serves Einhasad and lives to do her will, your level must be at least 20, and you must also pass the Test of the Cleric.
Description of a Cleric
Change profession to a Cleric
Return


Please Note: This CSS will be added as a style tag in the head section of the document.
To use pre-defined templates, please visit this
link.
To serve high quality icons for the bookmarks, I have deployed a favicon fetcher service deployed on heroku. In case you wish to host it yourself, please follow the instructions provided in the favicon fetcher service and replace the domain in the text box below.


According to Sun EJB specifications, the enterprise bean must not attempt to use the subclass and object substitution features of the Java Serialization Protocol.
Allowing the enterprise bean to use these functions could compromise security.


Tcl/Tk Keywords - S
- safe
-
Tk_Init
- safe
interpreter
-
safe, loadTk
- safe interpreter
-
interp, load
- scalar
-
SetVar
- scale
-
scale
- scan
-
binary, scan
- screen
-
winfo, CrtWindow, GetVisual, WindowId
- screen distance
-
SetOptions
- screen units
-
GetPixels
- script
-
eval, fileevent, source, time, Eval, BindTable
- script file
-
tclsh
- scrollbar
-
scrollbar, GetScroll
- scrolling command
-
GetScroll
- search
-
array, lsearch, Hash
- security
-
send
- security policy
-
http
- seek
-
seek, OpenFileChnl
- seeking
-
tell
- selection
-
chooseDirectory, clipboard, selection, CanvTkwin, CanvTxtInfo, ClrSelect, CrtItemType, CrtSelHdlr
- selection anchor
-
CanvTxtInfo
- selection owner
-
OwnSelect
- selection retrieval
-
GetSelect
- send
-
send, tk
- send command
-
SetAppName
- separator
-
join
- serial
-
open
- server
-
OpenTcp
- service mode
-
Notifier
- set
-
lset, SetVar
- shadow
-
3DBorder
- shared library
-
load
- shell
-
tclsh, wish
- signal
-
Async
- signal numbers
-
Signal
- signals
-
Signal
- size
-
grid, pack, wm
- slave
-
place, CrtSlave, MaintGeom
- slave interpreter
-
interp, safe, loadTk
- sleep
-
after, Sleep
- slider
-
scale
- socket
-
http, socket
- sort
-
lsort
- source
-
safe, loadTk
- spinbox
-
spinbox
- split
-
split, SplitList, SplitPath
- sprintf
-
format
- stack
-
AddErrInfo
- stack frame
-
uplevel
- stacking order
-
lower, raise, Restack
- standard channel
-
GetStdChan
- standard channels
-
StdChannels
- standard error
-
GetStdChan
- standard input
-
GetStdChan
- standard option
-
options
- standard output
-
GetStdChan
- stat
-
file, Access
- stat access filesystem vfs
-
FileSystem
- state
-
SaveResult
- static linking
-
StaticPkg
- stipple
-
CanvPsY
- storage
-
Preserve
- string
-
format, lsearch, re_syntax, regexp, split, string, ExprLong, ExprLongObj, LinkVar, PrintDbl, RegExp, StrMatch, GetJustify, GetRelief
- string object
-
StringObj
- string representation
-
BoolObj, DoubleObj, IntObj, ListObj, Object, ObjectType, StringObj
- string type
-
StringObj
- strings
-
Concat, SplitList
- stubs
-
InitStubs, TkInitStubs
- subexpression
-
RegExp
- sublist
-
lrange
- subprocess
-
exec, tclvars
- substitute
-
regsub
- substitution
-
format
- switch
-
switch, options
- synonym
-
ConfigWidg, SetOptions
Copyright © 1989-1994 The Regents of the University of California.
Copyright © 1990-1994 The Regents of the University of California
Copyright © 1992-1999 Karl Lehenbauer and Mark Diekhans
Copyright © 1992-1999 Karl Lehenbauer and Mark Diekhans.
Copyright © 1993-1997 Bell Labs Innovations for Lucent Technologies
Copyright © 1994 The Australian National University
Copyright © 1994-2000 Sun Microsystems, Inc.
Copyright © 1997-2000 Ajuba Solutions.
Copyright © 1997-2000 Scriptics Corporation.
Copyright © 1998 Mark Harrison.
Copyright © 1998-1999 Scriptics Corporation
Copyright © 1998-2000 Ajuba Solutions
Copyright © 1999 Scriptics Corportation
Copyright © 2000 Jeffrey Hobbs.
Copyright © 2001 ActiveState Tool Corp.
Copyright © 2001 Kevin B. Kenny.
Copyright © 2001 Vincent Darley
Copyright © 2001-2002 ActiveState Corporation
Copyright © 2001-2002 Donal K. Fellows
Copyright © 2001-2002 Kevin B. Kenny. All rights reserved.
Copyright © 2001-2004 ActiveState Corporation.
Copyright © 2006-2007 Daniel A. Steffen
Copyright © 1995-1997 Roger E. Critchlow Jr.