سریال House MD.
فصل سه، قسمت سه: رضایت آگاهانه
Post #3360
788
AG @dr_biglari_ds
Agora Mazzy Star – Into Dust

Most people think GPU programming is about throwing more cores at a problem.
It's not. It's about understanding how those cores actually work and writing code that cooperates with the hardware instead of fighting it.
Parallel reduction is the perfect example. It's just a sum. An array in, a number out. Dead simple.
But the difference between a naive CUDA kernel and an optimized one is an 8× speedup , not from better math, but from:
• Fixing an addressing pattern that was silently serializing warps
• Letting the compiler eliminate dead code at compile time
• Skipping synchronization barriers that weren't needed
• Moving from shared memory to register-level communication


Agora // strAttack.go package timeAttack import ( "fmt" "math/rand" "sort" "time" ) const SECRET = "s3cr3t_k3y" // Use a sink variable — prevents compiler from optimizing away the work loop var sink int func vulnerableCheck(input string) bool…

Secret length is known (or guessed): 9
Cracking position 0... found '4' (signal: 0s) → recovered so far: 4
Cracking position 1... found 'o' (signal: 0s) → recovered so far: 4o
Cracking position 2... found 'P' (signal: 0s) → recovered so far: 4oP
Cracking position 3... found 'Q' (signal: 0s) → recovered so far: 4oPQ
Cracking position 4... found 'D' (signal: 0s) → recovered so far: 4oPQD
Cracking position 5... found 'x' (signal: 0s) → recovered so far: 4oPQDx
Cracking position 6... found 'f' (signal: 0s) → recovered so far: 4oPQDxf
Cracking position 7... found 'S' (signal: 0s) → recovered so far: 4oPQDxfS
Cracking position 8... found '8' (signal: 0s) → recovered so far: 4oPQDxfS8
:( Got: "4oPQDxfS8" (close but timing noise interfered)
Run again — noise can cause misses on a busy system.
Secret length is known (or guessed): 10
Cracking position 0... found 's' (signal: 1.084µs) → recovered so far: s
Cracking position 1... found '3' (signal: 2.209µs) → recovered so far: s3
Cracking position 2... found 'c' (signal: 3.333µs) → recovered so far: s3c
Cracking position 3... found 'r' (signal: 4.458µs) → recovered so far: s3cr
Cracking position 4... found '3' (signal: 5.583µs) → recovered so far: s3cr3
Cracking position 5... found 't' (signal: 6.708µs) → recovered so far: s3cr3t
Cracking position 6... found '_' (signal: 7.834µs) → recovered so far: s3cr3t_
Cracking position 7... found 'k' (signal: 8.958µs) → recovered so far: s3cr3t_k
Cracking position 8... found '3' (signal: 10.042µs) → recovered so far: s3cr3t_k3
Cracking position 9... found 'y' (signal: 11.167µs) → recovered so far: s3cr3t_k3y
:) Secret recovered: "s3cr3t_k3y"
// strAttack.go
package timeAttack
import (
"fmt"
"math/rand"
"sort"
"time"
)
const SECRET = "s3cr3t_k3y"
// Use a sink variable — prevents compiler from optimizing away the work loop
var sink int
func vulnerableCheck(input string) bool {
if len(input) != len(SECRET) {
return false
}
for i := 0; i < len(SECRET); i++ {
if input[i] != SECRET[i] {
return false
}
// sink prevents dead-code elimination by the compiler
for j := 0; j < 1000; j++ {
sink += j
}
}
return true
}
func measureTime(input string, trialsCount int) time.Duration {
samples := make([]int64, trialsCount)
for i := 0; i < trialsCount; i++ {
start := time.Now()
vulnerableCheck(input)
samples[i] = time.Since(start).Nanoseconds()
}
sort.Slice(samples, func(i, j int) bool { return samples[i] < samples[j] })
// lower quartile — stable against GC/scheduler spikes
return time.Duration(samples[trialsCount/4])
}
func Attack(guessedLength int) string {
const trials = 3_000
charset := "abcdefghijklmnopqrstuvwxyz0123456789_!ABCDEFGHIJKLMNOPQRSTUVWXYZ"
recovered := make([]byte, guessedLength)
for i := range recovered {
recovered[i] = 'a'
}
for index := 0; index < guessedLength; index++ {
fmt.Printf("Cracking position %d... ", index)
bestChar := charset[0]
bestTime := time.Duration(0)
first := true
// Shuffle charset order to avoid positional bias
order := rand.Perm(len(charset))
for _, ci := range order {
recovered[index] = charset[ci]
elapsed := measureTime(string(recovered), trials)
if first || elapsed > bestTime {
bestTime = elapsed
bestChar = charset[ci]
first = false
}
}
recovered[index] = bestChar
fmt.Printf("found '%c' (signal: %v) → recovered so far: %s\n",
bestChar, bestTime, string(recovered[:index+1]))
}
return string(recovered)
}
// main.go
package main
import (
"fmt"
"practice/timeAttack"
)
func main() {
fmt.Println("=== Timing Attack Demo ===")
for i := 1; i < 11; i++ {
fmt.Printf("Secret length is known (or guessed): %d\n\n", i)
result := timeAttack.Attack(i)
fmt.Println()
if result == timeAttack.SECRET {
fmt.Printf(":) Secret recovered: \"%s\"\n", result)
break
} else {
fmt.Printf(":( Got: \"%s\" (close but timing noise interfered)\n", result)
fmt.Println(" Run again — noise can cause misses on a busy system.")
}
}
}
Agora بررسی تساوی دو رشته در جاوا - بخش دوم ـــــــــــــــــــــــــــــــــــ حالا اگر آدرسها یکی نبود چی؟ بهتره یک نگاهی به پیادهسازی equals توی StringLatin1 و StringUTF16 بندازیم: public static boolean equals(byte[] value, byte[] other) { if (value.length…
a = "123abc"
b = "123bbc"
Brumley and Boneh devised a timing attack against OpenSSL and successfully extracted a factor of the RSA modulus (and therefore the private key) over a local network. Before this attack, it was generally believed that timing attacks would not work against general-purpose servers because timing variations would mask the decryption times.
They reported using about a million queries to remotely extract a 1024-bit key from an OpenSSL 0.9.7 server in about two hours. The fix was enabling RSA blinding by default in OpenSSL.
A test setup showed that for a correct username, the login response was 2–10 times slower than for an incorrect one, even when only running 5 queries per candidate. The difference was described as immediately obvious and easy to detect through any modern network with even a basic script.
MessageDigest.isEqual()
subtle.ConstantTimeCompare()
hmac.compare_digest()


Agora یکی از پروژههایی که بعد از رهایی از دانشگاه میخواستم پیش ببرم که خودش چند زیر پروژه داره و هر کدوم یک پست مفصل میطلبه، طراحی Homelab خودم بود. فعلا همچنان تو فاز پسا خرید تجهیزات مونده. اینقدر درگیر و مشغولم که فرصت نمیکنم به زندگی برسم و به طبع این پروژه…
