1#!/usr/bin/env perl 2 3## 4## Author......: See docs/credits.txt 5## License.....: MIT 6## 7 8use strict; 9use warnings; 10 11use Digest::SHA qw (sha256); 12use MIME::Base64; 13 14sub module_constraints { [[0, 256], [0, 16], [-1, -1], [-1, -1], [-1, -1]] } 15 16sub module_generate_hash 17{ 18 my ($word, $salt, $iter) = @_; 19 20 return unless defined $word; 21 return unless defined $salt; 22 23 $iter //= 1000; 24 25 my $digest = sha256 ($salt . $word); 26 27 for (my $i = 1; $i < $iter; $i++) 28 { 29 $digest = sha256 ($digest); 30 } 31 32 chomp ($digest = encode_base64 ($digest)); 33 34 my $hash = sprintf ("otm_sha256:%d:%s:%s", $iter, $salt, $digest); 35 36 return $hash; 37} 38 39sub module_verify_hash 40{ 41 my $line = shift; 42 43 my ($sig, $iter, $salt, $hash, $word) = split (':', $line); 44 45 return unless defined $iter; 46 return unless defined $salt; 47 return unless defined $word; 48 49 my $new_hash = module_generate_hash ($word, $salt, $iter); 50 51 return ($new_hash, $word); 52} 53 541; 55