Created
May 7, 2015 05:50
-
-
Save brianddk/edf191c62fe5cee44c63 to your computer and use it in GitHub Desktop.
Encoding depth of various RSA algorithms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function rsa_enc($pad, $bits, $bytes) | |
| { | |
| $in = "filein\rand_${bytes}.bin" | |
| $inkey = "keyin\rsa_${bits}_priv.pem" | |
| while ( -not ((Test-Path $in) -and (Test-Path $inkey)) ) | |
| { | |
| Write-Host "Waiting...." | |
| Start-Sleep -Seconds 10 | |
| } | |
| openssl rsautl -in $in -encrypt -$pad -inkey $inkey *>&1 | Out-Null | |
| $rc = $LASTEXITCODE | |
| $msg = "Pad: $pad; Bits: $bits; Bytes: $bytes; RC: $rc" | |
| if($rc) { Write-Host $msg} | |
| else { Write-Host $msg} | |
| return $rc | |
| } | |
| function bits_bytes_lt_max($hash, $max) | |
| { | |
| $rtn = $true | |
| foreach ($k in $hash.Keys.GetEnumerator()) | |
| { | |
| foreach ($sk in $hash[$k].Keys.GetEnumerator()) | |
| { | |
| $rtn = $rtn -and $hash[$k][$sk] -lt $max | |
| } | |
| } | |
| return $rtn | |
| } | |
| function enc_main() | |
| { | |
| $j = 0 | |
| $i = 85 | |
| $max = 8192 | |
| $h = @{"pkcs" = @{"bits" = $i; "bytes" = $j; "chars" = 0}; | |
| "oaep" = @{"bits" = $i; "bytes" = $j; "chars" = 0}} | |
| #"ssl" = @{"bits" = $i; "bytes" = $j}} | |
| do | |
| { | |
| foreach ($pad in $h.Keys.GetEnumerator()) | |
| { | |
| $i = $h[$pad]["bits"] + 1 | |
| $j = $h[$pad]["bytes"] + 1 | |
| $i-- | |
| do | |
| { | |
| $i++ | |
| #Write-Host "openssl rsautl -in filein\rand_${j}.bin -encrypt -inkey keyin\rsa_${i}_priv.pem *>&1 | Out-Null" | |
| $rc = rsa_enc $pad $i $j | |
| } | |
| while ($rc) | |
| $h[$pad]["bits"] = [int] $i | |
| $h[$pad]["bytes"] = [int] $j | |
| $h[$pad]["chars"] = [int] $c | |
| $c = (openssl rsautl -in filein\rand_${j}.bin -encrypt -$pad -inkey keyin\rsa_${i}_priv.pem 2>$null | wc -c) | |
| do | |
| { | |
| $i++ | |
| #Write-Host "openssl rsautl -in filein\rand_${j}.bin -encrypt -inkey keyin\rsa_${i}_priv.pem *>&1 | Out-Null" | |
| $last = (openssl rsautl -in filein\rand_${j}.bin -encrypt -$pad -inkey keyin\rsa_${i}_priv.pem 2>$null | wc -c) | |
| $x = $last - 2 | |
| Write-Host "Bits:`t$i`tBytes:`t$j`tChars:`t$x" | |
| } | |
| while ($c -eq $last) | |
| $i-- | |
| $x = $c - 2 | |
| $msg = "Bits:`t$i`nBytes:`t$j`nChars:`t$x`n" | |
| $msg | Set-Content encout\enc_${pad}_bi_${i}_by_${j}_ch_${x}.txt -Encoding ascii | |
| Write-Host $msg | |
| } | |
| } | |
| while(bits_bytes_lt_max $h $max) | |
| } | |
| enc_main -Verbose -Debug |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| foreach ($i in 1..8192) | |
| { | |
| Write-Host $i | |
| dd if=/dev/random bs=1 count=$i of=filein/rand_${i}.bin 2> err\rand_${i}.err | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| foreach ($i in 32..8192) | |
| { | |
| Write-Host $i | |
| openssl genrsa $i 2> err\rsa_${i}_priv.err | Out-File keyin\rsa_${i}_priv.pem -Encoding Ascii | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment