Software /
code /
verse
Annotate
util/random.lua @ 506:3610196c5e83 default tip
Merge with Zash.
author | Trần H. Trung <xmpp:trần.h.trung@trung.fun> |
---|---|
date | Sat, 08 Jul 2023 02:17:52 +0700 |
parent | 401:7be4ebefd1f4 |
rev | line source |
---|---|
388
d963c8a5d89c
Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Prosody IM |
d963c8a5d89c
Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2014 Matthew Wild |
d963c8a5d89c
Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2014 Waqas Hussain |
d963c8a5d89c
Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 -- |
d963c8a5d89c
Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
d963c8a5d89c
Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 -- COPYING file in the source package for more information. |
d963c8a5d89c
Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 -- |
d963c8a5d89c
Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
401
7be4ebefd1f4
util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents:
388
diff
changeset
|
9 local urandom = io.open("/dev/urandom", "r"); |
388
d963c8a5d89c
Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 |
401
7be4ebefd1f4
util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents:
388
diff
changeset
|
11 if urandom then |
7be4ebefd1f4
util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents:
388
diff
changeset
|
12 return { |
7be4ebefd1f4
util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents:
388
diff
changeset
|
13 seed = function () end; |
7be4ebefd1f4
util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents:
388
diff
changeset
|
14 bytes = function (n) return urandom:read(n); end |
7be4ebefd1f4
util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents:
388
diff
changeset
|
15 }; |
388
d963c8a5d89c
Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 end |
d963c8a5d89c
Import util.random from Prosody (using SHA-1)
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 |
401
7be4ebefd1f4
util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents:
388
diff
changeset
|
18 local crypto = require "crypto" |
7be4ebefd1f4
util.random: Use /dev/urandom or LuaCrypto
Kim Alvefur <zash@zash.se>
parents:
388
diff
changeset
|
19 return crypto.rand; |